原創|其它|編輯:郝浩|2012-10-16 15:31:59.000|閱讀 1093 次
概述:此demo只是講出使用Aspose.Cells 獲取Excel插入附件的原理,代碼較簡單。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
引入using Aspose.Cells;
(Aspose.Cells下載地址//fc6vip.cn/zh-CN/product/563/download.aspx)
此demo只是講出取Excel插入附件的原理,代碼較簡單
private void AsponseTest() { Workbook awork = new Workbook(textBox1.Text); Worksheet asheet = awork.Worksheets[0]; Workbook awork2 = new Workbook(); Worksheet asheet2 = awork2.Worksheets[0]; try { byte[] imageData = null; byte[] objectData = null; string sourceFullName = ""; int upperLeftRow = 0; int upperLeftColumn = 0; int height = 0; int width = 0; bool displayAsIcon = false; Aspose.Cells.Drawing.OleFileType fileType = Aspose.Cells.Drawing.OleFileType.Xls; string progID = ""; //循環的去除插入的對象 foreach (Aspose.Cells.Drawing.OleObject item in asheet.OleObjects) { //獲取對象屬性,為生成新的Excel插入對象使用 imageData = item.ImageData; //對象圖標 objectData = item.ObjectData; //對象內同 sourceFullName = item.SourceFullName; upperLeftRow = item.UpperLeftRow; upperLeftColumn = item.UpperLeftColumn; height = item.Height; width = item.Width; displayAsIcon = item.DisplayAsIcon; fileType = item.FileType; progID = item.ProgID; asheet2.OleObjects.Add(upperLeftRow, upperLeftColumn, height, width, imageData); //此功能是讀取出一個圖片,并另存為 MemoryStream outputImage = new MemoryStream(imageData, 0, (int)imageData.Length); Image returnImage = Image.FromStream(outputImage); pictureBox1.Image = returnImage; File.WriteAllBytes(@"C:\Users\ZhangYu\Desktop\2.txt", objectData); } //生成新的Excel,插入附件,此方法暫時只是舉例插入一個對象,若需要插入多個對象,則看情況改邏輯就可以 foreach (Aspose.Cells.Drawing.OleObject item in asheet2.OleObjects) { item.ObjectData = objectData; item.SourceFullName = sourceFullName; item.DisplayAsIcon = displayAsIcon; item.FileType = fileType; item.SetNativeSourceFullName(sourceFullName); item.ProgID = progID; } int count = asheet.OleObjects.Count; awork2.Save(targetPath); } catch (Exception ex) { }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:KeyRainie的專欄-CSDN