问题:
当我编程打开一个Excel文件,其中有形状(例如。(箭头),然后通过向文件添加一个新图像(通过编程)来修改该文件,如果我试图获取这个新修改的Excel文件的字节(GetAsByteArray),它就会崩溃。
复制bug的步骤:
有什么想法或解决办法吗?
发布于 2019-01-08 14:23:36
试试这段代码。它将在添加图像后给出字节。但是Excel文件不会发生其他任何事情。
//create a fileinfo object of an excel file on the disk
FileInfo file = new FileInfo(Server.MapPath(""~/Content/input.xlsx"));
//create a new Excel package from the file
using (ExcelPackage package = new ExcelPackage(file))
{
//create an instance of the the first sheet in the loaded file
ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
//Add programmatic picture
worksheet.Drawings
.AddPicture("logo", new FileInfo(Server.MapPath("~/Content/logo.png")))
.SetPosition(5, 0, 5, 0);
//get the new size in byte array
byte[] output = package.GetAsByteArray();
}https://stackoverflow.com/questions/54080274
复制相似问题