C# 使用EPPlus多次写入同一excel文件
我也在CodePlex讨论板上发布了这个问题() 下面是我在那里的复制和粘贴: 我正试图使用它来读取/写入SSIS中的excel文档。64位模式下的SSI不支持excel连接。在写入同一excel文件的不同任务中,第二次保存()总是失败。我也能在.NET中复制这个。以下内容模拟了SSIS中的场景C# 使用EPPlus多次写入同一excel文件,c#,.net,epplus,C#,.net,Epplus,我也在CodePlex讨论板上发布了这个问题() 下面是我在那里的复制和粘贴: 我正试图使用它来读取/写入SSIS中的excel文档。64位模式下的SSI不支持excel连接。在写入同一excel文件的不同任务中,第二次保存()总是失败。我也能在.NET中复制这个。以下内容模拟了SSIS中的场景 RowIndex = 2; using (var ep = new ExcelPackage(new FileInfo(filePath))) {
RowIndex = 2;
using (var ep = new ExcelPackage(new FileInfo(filePath)))
{
for (var i= 1; i<= 10; i++)
{
var worksheet = ep.Workbook.Worksheets["Sheet1"];
worksheet.Cells[RowIndex, 1].Value = i;
RowIndex++;
}
ep.Save();
}
RowIndex = 2;
using (var ep = new ExcelPackage(new FileInfo(filePath)))
{
for (var ii= 1; ii<= 10; ii++)
{
var worksheet = ep.Workbook.Worksheets["Sheet2"];
worksheet.Cells[RowIndex, 1].Value = ii;
RowIndex++;
}
ep.Save();
}
我尝试加载源代码进行调试,但是Cells集合不再存在。我不知道这是怎么发生的。如果您有任何帮助,我们将不胜感激。您可以对这两种保存使用相同的方法。您只需打开文件一次,然后只需获取/使用另一张工作表。这可能会修复错误并提高性能。您是要将同一个文件保存两次还是两个不同的文件?
{"Error saving file C:\\####.xlsm"}
Inner Exception:
{"Index was outside the bounds of the array."}
at OfficeOpenXml.Utils.CompoundDocument.GetChunk(Byte[] compBuffer, Int32& pos)
at OfficeOpenXml.Utils.CompoundDocument.DecompressPart(Byte[] part, Int32 startPos)
at OfficeOpenXml.VBA.ExcelVbaProject.ReadModules()
at OfficeOpenXml.VBA.ExcelVbaProject.GetProject()
at OfficeOpenXml.VBA.ExcelVbaProject..ctor(ExcelWorkbook wb)
at OfficeOpenXml.ExcelWorkbook.get_VbaProject()
at OfficeOpenXml.ExcelWorkbook.Save()
at OfficeOpenXml.ExcelPackage.Save()