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         }
原文地址:https://www.cnblogs.com/net064/p/9327353.html