我想用 codeplex excelpackage 编写一个 excel 文件(2007),但是编写 excel 文件需要很多时间。我没有找到任何可以接受数据源的方法。
我的一段代码:
var newFile = new FileInfo(GlobalVariables.Compare2007Path);
using (var excelpackage = new ExcelPackage(newFile))
{
var myWorkbook = excelpackage.Workbook;
myWorkbook.Worksheets.Add("sheetname");
var xlWorkSheet = xlWorkBook.Worksheets["sheetname"];
//loop the data and fill the columns
var rowCount = 2;
foreach (var compare in objCompare)
{
xlWorkSheet.Cell(rowCount, 1).Value = compare.adserverIdSite.ToString();
xlWorkSheet.Cell(rowCount, 2).Value = compare.site;
xlWorkSheet.Cell(rowCount, 3).Value = compare.adserverIdZone.ToString();
xlWorkSheet.Cell(rowCount, 4).Value = compare.zone;
xlWorkSheet.Cell(rowCount, 5).Value = compare.position;
xlWorkSheet.Cell(rowCount, 6).Value = compare.weekday;
xlWorkSheet.Cell(rowCount, 7).Value = compare.oldimps.ToString();
xlWorkSheet.Cell(rowCount, 8).Value = compare.olduu.ToString();
xlWorkSheet.Cell(rowCount, 9).Value = compare.oldimpsuu.ToString();
xlWorkSheet.Cell(rowCount, 10).Value = compare.newimps.ToString();
xlWorkSheet.Cell(rowCount, 11).Value = compare.newuu.ToString();
xlWorkSheet.Cell(rowCount, 12).Value = compare.newimpsuu.ToString();
xlWorkSheet.Cell(rowCount, 13).Value = compare.diffimps.ToString();
xlWorkSheet.Cell(rowCount, 14).Value = compare.diffimpsperc.ToString();
rowCount++;
}
excelpackage.Save();
}
或者除了excelpackage之外还有其他选择吗?