前面我们介绍了如何使用spire.xls , 该文将介绍如何将html格式文件保存为excel文档。
首先,请查看html示例文档
c#
using spire.xls;
namespace html_to_excel
{
class program
{
static void main(string[] args)
{
//加载示例文档
workbook workbook = new workbook();
workbook.loadfromhtml("sample.html");
//自适应行高
worksheet sheet = workbook.worksheets[0];
sheet.allocatedrange.autofitrows();
//保存文档
workbook.savetofile("result.xlsx",fileformat.version2010);
}
}
}
vb.net
imports spire.xls
namespace html_to_excel
class program
private shared sub main(byval args() as string)
'加载示例文档
dim workbook as workbook = new workbook
workbook.loadfromhtml("sample.html")
'自适应行高
dim sheet as worksheet = workbook.worksheets(0)
sheet.allocatedrange.autofitrows
'保存文档
workbook.savetofile("result.xlsx", fileformat.version2010)
end sub
end class
end namespace
效果图: