How to Set Word Document Properties with C#

Word properties shows a brief description about one document. Through properties, we can learn general information about this document, such as document size, date to create and so on. Also, we can set advance properties by ourselves, for example, adding document title, author information. In this post, I want to introduce a method about how to set Word document properties with C# via Spire.Doc.

//Create word document
Document document = new Document();

document.BuiltinDocumentProperties.Title = "Document Properties";
document.BuiltinDocumentProperties.Subject = "demo";
document.BuiltinDocumentProperties.Author = "S.W";
document.BuiltinDocumentProperties.Company = "e-iceblue";
document.BuiltinDocumentProperties.Manager = "H.H";
document.BuiltinDocumentProperties.Category = "Document Setting";
document.BuiltinDocumentProperties.Keywords = "Property, Setting, Word";
document.BuiltinDocumentProperties.Comments = "This is just an example.";

Section section = document.AddSection();
section.PageSetup.Margins.Top = 72f;
section.PageSetup.Margins.Bottom = 72f;
section.PageSetup.Margins.Left = 89.85f;
section.PageSetup.Margins.Right = 89.85f;

String p1
    = "Microsoft Word is a word processor designed by Microsoft. "
    + "It was first released in 1983 under the name Multi-Tool Word for Xenix systems. "
    + "Subsequent versions were later written for several other platforms including "
    + "IBM PCs running DOS (1983), the Apple Macintosh (1984), the AT&T Unix PC (1985), "
    + "Atari ST (1986), SCO UNIX, OS/2, and Microsoft Windows (1989). ";
String p2
    = "Microsoft Office Word instead of merely Microsoft Word. "
    + "The 2010 version appears to be branded as Microsoft Word, "
    + "once again. The current versions are Microsoft Word 2010 for Windows and 2008 for Mac.";
section.AddParagraph().AppendText(p1).CharacterFormat.FontSize = 14;
section.AddParagraph().AppendText(p2).CharacterFormat.FontSize = 14;


//Save doc file.
document.SaveToFile("Sample.doc",FileFormat.Doc);

posted on   大西瓜3721  阅读(645)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)

导航

点击右上角即可分享
微信分享提示