使用C#使用表填充Word文档模板中的表 [英] Populate Table in Word document template with table using C#

查看:226
本文介绍了使用C#使用表填充Word文档模板中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个.dot,并放置了一个简单的表.字段TESTE_1和TESTE_2来自快速部件>>字段",我想使用C#代码从数据库(外部文件或任何其他文件)填充此表.

I created a .dot, and put a simple table. The fields, TESTE_1 and TESTE_2 are from "Quick Parts >> Field " I want to populate this table from database (external files, or whatever) using C# Code.

我在表格单元格(Test1)中放置了一个"MergeField".有很多代码显示如何查找和替换"这些书签,但是如何填充我找不到的表,例如:

I put a "MergeField" in the table cells (Test1). There a lot of codes showing how to "find and replace" these bookmarks, But how to fill a table I not found, like:

Column1 | Column2 Foo | Bar Zee | Top.

Column1 | Column2 Foo | Bar Zee | Top.

推荐答案

由于您的主要问题是如何在文档中找到表格,然后使用它:

Since your main problem is how to locate the table in the document, then work with it:

  1. 选择表格并在其周围插入一个书签.这将使您的代码直接选择表格:

  1. Select the table and insert a Bookmark around it. This will allow your code to pick up the table directly:

Word.Table tbl = Doc.Bookmarks.get_item("Name").Range.Tables [1];

Word.Table tbl = Doc.Bookmarks.get_item("Name").Range.Tables[1];

这是一篇可以帮助您在Word中使用表的文章.它还讨论了性能问题: https://msdn.microsoft.com/zh-cn/library/aa537149%28v=office.11​​%29.aspx?f=255&MSPPError=-2147217396

Here's an article that will help you working with tables in Word. It also discusses performance issues: https://msdn.microsoft.com/en-us/library/aa537149%28v=office.11%29.aspx?f=255&MSPPError=-2147217396

这篇关于使用C#使用表填充Word文档模板中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