spire.xls 支持在excel中,并在文本框中添加文本及图片,对内容进行格式化操作等。同理,对于excel工作表中已有的文本框内容,也可以通过spire.xls读取出来,包括读取文本、读取图片。
测试文档如下:
c#
//创建workbook类的对象,并加载测试文档
workbook workbook = new workbook();
workbook.loadfromfile("sample.xlsx");
//获取指定工作表
worksheet sheet = workbook.worksheets["sheet1"];
//遍历工作表中文本框
for( int i = sheet.textboxes.count-1; i >= 0; i--)
{
xlstextboxshape shape = sheet.textboxes[i] as xlstextboxshape;
//提取文本框中的文本
string s = shape.text;
stringbuilder sb = new stringbuilder();
sb.appendline(s);
file.writealltext("提取文本.txt", sb.tostring());
//提取文本框中的图片
image image = shape.fill.picture;
image.save("提取图片.png", imageformat.png);
}
vb.net
'创建workbook类的对象,并加载测试文档
dim workbook as new workbook()
workbook.loadfromfile("sample.xlsx")
'获取指定工作表
dim sheet as worksheet = workbook.worksheets("sheet1")
'遍历工作表中文本框
for i as integer = sheet.textboxes.count - 1 to 0 step -1
dim shape as xlstextboxshape = trycast(sheet.textboxes(i), xlstextboxshape)
'提取文本框中的文本
dim s as string = shape.text
dim sb as new stringbuilder()
sb.appendline(s)
file.writealltext("提取文本.txt", sb.tostring())
'提取文本框中的图片
dim image as image = shape.fill.picture
image.save("提取图片.png", imageformat.png)
next
读取结果: