0

How can we display table border on a Open Office Calc sheet thro HTML?

Ours is a ASP.NET web application. I am generating Calc on the fly without saving it in the server and sending that to client(browser). For that, I am generating and sending HTML code through Response object to the browser. As Content-Type is set to "application/vnd.sun.xml.calc", browser treats it as an attachement and Open Office renders the HTML code. But I am having trouble displaying Table border on the Calc spreadsheet. As a note, this works fine if the attachment type is MS Excel. I noticed, Calc does not support all HTML tags. In this regard, I would like to know how can I display Table border in Calc thro my HTML content of Response object.

Below is the code snippet

protected void Page_Load(object sender, EventArgs e)
{  
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.Buffer = true;
    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=Sample.sxc");
    HttpContext.Current.Response.Charset = "";
    HttpContext.Current.Response.ContentType = "application/vnd.sun.xml.calc";
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);

    StringBuilder style = new StringBuilder();
    style.Append(@"<style> ");        
    style.Append(@" .text { mso-number-format:\@; } ");
    style.Append(@" .num { mso-number-format:\#\,\#\#0\.00; } ");
    style.Append(@" .intg { mso-number-format:\#\,\#\#0; } ");
    style.Append(@" .date { mso-number-format: 'Short Date'; } ");
    style.Append(@" .date { mso-number-format: 'dd\/mm\/yyyy'; } ");
    style.Append(@"</style>");


    HttpContext.Current.Response.Write(style.ToString());

    string s = @" <TABLE BORDER=""1""> 
                    <TR> 
                            <TD> <P> <U> <B> For Testing </B> </U> <BR> Generated By Sameer Bondasgfgzff </BR> </P> 
                            </TD> 
                    </TR>
                    <TR> 
                            <TD width=""100px"">  Sameer  </TD> 
                    </TR> 
                    <TR> <TD width=""100px"">  Srinivas  </TD> 
                    </TR> 
                </TABLE>"
                ;

    HttpContext.Current.Response.Output.Write(s);

    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();
}

Since, I could not figure out, I tried creating explicitly a Calc sheet with border. However, upon saving that as .HTML, I get a warning message saying formatting will be disturbed. If I suppress that and save it as .HTML, and when I open the saved .HTML thro Calc, border around the table dissapears.

I want to know how can I display border for the table in Calc sheet of Open Office thro HTML. Thanks in advance.

Sameer
  • 101
  • 2
  • 11
  • Can you provide code sample where you got this error.? – Vishal Suthar Jun 11 '13 at 07:17
  • i think query string of the form ?name=value has problems when the value contains = charaters (some of them will be dropped), You may be able to get away with appending the right number of = characters before doing the base64 decode.Try to use `Replace` method. – Rahul Jun 11 '13 at 07:20
  • Here is the stack trace : Invalid length for a Base-64 char array. SOURCE: mscorlib QUERYSTRING: PRIMARYKEYID=68545&ModuleName=CustomerDashBoard TARGETSITE: Byte[] FromBase64String(System.String) STACKTRACE: at System.Convert.FromBase64String(String s) at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) at System.Web.UI.HiddenFieldPageStatePersister.Load() Local Time: 11/06/2013 09:05:35 – Sameer Jun 11 '13 at 07:21
  • I beleive this code is causing the error : PageLoad() { if (!(Request.QueryString[QueryStrings.PRIMARYKEYID] == null)) { PrimaryKey = Convert.ToInt32(Request.QueryString[QueryStrings.PRIMARYKEYID]); } } – Sameer Jun 11 '13 at 07:23
  • in this line of code are you geeting or receiving the query string value. – Rahul Jun 11 '13 at 07:25
  • try to modified your code with this code `if (!(Request.QueryString["PRIMARYKEYID"] == null)) { PrimaryKey = Convert.ToInt32(Request.QueryString["PRIMARYKEYID"]); } ` and your query will look like that `PRIMARYKEYID=68545&ModuleName=CustomerDashBoard` – Rahul Jun 11 '13 at 07:29
  • Possible duplicate of [What causing this "Invalid length for a Base-64 char array"](http://stackoverflow.com/questions/858761/what-causing-this-invalid-length-for-a-base-64-char-array), it can for example be caused by a too large ViewState. Plesae show what else you found and eliminated. – CodeCaster Jun 11 '13 at 07:42
  • @CodeCaster: We are using ViewState but not to store large values. We are using it just to store boolean values and integers. – Sameer Jun 11 '13 at 08:27
  • @Sam I can't do anything with that comment. Your error is thrown when deserializing the ViewState. **You** will have to search in that direction, as we can't access your code or server. – CodeCaster Jun 11 '13 at 08:35

0 Answers0