简体   繁体   English

我正在尝试使用带有图片和CellAnchor的ExcelLibrary将图像插入excel文档中,但图像不显示

[英]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.

相关问题 我正在尝试上传图像并绑定Gridview以显示图像? - I'm trying to upload image and binding Gridview to display image? C#和OpenXML:将图像插入Excel文档 - C# & OpenXML: Insert an image into an excel document 图片框不显示图像 - Picture Box doesn't show image 如果我使用路径库,图像不会从wwwroot加载 - Image doesn't load from wwwroot if I'm using path base 如何通过链接而不是图像文件通过Spreadsheet Light将图片插入Excel电子表格? - How can I insert a picture into an Excel spreadsheet with Spreadsheet Light from a link rather than an image file? 如何使用Epplus在Excel中从Base64编码图像中插入图片 - How to insert picture in Excel from Base64 encoded image using Epplus 我正在尝试从我的数据库中显示图像,但图像不会填充img html属性的src - I'm trying to display an image from my database, but the image wont populate the src of the img html attribute 使用iTextSharp将图像添加到文档中时,为什么没有显示图像? - Why doesn't an Image show up when I add it to a Document using iTextSharp? dataGrid不显示图像 - dataGrid doesn't display the image 无法打开使用excelLibrary生成的excel文件 - Can't open excel file generated with excelLibrary
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM