从c#中提取Word文档中的项目符号和表格信息
我需要根据c#中的模板创建一个word文档。我只有段落的标签。有没有办法根据用户输入替换模板中已有的项目符号和表格。
我能够使用 Word InterOp 中的“替换”命令将段落替换为输入文本。
需要帮助来完成其余的项目。
- 根据用户输入替换项目符号
- 用输入值填写表格
用于根据标签替换段落的代码:
FindAndReplace(wordApplication, "/date/", DateTime.Now.Date.ToString("MMM dd, yyyy"));
FindAndReplace(){
wordApplication.Selection.Find.Execute(ref findText,
ref matchCase, ref matchWholeWord, ref matchWildCards, ref matchSoundsLike,
ref matchAllWordsForms, ref forward, ref wrap, ref format, ref replaceWithText, ref replace, ref matchKashida,
ref matchDiacritics, ref matchAlefHamsa, ref matchControl);
}
提前致谢。尽快
I need to create an word document based on the template in c#. I have tags for only the paragraphs. Is there any way to replace the bullets and tables that are already available in the template based on the user input.
I was able to replace the paragraph with input text using the Replace command in the Word InterOp.
Need help to do the rest of the items.
- Replace the bullets based on the user input
- Fill the tables with the input values
Code for replacing the Paragraph based on the tag:
FindAndReplace(wordApplication, "/date/", DateTime.Now.Date.ToString("MMM dd, yyyy"));
FindAndReplace(){
wordApplication.Selection.Find.Execute(ref findText,
ref matchCase, ref matchWholeWord, ref matchWildCards, ref matchSoundsLike,
ref matchAllWordsForms, ref forward, ref wrap, ref format, ref replaceWithText, ref replace, ref matchKashida,
ref matchDiacritics, ref matchAlefHamsa, ref matchControl);
}
Thanks in Advance. ASAP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议将书签放入 Word 文档中并使用它们来分配数据。
您可以使用此方法填充表格,我想您应该能够填充要点。
这是以编程方式填充 Word 模板的普遍接受的方法。匹配字符串很难准确地编写和维护,并且很容易产生意想不到的结果。通过书签,您可以知道要分配的数据以及数据的确切去向。
查看此 Coderush 项目。
I'd suggest putting bookmarks into your Word document and using them to assign data.
You can populate tables using this method and I imagine you should be able to populate bullet points.
This is the generally accepted way to programmatically populate a Word template. Matching strings is difficult to write and maintain accurately and can easily yield unexpected results. With a bookmark, you know what data you're assigning and exactly where it's going.
Take a look at this Coderush project.