ASP.NET 将一个DataTable中的数据源导出多个EXCEL中,不是多个Sheet?怎么做啊?
比如:DataTable数据源:abc123456789在导出时,我要设计成,分3个EXCEL导出,第一个导出数据是1,2,3,第二个导出数据是4,5,6......
比如:DataTable 数据源: a b c
1 2 3
4 5 6
7 8 9
在导出时,我要设计成,分3个EXCEL导出,第一个导出数据是1,2,3,第二个导出数据是4,5,6
... 展开
1 2 3
4 5 6
7 8 9
在导出时,我要设计成,分3个EXCEL导出,第一个导出数据是1,2,3,第二个导出数据是4,5,6
... 展开
展开全部
创建3个workbook对象分别把他们导出到这三个中
比如:
var aplExcel = newApplication {DisplayAlerts = false, SheetsInNewWorkbook = 3};
var workBook = (_Workbook)aplExcel.Workbooks.Add(Missing.Value);
var activateSheet = (_Worksheet)workBook.Sheets[1];
activateSheet.Activate();
workBook.SaveAs(excelFilePath,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
workBook.Close();
可以创建出来一个excel再把数据贴上去,再按你要的要求循环三次
比如:
var aplExcel = newApplication {DisplayAlerts = false, SheetsInNewWorkbook = 3};
var workBook = (_Workbook)aplExcel.Workbooks.Add(Missing.Value);
var activateSheet = (_Worksheet)workBook.Sheets[1];
activateSheet.Activate();
workBook.SaveAs(excelFilePath,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
workBook.Close();
可以创建出来一个excel再把数据贴上去,再按你要的要求循环三次
更多追问追答
追问
我也想这样但是代码在循环走到第二遍的时候报错
追答
什么错误?
for
(int i = 0; i < 3; i++)
{
var aplExcel = newApplication { DisplayAlerts = false, SheetsInNewWorkbook = 3 };
var workBook = (_Workbook)aplExcel.Workbooks.Add(Missing.Value);
var activateSheet = (_Worksheet)workBook.Sheets[1];
activateSheet.Activate();
workBook.SaveAs(
"d:\\a" + i + ".xlsx",
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
XlSaveAsAccessMode.xlNoChange,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);
workBook.Close();
}
没有错误啊。可以出来三个excel
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询