Export DataSet To Multiple Excel Sheets And Download Into A Zip File Using C#?

Jan 21, 2011

how to Export DataSet to Multiple Excel Sheets and download those file into a zip in C# asp.net?

View 2 Replies


Similar Messages:

C# - Exporting Dataset To Excel File With Multiple Sheets?

Apr 2, 2010

In C# ASP.NET 3.5 web application, I need to export multiple datatables (or a dataset) to an Excel 2007 file with multiple sheets, and then provide the user with 'Open/Save' dialog box, WITHOUT saving the Excel file on the web server.

I have used Excel Interop before. I have been reading that it's not efficient and is not the best approach to achieve this and there are more ways to do it, 2 of them being: 1) Converting data in datatables to an XML string that Excel understands 2) Using OPEN XML SDK 2.0.

It looks like OPEN XML SDK 2.0 is better, please let me know. Are there any other ways to do it? I don't want to use any third-party tools.

If I use OPEN XML SDK, it creates an excel file, right? I don't want to save it on the (Windows 2003) server hard drive (I don't want to use Server.MapPath, these Excel files are dynamically created, and they are not required on the server, once client gets them). I directly want to prompt the user to open/save it. I know how to do it when the 'XML string' approach is used.

View 3 Replies

Exporting Multiple Tables In A DataSet To An Excel File With Multiple Sheets?

Jul 8, 2010

I was in need of exporting multiple tables in a DataSet to an Excel file with multiple sheets. I found a very good article in [URL].[URL] was able to successfully export each of my datatables in the dataset to excel worksheets. This solution worked for small number of rows. But when the data got larger I am consistently getting the system.outofmemoryexception. THis is because the code is using up the memory when creating excel.

Does anyone have another option to do the above?

View 2 Replies

How To Export A Dataset To Excel And Raise A File Download Dialog From Webmethod

Aug 6, 2010

I am using the following code to export a datset to excel sheet.

[Code]....

Problem is that its not raising file download and hence no export is taking place.The same code works fine in a normal method.But with the webmethod its not working.

View 3 Replies

Databases :: Export To Excel Multiple Sheets Without COM Interop Or Excel Object?

Feb 18, 2011

i want to export multiple tables in a dataset to excel workbook with each tables as sheets without using COM Interop or Excel Object.

View 2 Replies

Data Controls :: Export GridView Data To Multiple Sheets In Same Excel File

Jan 24, 2016

I used this coding for export to excel, by using this coding i got only 65,536 rows only. How to bind more than 65,536 records or how to move the  balace records to sheet 2 by using this method.

Protected Sub btnExportExcel_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ars_stock As New DataTable
ars_stock = cls.FillDataTable("select top 70000 * from spal..po_acc_details")
Response.Clear()
Response.Buffer = True

[Code] ....

View 1 Replies

Forms Data Controls :: Export Multiple Gridviews To Multiple Sheets In Excel

Feb 18, 2011

I have a page with two gridviews and I want to export the gridviews content to excel in two separate sheets. How is it achieved?

View 1 Replies

Forms Data Controls :: Export Multiple Gridview To Excel Add Multiple Sheets

Oct 9, 2010

I create reports sometimes with a gridview and export the data to excel. Lets say I have like multiple gridviews and I wanted to export each gridview to excel under its own spreadsheet.

So gridview1, gridview2, gridview3 are exported to excel under $heet1, $heet2, $heet3.

I know how to export multiple gridviews to 1 excel sheet but I don't know how to export them separately under their own spreadsheet.

I've been researching online, and i'm continously searching, but does anyone know how to do what i'm trying to do with the gridview and excel or is this not possible?

View 1 Replies

Data Controls :: Export Multiple GridView To Multiple Excel Sheets With Formatting Using OpenXml

Mar 26, 2016

i have a page having 12 gridviews which cell background color depend on another cell value.now the requirement of my project is download to these 12 gridviews in single excel file in multiple sheets like gridview 1 in sheet1 gridview2 in sheet2 likewise,,,,,,,,,,,i have seen your article on downloading multiple gridviews on same page but i want in above mention format........

View 1 Replies

Web Forms :: Extracting Excel Report With Multiple Sheets From Dataset?

Oct 17, 2012

I know to populate Excel file using htmltextwriter from dataset.

