问题:
1.能不能不用生成中间文件直接将Dataset数据提供用户下载。
(我想的方法时将Dataset的数据构造一个excel表在内存里,然后将内存里的Excel表下载到用户端。)
6 个解决方案
#1
如果生成的excel由服务器来操作,那么生成一次,用户就可以根据在服务器的地址来下载
按你说的,应该没有必要一直操作内存
按你说的,应该没有必要一直操作内存
#2
貌似网上有个教程,需要个插件来弄
#3
有链接没?
#6
贴一段代码给你:
using System;
using Acey.ExcelX;
public void ExportData(DataSet ds,string xlsFileName)
{
IWorkbook workbook = ExcelxApplication.CreateWorkbook();
IWorksheet worksheet = workbook.Worksheets[0];
int row = 0;
for (int i = 0; i < ds.Tables.Count; i++)
{
DataTable table = ds.Tables[i];
//导出DataTable到Excel中
worksheet.ImportDataTable(table, true,row,0);
row += table.Rows.Count + 1;
}
workbook.SaveAs(xlsFileName,FileFormat.Excel97To2003);
}
参考blog:http://www.cnblogs.com/happyfish78/
using System;
using Acey.ExcelX;
public void ExportData(DataSet ds,string xlsFileName)
{
IWorkbook workbook = ExcelxApplication.CreateWorkbook();
IWorksheet worksheet = workbook.Worksheets[0];
int row = 0;
for (int i = 0; i < ds.Tables.Count; i++)
{
DataTable table = ds.Tables[i];
//导出DataTable到Excel中
worksheet.ImportDataTable(table, true,row,0);
row += table.Rows.Count + 1;
}
workbook.SaveAs(xlsFileName,FileFormat.Excel97To2003);
}
参考blog:http://www.cnblogs.com/happyfish78/
#1
如果生成的excel由服务器来操作,那么生成一次,用户就可以根据在服务器的地址来下载
按你说的,应该没有必要一直操作内存
按你说的,应该没有必要一直操作内存
#2
貌似网上有个教程,需要个插件来弄
#3
有链接没?
#4
#5
#6
贴一段代码给你:
using System;
using Acey.ExcelX;
public void ExportData(DataSet ds,string xlsFileName)
{
IWorkbook workbook = ExcelxApplication.CreateWorkbook();
IWorksheet worksheet = workbook.Worksheets[0];
int row = 0;
for (int i = 0; i < ds.Tables.Count; i++)
{
DataTable table = ds.Tables[i];
//导出DataTable到Excel中
worksheet.ImportDataTable(table, true,row,0);
row += table.Rows.Count + 1;
}
workbook.SaveAs(xlsFileName,FileFormat.Excel97To2003);
}
参考blog:http://www.cnblogs.com/happyfish78/
using System;
using Acey.ExcelX;
public void ExportData(DataSet ds,string xlsFileName)
{
IWorkbook workbook = ExcelxApplication.CreateWorkbook();
IWorksheet worksheet = workbook.Worksheets[0];
int row = 0;
for (int i = 0; i < ds.Tables.Count; i++)
{
DataTable table = ds.Tables[i];
//导出DataTable到Excel中
worksheet.ImportDataTable(table, true,row,0);
row += table.Rows.Count + 1;
}
workbook.SaveAs(xlsFileName,FileFormat.Excel97To2003);
}
参考blog:http://www.cnblogs.com/happyfish78/