簡體   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