从c#中提取Word文档中的项目符号和表格信息

发布于 2024-09-05 12:50:27 字数 701 浏览 0 评论 0原文

我需要根据c#中的模板创建一个word文档。我只有段落的标签。有没有办法根据用户输入替换模板中已有的项目符号和表格。

我能够使用 Word InterOp 中的“替换”命令将段落替换为输入文本。

需要帮助来完成其余的项目。

  1. 根据用户输入替换项目符号
  2. 用输入值填写表格

用于根据标签替换段落的代码:

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.

  1. Replace the bullets based on the user input
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凶凌 2024-09-12 12:50:28

我建议将书签放入 Word 文档中并使用它们来分配数据。

object oBookMark = "MyBookmark";
oWordDoc.Bookmarks.Item(ref oBookMark).Range.Text = "Some Text Here";

您可以使用此方法填充表格,我想您应该能够填充要点。

这是以编程方式填充 Word 模板的普遍接受的方法。匹配字符串很难准确地编写和维护,并且很容易产生意想不到的结果。通过书签,您可以知道要分配的数据以及数据的确切去向。

查看此 Coderush 项目

I'd suggest putting bookmarks into your Word document and using them to assign data.

object oBookMark = "MyBookmark";
oWordDoc.Bookmarks.Item(ref oBookMark).Range.Text = "Some Text Here";

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文