spire.xls支持将excel工作表转换为常见的图片格式, 如jpeg, png, bmp, wmf, emf 和tiff等。当excel工作表中含有excel图表时,spire.xls也支持仅将excel图表保存为图片格式。下面将介绍如何使用spire.xls将 excel 工作表 和excel图表保存为图片格式。
excel工作表转图片
[c#]
//初始化workbook实例
workbook workbook = new workbook();
//加载excel文档
workbook.loadfromfile("sample.xlsx");
//获取第一个工作表
worksheet sheet = workbook.worksheets[0];
//将工作表保存为图片
sheet.savetoimage("exceltoimage.png", imageformat.png);
[vb.net]
dim workbook as new workbook()
workbook.loadfromfile("sample.xlsx")
dim sheet as worksheet = workbook.worksheets(0)
sheet.savetoimage("exceltoimage.png", imageformat.png)
excel工作表中的图表转图片
[c#]
//初始化workbook实例
workbook workbook = new workbook();
//加载excel文档
workbook.loadfromfile("sample.xlsx");
/获取第一个工作表
worksheet sheet = workbook.worksheets[0];
//将图表保存为图片
image[] imgs = workbook.savechartasimage(sheet);
for (int i = 0; i < imgs.length; i )
{
imgs[i].save(string.format("img-{0}.png", i), imageformat.png);
}
[vb.net]
dim workbook as new workbook()
workbook.loadfromfile("sample.xlsx")
dim sheet as worksheet = workbook.worksheets(0)
dim imgs as image() = workbook.savechartasimage(sheet)
for i as integer = 0 to imgs.length - 1
imgs(i).save(string.format("img-{0}.png", i), imageformat.png)
next
excel工作表中的两个图表存为两张图片: