word文档的摘要通常包括文档主题、作者、所属公司、关键字等信息,自定义属性则可以包含更多附加信息,例如创建时间,联系电话,文档编号等。恰当的摘要及自定义属性可以帮助读者快速了解文档所要传递的信息。
本文将展示如何使用spire.doc为word添加摘要和自定义属性,以及如何获取现有文档的文档属性。
添加摘要和自定义属性
c#
//创建文档
document doc = new document();
//添加section
section section = doc.addsection();
//添加预设文档属性
builtindocumentproperties builtinproperties = doc.builtindocumentproperties;
builtinproperties.title = "_怎样使用spire.doc设置文档属性";
builtinproperties.subject = "无";
builtinproperties.author = "spire.doc";
builtinproperties.manager = "bill.zhou";
builtinproperties.company = "_成都冰蓝科技有限公司";
builtinproperties.category = "展示文档";
builtinproperties.keywords = "word文档摘要, 自定义属性";
builtinproperties.comments = "更多在线教程,请参考e-iceblue官方网站";
//添加自定义文档属性
customdocumentproperties customproperties = doc.customdocumentproperties;
customproperties.add("是否加密", false);
customproperties.add("_创建时间", datetime.now);
customproperties.add("联系电话", "028-81705109");
//保存文档
doc.savetofile("set_properties.docx");
获取现有文档的属性
c#
//加载测试文档
document doc = new document();
doc.loadfromfile("set_properties.docx");
//获取预设文档属性
console.writeline("摘要\n");
console.writeline(("_标题: " doc.builtindocumentproperties.title));
console.writeline(("主题: " doc.builtindocumentproperties.subject));
console.writeline(("作者_: " doc.builtindocumentproperties.author));
console.writeline(("主管: " doc.builtindocumentproperties.manager));
console.writeline(("单位: " doc.builtindocumentproperties.company));
console.writeline(("类别: " doc.builtindocumentproperties.category));
console.writeline(("关键字: " doc.builtindocumentproperties.keywords));
console.writeline(("_备注: " doc.builtindocumentproperties.comments));
//获取自定义文档属性
console.writeline("\n自定义属性\n");
for (int i = 0;i < doc.customdocumentproperties.count;i )
{
console.writeline((doc.customdocumentproperties[i].name (": " doc.customdocumentproperties[i].value)));
i = (i 1);
}
console.read();
vb.net
dim doc as document = new document
doc.loadfromfile("set_properties.docx")
console.writeline("摘要\n")
console.writeline(("标题: " doc.builtindocumentproperties.title))
console.writeline(("主题: " doc.builtindocumentproperties.subject))
console.writeline(("作者: " doc.builtindocumentproperties.author))
console.writeline(("主管: " doc.builtindocumentproperties.manager))
console.writeline(("单位: " doc.builtindocumentproperties.company))
console.writeline(("类别: " doc.builtindocumentproperties.category))
console.writeline(("关键字: " doc.builtindocumentproperties.keywords))
console.writeline(("备注: " doc.builtindocumentproperties.comments))
console.writeline("\n自定义属性\n")
dim i as integer = 0
do while (i < doc.customdocumentproperties.count)
console.writeline((doc.customdocumentproperties(i).name (": " doc.customdocumentproperties(i).value)))
i = (i 1)
loop
console.read