Aspose.cells 讀取Excel表中的圖片問題


一、說明

本文主要是講解,怎么使用aspose.cells讀取Excel表中的圖片,並把圖片轉換成流或是image對象。

二、開發環境說明

開發工具vs2012,c#語言,

三、Aspose.cells讀取Excel數據表中圖片的代碼

 1 //Excel表的路徑
 2   string path = Application.StartupPath +  @"\excel\用地調查摸底表.xlsx";
 3 //winform窗體上的按鈕事件
 4   private void button2_Click(object sender, EventArgs e)
 5         {
 6             Workbook book = new Workbook(path);
 7             Worksheet sheet = book.Worksheets[0];
 8          //aspose.cells 從Excel數據表中讀取的圖片存放在sheet.Pictures[0]中,前提是Excel中只有一張圖片,有多張//圖片遍歷即可           
 9             this.pictureBox1.Image = ChangeToImage(sheet.Pictures[0]); 
10         }
11 //把Aspose.Cells.Drawing.Picture對象轉換為Image對象
12    private Image ChangeToImage(Aspose.Cells.Drawing.Picture pic)
13         {
14             ImageOrPrintOptions printOption = new ImageOrPrintOptions(); //圖片格式
15             printOption.ImageFormat = pic.ImageFormat;
16            MemoryStream  mstream = new MemoryStream();           
17      
18             pic.ToImage(mstream, printOption);  // 保存(參數為:內存流和圖片格式)
19             Bitmap img = new Bitmap(mstream);
20             return img;
21         }
View Code

四、讀取的圖片轉換為流

1    private MemoryStream ChangeToStream(Aspose.Cells.Drawing.Picture pic, ref )
2         {
3             ImageOrPrintOptions printOption = new ImageOrPrintOptions(); //圖片格式
4             printOption.ImageFormat = pic.ImageFormat;
5           MemoryStream mstream = new MemoryStream();
6             pic.ToImage(mstream, printOption);  // 保存(參數為:內存流和圖片格式)
7 return mstream ;
8         }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM