Microsoft Word 2007 VSTO,在word之外创建表格?

发布于 2024-08-18 17:00:57 字数 690 浏览 2 评论 0原文

我正在使用 VSTO 将数据填充到 Microsoft Word 2007 模板中的表中。数据量各不相同,填充许多页 (+50) 需要花费大量时间。

我用来创建表格的代码:

Word.Table table = doc.Tables.Add(tablePosition, 
                                  numberOfRows, 
                                  8, 
                                  ref System.Reflection.Missing.Value, 
                                  ref System.Reflection.Missing.Value);

我怀疑时间消耗是由于每次将数据插入单元格时 Visual Studio (C#) 和 Word 之间的通信造成的。如果是这种情况,在 C# 中创建表然后将其插入到 Word 中可能会更快。

Microsot.Office.Interop.Word.Table 是一个抽象类 - 因此我无法做到这一点,

Word.Table table = new Word.Table();

这本来会很方便。

只使用VSTO还有其他可能性吗?

I am using VSTO to fill data into a table in a Microsoft Word 2007 template. The amount of data varies and filling many pages (+50) takes a lot of time.

The code I use to create a table:

Word.Table table = doc.Tables.Add(tablePosition, 
                                  numberOfRows, 
                                  8, 
                                  ref System.Reflection.Missing.Value, 
                                  ref System.Reflection.Missing.Value);

I suspect that the time consumption is due to the communication between Visual Studio (C#) and Word each time I insert data into a cell. If this is the case, it might be faster to create the table in C# and afterwards insert it into Word.

The Microsot.Office.Interop.Word.Table is an abstract class - thus I cannot do this

Word.Table table = new Word.Table();

which would have been handy.

Are there other possibilities when just using VSTO?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

离去的眼神 2024-08-25 17:00:57
  • 尝试以 HTML 剪贴板格式创建表格,添加到剪贴板,然后粘贴。
  • 尝试在 HTML 中创建表格并插入它。
  • 尝试为每条记录创建带有换行符的制表符分隔字符串。插入带有选择的字符串,使用制表符作为分隔符将选择转换为表格。
  • 创建 XML 格式的模板,使用 Xslt 将数据转换为 Word XML 文档。
  • 创建模板作为“目录邮件合并”,执行与数据的邮件合并。

根据您的要求,我建议使用邮件合并技术,因为用户可以编辑模板并且邮件合并速度很快,尤其是在您有 50 多个页面。

  • Try creating the table in HTML Clipboard format, add to clipboard, then paste.
  • Try creating the table in HTML and inserting it.
  • Try creating tab-delimited string with newline character for each record. Insert string with selection, convert selection to table using tabs as delimiter.
  • Create template as XML, transforming data with Xslt into Word XML Document.
  • Create template as a "Directory Mail Merge", perform mail merge with data.

Depending on your requirements, I recommend using the mail merge technique because the user can edit the template and mail merges are fast, especially if you have 50+ pages.

不离久伴 2024-08-25 17:00:57

虽然我用LabVIEW7.1和Word2000做了类似的事情,但问题是相似的。我还没有找到一种用一个命令插入数据块(表)的方法。甚至在插入单个元素对于单词来说太快时甚至会出现问题,它有时会挂起并且必须被杀死才能解决这个问题。不幸的是,没有任何事件或属性表明单词有能力接受下一个命令和数据集 - 至少我找不到任何东西。
由于这是在测试定序器中,因此我有时间将测试结果输入到 word 中,并且延迟时间足够长,以便在发送下一部分数据时假设 word 再次准备好......

Although I do similar things with LabVIEW7.1 and Word2000, the problem is similar. I have not found a way to insert blocks of data (table) with one command. There is even a problem when inserting single elements too fast for word, it occasionally hangs than and must be killed in order to solve that. Unfortunately there is no event nor property that signals word's ability to accept the next command and data set - at least I could not find anything.
As this is in a test sequencer I have the time to feed the test results into word with delays long enough to assume word is ready again when the next portion of data is send...

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