本文将介绍如何使用spire.xls for .net转换excel中的形状和smartart图形到图片。
原excel文档:
c#
using spire.xls;
using system.collections.generic;
using system.drawing;
using system.drawing.imaging;
namespace convert_shapes_and_smartart_to_image
{
class program
{
static void main(string[] args)
{
//创建workbook对象
workbook workbook = new workbook();
//加载excel文档
workbook.loadfromfile("sample.xlsx");
//获取第一个工作表
worksheet sheet = workbook.worksheets[0];
//创建saveshapetypeoption对象
saveshapetypeoption shapelist = new saveshapetypeoption();
//保存工作表中的形状和smartart图形到图片
list images = sheet.saveshapestoimage(shapelist);
//保存图片到指定路径
int index = 0;
foreach (image img in images)
{
img.save("image/" "toimage" index ".png", imageformat.png);
index ;
}
}
}
}
vb.net
imports spire.xls
imports system.collections.generic
imports system.drawing.imaging
namespace convert_shapes_and_smartart_to_image
friend class program
private shared sub main(byval args as string())
'创建workbook对象
dim workbook as workbook = new workbook()
'加载excel文档
workbook.loadfromfile("sample.xlsx")
'获取第一个工作表
dim sheet as worksheet = workbook.worksheets(0)
'创建saveshapetypeoption对象
dim shapelist as saveshapetypeoption = new saveshapetypeoption()
'保存工作表中的形状和smartart图形到图片
dim images as list(of bitmap) = sheet.saveshapestoimage(shapelist)
'保存图片到指定路径
dim index as integer = 0
for each img as image in images
img.save("image/" & "toimage" & index & ".png", imageformat.png)
index = 1
next
end sub
end class
end namespace
转换结果: