Last post May 04, 2011 09:16 AM by Larry Neblett
Jan 21, 2011 08:24 PM|Jerry8989|LINK
I have a search page on my website that a user will need to export to excel. I have the following code that works but the only problem is that the entire string takes up only one cell instead of each column taking up it's own column cell in excel. So when
I select cell A1 in excel my entire row displays and B1, etc.. are all blank.
OracleCommand oCmd = new OracleCommand(tempSQL, conn);
OracleDataReader oRead = oCmd.ExecuteReader();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
StringBuilder sb = new StringBuilder();
for (int col = 0; col < oRead.FieldCount - 1; col++)
Response.Write(sb.ToString() + "\n");
Is there a better way to do it? My problem is that I cant save the file on the server.
Jan 21, 2011 08:50 PM|DarrellNorton|LINK
Using CarlosAg Excel Xml Writer, you can create Excel spreadsheets the way you want to (including formatting, calculations, etc.) and write the response stream:
<div class="code"><%@ Page Language="C#" ContentType="text/xml" %>
<%@ Import Namespace="CarlosAg.ExcelXmlWriter"
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets.Add("Sample");
WorksheetRow row = sheet.Table.Rows.Add();
row.Cells.Add(new WorksheetCell("Hello World from ASP.NET"));
Jan 21, 2011 08:59 PM|Jerry8989|LINK
Thank you so much for your reply. I am unable to install any 3rd party controls/code on our webserver. I'm only allowed to use the basics. Is there another way?
Jan 24, 2011 01:46 PM|Jerry8989|LINK
Does anyone else have any idea on how to do this without 3rd party controls?
Apr 18, 2011 03:44 PM|DarrellNorton|LINK
You don't have to "install" it. Just copy it to the BIN directory. For all the admins will know, it is just another DLL.
May 04, 2011 09:16 AM|Larry Neblett|LINK
Hi Jerry, if you will be able to put some dll into your BIN directory on the site. I can suggest you
Excel Jetcell .NET component. It has a
free version that can create excel files XLS or XLSX. It allows to export data from datatable or dataset to excel but can't add a formatting to cells of excel spreadsheet.