繁体   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

我进行了一些修剪,所以如果缺少上下文,对不起,我将进行编辑。

我没有收到任何错误,图片似乎确实已添加到工作簿对象中...

我也尝试过只插入到一个新的cell()中,但是当我要保存到流中时,它会得到一个无效的Cell值。

我使用此链接作为参考: 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());

问题和答案使用Microsoft.Interop Excel,但它完成相同的任务。 可能不是您需要的答案,但我认为它可以正常工作。 当然,我已经在使用互操作性东西,只需要稍微修改一下代码即可使其工作。

我想知道您是否忘记添加等效的ExcelLibrary

pic.Placement = // Can be any of Excel.XlPlacement.XYZ value

我不知道它只是我还是它实际上不在文档中的任何地方,但是不支持* .bmp,*。jpeg,*。gif',它只是将其转换为.png即可使用... 。

感谢您提供的链接,因为将它与其他方法进行比较是一种体验。 如果您发现自己仍然无法解决问题,还可以通过以下其他链接进行操作:

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

如何从字节数组创建System.Windows.Media.ImageSource?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM