[英]I'm trying to insert an image into an excel document using ExcelLibrary with Picture and CellAnchor and the image doesn't display
I trimmed out quite a bit so if there is context missing sorry, I'll edit. 我进行了一些修剪,所以如果缺少上下文,对不起,我将进行编辑。
I'm not getting any errors and the Picture does seems to get added to the workbook object... 我没有收到任何错误,图片似乎确实已添加到工作簿对象中...
I've also tried just inserting into a new cell(), but when I get to saving to the stream it get an Invalid Cell value. 我也尝试过只插入到一个新的cell()中,但是当我要保存到流中时,它会得到一个无效的Cell值。
I'm using this link as a reference: https://excellibrary.googlecode.com/svn-history/r51/trunk/src/ExcelLibrary.WinForm/Form1.cs 我使用此链接作为参考: https : //excellibrary.googlecode.com/svn-history/r51/trunk/src/ExcelLibrary.WinForm/Form1.cs
Workbook wBook = new Workbook();
Worksheet wSheet = new Worksheet();
//getting my file
var path = context.Server.MapPath("~/data/default/content/logo.bmp");
pic.Image = ExcelLibrary.SpreadSheet.Image.FromFile(path);
pic.TopLeftCorner = new CellAnchor(5, 1, 0, 0);
pic.BottomRightCorner = new CellAnchor(7, 5, 592, 243);
wSheet.AddPicture(pic);
wSheet.Cells[rows, 0] = new Cell("some text");
wBook.Worksheets.Add(wSheet);
context.Response.AddHeader("Content-Disposition","Attachment;Filename=PlattShoppingCart.xls");
context.Response.ContentType = "application/vnd.ms-excel";
MemoryStream stream = new MemoryStream();
wBook.SaveToStream(stream);
context.Response.BinaryWrite(stream.ToArray());
This question and answer uses Microsoft.Interop Excel, but it accomplishes the same task. 此问题和答案使用Microsoft.Interop Excel,但它完成相同的任务。 Probably not the answer you need, but I got it to work just fine.
可能不是您需要的答案,但我认为它可以正常工作。 Of course, I was already using the interop stuff, just needed to modify the code a little to get it work.
当然,我已经在使用互操作性东西,只需要稍微修改一下代码即可使其工作。
I wonder if you forgot to add the ExcelLibrary equivalent of 我想知道您是否忘记添加等效的ExcelLibrary
pic.Placement = // Can be any of Excel.XlPlacement.XYZ value
I don't know if it was just me or it's actually not anywhere in the documentation, but *.bmp, *.jpeg, *.gif', are not supported and it worked by simply turning it into a .png.... 我不知道它只是我还是它实际上不在文档中的任何地方,但是不支持* .bmp,*。jpeg,*。gif',它只是将其转换为.png即可使用... 。
Thanks for the link though as it was an experience to compare it to other methods. 感谢您提供的链接,因为将它与其他方法进行比较是一种体验。 Here are some other links if you find yourself getting this far and you still have issues:
如果您发现自己仍然无法解决问题,还可以通过以下其他链接进行操作:
http://www.codeproject.com/Questions/793324/How-Do-I-Insert-Jpg-Image-From-File-Stream http://www.codeproject.com/Questions/793324/How-Do-I-Insert-Jpg-Image-From-File-Stream
http://www.codeproject.com/Questions/84487/How-to-insert-a-picture-image-in-XML-spreadsheet http://www.codeproject.com/Questions/84487/How-to-insert-a-picture-image-in-XML-spreadsheet
How Do I Create a System.Windows.Media.ImageSource From a Byte Array? 如何从字节数组创建System.Windows.Media.ImageSource?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.