Aspose.cells 读取Excel表中的图片问题

2022-11-25,,,,

一、说明

本文主要是讲解,怎么使用aspose.cells读取Excel表中的图片,并把图片转换成流或是image对象。

二、开发环境说明

开发工具vs2012,c#语言,

三、Aspose.cells读取Excel数据表中图片的代码

 //Excel表的路径
string path = Application.StartupPath + @"\excel\用地调查摸底表.xlsx";
//winform窗体上的按钮事件
private void button2_Click(object sender, EventArgs e)
{
Workbook book = new Workbook(path);
Worksheet sheet = book.Worksheets[];
//aspose.cells 从Excel数据表中读取的图片存放在sheet.Pictures[0]中,前提是Excel中只有一张图片,有多张//图片遍历即可
this.pictureBox1.Image = ChangeToImage(sheet.Pictures[]);
}
//把Aspose.Cells.Drawing.Picture对象转换为Image对象
private Image ChangeToImage(Aspose.Cells.Drawing.Picture pic)
{
ImageOrPrintOptions printOption = new ImageOrPrintOptions(); //图片格式
printOption.ImageFormat = pic.ImageFormat;
MemoryStream mstream = new MemoryStream(); pic.ToImage(mstream, printOption); // 保存(参数为:内存流和图片格式)
Bitmap img = new Bitmap(mstream);
return img;
}

四、读取的图片转换为流

    private MemoryStream ChangeToStream(Aspose.Cells.Drawing.Picture pic, ref )
{
ImageOrPrintOptions printOption = new ImageOrPrintOptions(); //图片格式
printOption.ImageFormat = pic.ImageFormat;
MemoryStream mstream = new MemoryStream();
pic.ToImage(mstream, printOption); // 保存(参数为:内存流和图片格式)
return mstream ;
}

Aspose.cells 读取Excel表中的图片问题的相关教程结束。

《Aspose.cells 读取Excel表中的图片问题.doc》

下载本文的Word格式文档,以方便收藏与打印。