Hello Everyone,
I am trying to save a stringBuilder to excel spreadsheet from asp.net page. I can succesfully save the string, but how can I pur each string in different cells
so I have this string
StringBuilder sb= new StringBuilder();
sb.append("A");
sb.append("B");
sb.append("C");
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
btnExport.EnableViewState = false;
Response.Write(sb);
Response.End();
it saves and creates the excel spreadsheet, but ABC all come in one cell of spreadsheet. How can I place A in once and right below it in another cell, I want to place "B" and "C" in another cell below B.
Is it possible to do it.
Please let me know.
Thanks.
Im supprised it works as it is!! usually you have to call .ToString() on a string builder to retrieve its text? Then append method also starts with a capital :D
Putting that to one side, you can achieve your goal by creating a table!
StringBuilder sb= new StringBuilder();
sb.Append("<table><tr>");
sb.append("<td>A</td>");
sb.append("<td>B</td>");");
sb.append("<td>C</td>");");
sb.Append("</tr></table>
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
btnExport.EnableViewState = false;
Response.Write(sb);
Response.End();
Sorry miss-read what your requirements are. The code i provided will place text into ajacent horizontal cells. To have the rows in a verticle mannor create each <td> within a new row!
0 comments:
Post a Comment