在 EPPlus 4.05 中保存 .xlsm 文件时,出现错误,然后 Excel 删除 /xl/vbaProject.bin 部分
When saving .xlsm file in EPPlus 4.05, I get an error and then Excel deletes /xl/vbaProject.bin part
当我尝试以下代码时出现错误:
//https://github.com/JanKallman/EPPlus/issues/31
//Otherwise, I get an EPP error
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
//var excelFile = new FileInfo($"{keywordLocation.FilePath}{keywordLocation.FileName}".Replace("http://", ""));
var excelFile = new FileInfo(@"wwwroot/SubmissionFiles/23477-1/Financial_Report_0001091596.xlsx");
using (var source = new ExcelPackage(excelFile))
{
//source.Workbook.Worksheets.Add("VBA Sample");
source.Workbook.CreateVBAProject();
var sb = new StringBuilder();
sb.AppendLine("Private Sub Workbook_Open()");
sb.AppendLine("End Sub");
source.Workbook.CodeModule.Code = sb.ToString();
source.SaveAs(new FileInfo(@"wwwroot/SubmissionFiles/23477-1/Financial_Report_0001091596.xlsm"));
}
这是错误:
Problem in workbook error
当我单击“确定”时,出现以下错误:
Excel was able to open the file by repairing or removing the unreadable content
我也用最简单的 VBA 代码尝试过这个,其中包含一条注释:sb.AppendLine("'VBA Code");
现在的EPPlus 4.5.3.2还是有同样的问题...
甚至不必更改宏内容
using (var targetPackage = new ExcelPackage(new FileInfo(filename)))
{
var target = targetPackage.Workbook.VbaProject;
...
targetPackage.Save();
}
Excel 2016 年的结果不正确。
当我尝试以下代码时出现错误:
//https://github.com/JanKallman/EPPlus/issues/31
//Otherwise, I get an EPP error
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
//var excelFile = new FileInfo($"{keywordLocation.FilePath}{keywordLocation.FileName}".Replace("http://", ""));
var excelFile = new FileInfo(@"wwwroot/SubmissionFiles/23477-1/Financial_Report_0001091596.xlsx");
using (var source = new ExcelPackage(excelFile))
{
//source.Workbook.Worksheets.Add("VBA Sample");
source.Workbook.CreateVBAProject();
var sb = new StringBuilder();
sb.AppendLine("Private Sub Workbook_Open()");
sb.AppendLine("End Sub");
source.Workbook.CodeModule.Code = sb.ToString();
source.SaveAs(new FileInfo(@"wwwroot/SubmissionFiles/23477-1/Financial_Report_0001091596.xlsm"));
}
这是错误:
Problem in workbook error
当我单击“确定”时,出现以下错误:
Excel was able to open the file by repairing or removing the unreadable content
我也用最简单的 VBA 代码尝试过这个,其中包含一条注释:sb.AppendLine("'VBA Code");
现在的EPPlus 4.5.3.2还是有同样的问题... 甚至不必更改宏内容
using (var targetPackage = new ExcelPackage(new FileInfo(filename)))
{
var target = targetPackage.Workbook.VbaProject;
...
targetPackage.Save();
}
Excel 2016 年的结果不正确。