C#-添加、读取Word脚注尾注.docxVIP

  • 1
  • 0
  • 约4.03千字
  • 约 7页
  • 2018-05-31 发布于福建
  • 举报
C# 添加、读取Word脚注、尾注脚注和尾注是对文本的补充说明。脚注一般位于页面的底部,可以作为文档某处内容的注释;尾注一般位于文档的末尾,列出引文的出处等。在本示例中将介绍如何来添加和读取Word脚注尾注。工具使用: Free Spire. Doc for .NET1.dll引用2.添加Word脚注、尾注【C#】using Spire.Doc;usingSpire.Doc.Documents;usingSpire.Doc.Fields;usingSystem.Drawing;namespaceInsertFootnote_Doc{classProgram {staticvoid Main(string[] args) {//新建一个word文档对象并加载需要添加脚注尾注的word文档Documentdocument = newDocument();document.LoadFromFile(sample.docx, FileFormat.Docx2010);//获取第3个段落Paragraphparagraph = document.Sections[0].Paragraphs[2];//添加脚注Footnotefootnote = paragraph.AppendFootnote(FootnoteType.Footnote);//在第一段里查找指定字符串,并添加脚注DocumentObjectobj = null;for (inti = 0; i paragraph.ChildObjects.Count; i++) {obj = paragraph.ChildObjects[i];if (obj.DocumentObjectType == DocumentObjectType.TextRange) {TextRangetextRange = objasTextRange;if (textRange.Text == 中国——东盟自贸区框架) {//为添加脚注的字符串设置加粗格式textRange.CharacterFormat.Bold = true;//插入脚注paragraph.ChildObjects.Insert(i + 1, footnote);break; } } }//添加脚注内容被设置字体格式TextRange text = footnote.TextBody.AddParagraph().AppendText(2002年11月4日,朱镕基总理和东盟10国领导人共同签署了《中国-东盟全面经济合作框架协议》,这标志着中国与东盟的经贸合作进入了一个新的历史阶段。);text.CharacterFormat.FontName = Arial Black;text.CharacterFormat.FontSize = 9;text.CharacterFormat.TextColor = Color.DarkGray;footnote.MarkerCharacterFormat.FontName = Calibri;footnote.MarkerCharacterFormat.FontSize = 12;footnote.MarkerCharacterFormat.Bold = true;footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;//获取第5段落Paragraph paragraph2 = document.Sections[0].Paragraphs[4];//添加尾注并设置尾注和格式Footnote endnote = paragraph2.AppendFootnote(FootnoteType.Endnote);TextRange text2 = endnote.TextBody.AddParagraph().AppendText(党的十七大报告明确指出:“坚持对外开放的基本国策,把‘引进来’和‘走出去’更好地结合起来,扩大开放领域,优化开放结构,提高开放质量,完善内外联动,互利共赢、安全高效的开放型经济体系,形成经济全球化条件下参与国际经济合作和竞争的新优势。); text2.CharacterFormat.FontName = Arial Black; text2.CharacterFormat.FontSize = 9; text2.CharacterFormat.Te

文档评论(0)

1亿VIP精品文档

相关文档