I want to know how to populate Excel multiple sheets using htmltextwriter from dataset based on condition

View 1 Replies

Data Controls :: Export Single DataTable To Multiple Excel Sheets Using OpenXml?

May 7, 2015

I have 25 collumn, i want export 20 collumn to sheet 1 and 5 collumn to sheet 2.

View 1 Replies

Export 4 Tables Data Into One Excel File In Different Sheets With Column Names?

Jan 11, 2010

anybody working on data exporting? I've 4 tables in my sql server database. I want to export these 4 tables data into one excel file in different sheets with column names.

View 7 Replies

Web Forms :: Exporting Multiple HTML Tables To Multiple Excel Sheets Excel

Mar 30, 2010

is there any way that i could export multiple tables already formatted into multiple excel sheets. I know how to export data to multiple sheets through dataset while looping through tables, rows and columns and then add styles.

But I really want to export formatted html tables each into seperate sheet

View 3 Replies

Export Excel File From Dataset In C#?

May 29, 2010

i have data in sql server i want to export to data with asp.net C#

View 3 Replies

Export Mutiple Tables Into One Excel With Different Sheets?

Jun 10, 2010

Any one know how to export mutiple tables into one excel with different sheets in asp.net application.

View 7 Replies

Forms Data Controls :: Export Multiple Grids And Dataset To Excel Sheet

Feb 9, 2010

In a page im having multiple data grids with some data tables.How can i export all these to excel sheet without any change in the alignment.

View 6 Replies

Forms Data Controls :: Export To Excel With Two Sheets From Two Grid Views?

Jun 16, 2010

Export to Excel with two sheets from two grid views. I am in need of export two grids into a single excel with two sheets.

View 2 Replies

C# - Multiple Different Excel Sheets Into One SQL Table

Oct 19, 2010

I have a lot of excel sheets which columns are slightly different, i want to import all of these sheets (one at a time) into ONE SQL TABLE. I'll give an example : Say ive written the required program and called it Excel2sql converter. So Excel2sql takes an excel sheet and create a database table with the data of that excel sheet, For example say i have the following excel sheet:

Excel_Sheet_1
-----------------------------
FirstName MiddleName LastName
John A. Smith

when i run Excel2sql (Excel_Sheet_1), a database table should be CREATED for me with the following data in it:

FirstName MiddleName LastName
John A. Smith

Now, when i run my program again with the following excel sheet:...................

View 2 Replies

C# - EXPORT Dataset To EXCEL

Feb 12, 2011

I am using the following code to export fields from a database table into excel. What I want to do is be able to write a SQL statement to retrieve fields from multiple tables and export them into excel. This code only allows me to export one table. Also, how can I display a save prompt dialog?

protected void export_Click(object sender, EventArgs e)
{
string sql = null;
string data = null;
string path = save_as.Text;
int i = 0;
int j = 0;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//connectionString = "data source=servername;initial catalog=databasename;user id=username;password=password;";
SqlConnection cnn = new SqlConnection(GetConnectionString());
cnn.Open();
sql = "SELECT Story, CreationDate FROM Story";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
DataSet ds = new DataSet();
dscmd.Fill(ds);
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
for (j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
{
data = ds.Tables[0].Rows[i].ItemArray[j].ToString();
xlWorkSheet.Cells[i + 1, j + 1] = data;
}
}
xlWorkBook.SaveAs(path+".xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
//MessageBox.Show("Excel file created , you can find the file c:\csharp.net-informations.xls");
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
//MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
}
finally
{
GC.Collect();
}
}

View 2 Replies

Web Forms :: Export A Big Dataset To Excel Via Web?

Feb 24, 2010

Actually I have a SQL query that a user exports to excel in our web server. I did it in c# with Visual Studio 2003 (.Net v1.1): I get the data from a SQL server into a Dataset, then with this method I create the XLS file:

private void ExportAsExcelFile ( DataSet dtExport )
{
Response.Clear() ;
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.UTF8 ;
Response.Charset = string.Empty ;
Response.AddHeader ( "Content-Disposition", "attachment;filename=data.xls" ) ;
System.IO.StringWriter objStringWriter = new StringWriter () ;
System.Web.UI.HtmlTextWriter objHtmlTextWriter = new System.Web.UI.HtmlTextWriter(objStringWriter) ;
DataGrid objDatagrid = new DataGrid () ;
objDatagrid.DataSource = dtExport ;
objDatagrid.DataBind () ;
objDatagrid.RenderControl ( objHtmlTextWriter ) ;
Response.Write (objStringWriter.ToString()) ;
Response.End () ;
}

