excel文档的摘要通常包括文档标题、作者、所属单位、关键字等信息,自定义属性则可以包含更多附加信息,例如创建时间,联系电话,文档编号等。读者可以从excel文档属性快速了解该文档的大概主要信息。本文将展示如何使用spire.xls为excel 文档添加摘要和自定义属性,以及如何获取现有文档的文档属性。
添加摘要和自定义属性
c#
//加载excel文档
workbook workbook = new workbook();
workbook.loadfromfile("test.xlsx");
//设置摘要
workbook.documentproperties.author = "spire.xls";
workbook.documentproperties.title = "如何设置excel摘要";
workbook.documentproperties.keywords = "excel摘要,自定义属性";
workbook.documentproperties.category = "展示文档";
workbook.documentproperties.company = "成都冰蓝科技有限公司";
//设置自定义属性
workbook.customdocumentproperties.add("_markasfinal", true);
workbook.customdocumentproperties.add("联系电话", 81705109);
workbook.customdocumentproperties.add("更新时间", datetime.now);
//保存文档
workbook.savetofile("result.xlsx", fileformat.version2010);
vb.net
'加载excel文档
dim workbook as new workbook()
workbook.loadfromfile("test.xlsx")
'设置摘要
workbook.documentproperties.author = "spire.xls"
workbook.documentproperties.title = "如何设置excel摘要"
workbook.documentproperties.keywords = "excel摘要,自定义属性"
workbook.documentproperties.category = "展示文档"
workbook.documentproperties.company = "成都冰蓝科技有限公司"
'设置自定义属性
workbook.customdocumentproperties.add("_markasfinal", true)
workbook.customdocumentproperties.add("联系电话", 81705109)
workbook.customdocumentproperties.add("更新时间", datetime.now)
'保存文档
workbook.savetofile("result.xlsx", fileformat.version2010)
获取现有的文档属性
c#
//加载excel文档
workbook workbook = new workbook();
workbook.loadfromfile("result.xlsx");
//获取摘要
builtindocumentproperties p = workbook.documentproperties;
//获取自定义属性
icustomdocumentproperties properties = workbook.customdocumentproperties;
for (int i = 0; i < properties.count; i )
{
string name = properties[i].name;
string value = properties[i].value as string;
}
vb.net
'加载excel文档
dim workbook as new workbook()
workbook.loadfromfile("result.xlsx")
'获取摘要
dim p as builtindocumentproperties = workbook.documentproperties
'获取自定义属性
dim properties as icustomdocumentproperties = workbook.customdocumentproperties
for i as integer = 0 to properties.count - 1
dim name as string = properties(i).name
dim value as string = trycast(properties(i).value, string)
next