Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

.net - Populate Table in Word document template with table using 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.

enter image description here

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  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];

  2. 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...