Well, this works when the SQL query has 10.000 rows and so on. But now the query has more than 200.000 rows, and I´m getting a TimeOut Error trying to export the data. I read about generate this big files with a Store Procedure and the SQL Commad: BCP [URL], but I tryed and it fails. I have no permissions to execute this command. Is there any other way to export this SQL data to Excel via a ASPX page?

View 1 Replies

VS 2005 - Export Dataset To Excel

Sep 9, 2011

I have a dataset wity multiple table, the same dataset need to export to excel

dataset.table[0] data
dataset.table[1] data in the same excel sheet

View 1 Replies

VS 2008 - Export Dataset To Excel Attachment

Jul 12, 2012

I need to give users of my asp.net/vb.net web application the ability to click a button which will then send them an e-mail with the contents of a SQL query attached as an Excel e-mail attachment.

I can manage all of this apart from getting the contents of a VB dataset object into an Excel file on my server.

I know how to export a gridview to Excel at the client end, but my boss has been adamant that he wants the button to send an e-mail with the results attached - I have no need to display a gridview at all.

How to export the contents of a datareader or dataset directly into an Excel file at the server side?

View 12 Replies

Forms Data Controls :: Download - Export To Excel

Jan 19, 2010

I have written code to export to excel as below:

View 2 Replies

Web Forms :: Export The Dataset Values Into Excel In Application

Mar 9, 2011

I am trying to Export the dataset values into Excel in my application, its working for first time. Again if i click the export button [second time] the button does't cause postback and the entire page is not postback.

View 4 Replies

C# - Numbers Are Converted As Text When Export Dataset To Excel

Jul 8, 2010

Iam exporting dataset to excel , the numbers on the sheet shown as text when export it to excel. Here is the code:

public class Excel
{
const int rowLimit = 65000;
private static string getWorkbookTemplate()
{
StringBuilder sb = new StringBuilder(818);
sb.AppendFormat(@"<?xml version=""1.0""?>{0}", Environment.NewLine);
sb.AppendFormat(@"<?mso-application progid=""Excel.Sheet""?>{0}", Environment.NewLine);
sb.AppendFormat(@"<Workbook xmlns=""urn:schemas-microsoft-com:office:spreadsheet""{0}", Environment.NewLine);
sb.AppendFormat(@" xmlns:o=""urn:schemas-microsoft-com:office:office""{0}", Environment.NewLine);
sb.AppendFormat(@" xmlns:x=""urn:schemas-microsoft-com:office:excel""{0}", Environment.NewLine);
sb.AppendFormat(@" xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet""{0}", Environment.NewLine);
sb.AppendFormat(@" xmlns:html=""[URL]
sb.AppendFormat(@" <Styles>{0}", Environment.NewLine);
sb.AppendFormat(@" <Style ss:ID=""Default"" ss:Name=""Normal"">{0}", Environment.NewLine);
sb.AppendFormat(@" <Alignment ss:Vertical=""Bottom""/>{0}", Environment.NewLine);
sb.AppendFormat(@" <Borders/>{0}", Environment.NewLine);
sb.AppendFormat(@" <Font ss:FontName=""Verdana"" x:Family=""Swiss"" ss:Size=""12"" ss:Color=""#0000A0""/>{0}", Environment.NewLine);
sb.AppendFormat(@" <Interior/>{0}", Environment.NewLine);
sb.AppendFormat(@" <NumberFormat/>{0}", Environment.NewLine);
sb.AppendFormat(@" <Protection/>{0}", Environment.NewLine);
sb.AppendFormat(@" </Style>{0}", Environment.NewLine);
sb.AppendFormat(@" <Style ss:ID=""s62"">{0}", Environment.NewLine);
sb.AppendFormat(@" <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#000000""{0}", Environment.NewLine);
sb.AppendFormat(@" ss:Bold=""1""/>{0}", Environment.NewLine);
sb.AppendFormat(@" </Style>{0}", Environment.NewLine);
sb.AppendFormat(@" <Style ss:ID=""s63"">{0}", Environment.NewLine);
sb.AppendFormat(@" <NumberFormat ss:Format=""Short Date""/>{0}", Environment.NewLine);
sb.AppendFormat(@" </Style>{0}", Environment.NewLine);
sb.AppendFormat(@" </Styles>{0}", Environment.NewLine);
sb.Append(@"{0}
</Workbook>");
return sb.ToString();
}
private static string replaceXmlChar(string input)
{
input = input.Replace("&", "&");
input = input.Replace("<", "<");
input = input.Replace(">", ">");
input = input.Replace(""", """);
input = input.Replace("'", "&apos;");
return input;
}
private static string getCell(Type type, object cellData)
{
Object data = (cellData is DBNull) ? "" : cellData;
if (type.Name.Contains("Int") || type.Name.Contains("Double") || type.Name.Contains("Decimal")) return string.Format("<Cell><Data ss:Type="Number">{0}</Data></Cell>", data);
if (type.Name.Contains("Date") && data.ToString() != string.Empty)
{
return string.Format("<Cell ss:StyleID="s63"><Data ss:Type="DateTime">{0}</Data></Cell>", Convert.ToDateTime(data).ToString("yyyy-MM-dd"));
}
return string.Format("<Cell><Data ss:Type="String">{0}</Data></Cell>", replaceXmlChar(data.ToString()));
}
private static string getWorksheets(DataSet source)
{
StringWriter sw = new StringWriter();
if (source == null || source.Tables.Count == 0)
{
sw.Write("<Worksheet ss:Name="Sheet1">
<Table>
<Row><Cell><Data ss:Type="String"></Data></Cell></Row>
</Table>
</Worksheet>");
return sw.ToString();
}
foreach (DataTable dt in source.Tables)
{
if (dt.Rows.Count == 0)
sw.Write("<Worksheet ss:Name="" + replaceXmlChar(dt.TableName) + "">
<Table>
<Row><Cell ss:StyleID="s62"><Data ss:Type="String"></Data></Cell></Row>
</Table>
</Worksheet>");
else
{
//write each row data
int sheetCount = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
if ((i % rowLimit) == 0)
{
//add close tags for previous sheet of the same data table
if ((i / rowLimit) > sheetCount)
{
sw.Write("
</Table>
</Worksheet>");
sheetCount = (i / rowLimit);
}
sw.Write("
<Worksheet ss:Name="" + replaceXmlChar(dt.TableName) +
(((i / rowLimit) == 0) ? "" : Convert.ToString(i / rowLimit)) + "">
<Table>");
//write column name row
sw.Write("
<Row>");
foreach (DataColumn dc in dt.Columns)
sw.Write(string.Format("<Cell ss:StyleID="s62"><Data ss:Type="String">{0}</Data></Cell>", replaceXmlChar(dc.ColumnName)));
sw.Write("</Row>");
}
sw.Write("
<Row>");
foreach (DataColumn dc in dt.Columns)
sw.Write(getCell(dc.DataType, dt.Rows[i][dc.ColumnName]));
sw.Write("</Row>");
}
sw.Write("
</Table>
</Worksheet>");
}
}
return sw.ToString();
}
public static string GetExcelXml(DataTable dtInput, string filename)
{
string excelTemplate = getWorkbookTemplate();
DataSet ds = new DataSet();
ds.Tables.Add(dtInput.Copy());
string worksheets = getWorksheets(ds);
string excelXml = string.Format(excelTemplate, worksheets);
return excelXml;
}
public static string GetExcelXml(DataSet dsInput, string filename)
{
string excelTemplate = getWorkbookTemplate();
string worksheets = getWorksheets(dsInput);
string excelXml = string.Format(excelTemplate, worksheets);
return excelXml;
}
public static void ToExcel(DataSet dsInput, string filename, HttpResponse response)
{
string excelXml = GetExcelXml(dsInput, filename);
response.Clear();
response.AppendHeader("Content-Type", "application/vnd.ms-excel");
response.AppendHeader("Content-disposition", "attachment; filename=" + filename);
response.Write(excelXml);
response.Flush();
response.End();
}
public static void ToExcel(DataTable dtInput, string filename, HttpResponse response)
{
DataSet ds = new DataSet();
ds.Tables.Add(dtInput.Copy());
ToExcel(ds, filename, response);
}
}

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved