This article is a mirror article of machine translation, please click here to jump to the original article.

View: 5606|Reply: 6

[Source] VSTO (III) Inserts DataTable data into a Word document

[Copy link]
Posted on 2023-4-30 23:30:35 | | | |
Requirements: Use ADO.NET to execute SQL statements to return query result data as DataTable objects, and finally, insert DataTable data into a Word document to display it as a table.

First, let's take a look at the renderings:



Create a new Word document and set the custom ribbon ->Development tools(checked), as shown in the figure below:



According to your needs, add the "Build Base Library Content Control" to the Word document, as shown in the following figure:



Content Control object (Content Control Object) typeWdContentControlTypeThe enumeration (type of content control) is as follows:

name
value
Description
wdContentControlBuildingBlockGallery5Specifies the build block library content control.
wdContentControlCheckbox8Specify the checkbox content control.
wdContentControlComboBox3Specifies the combobox content control.
wdContentControlDate6Specify a date content control.
wdContentControlGroup7Specify group content controls.
wdContentControlDropdownList4Specify the drop-down content controls.
wdContentControlPicture2Specifies the image content control.
wdContentControlRepeatingSection9Specifies duplicate partial content controls.
wdContentControlRichText0Specifies RTF content controls.
wdContentControlText1Specifies text content controls.

Reference:The hyperlink login is visible.

The DataTable object code returned via ADO.NET by executing a SQL statement is as follows:

Insert the DataTable object queried from the database into the location marked test1 in the word document with the following code:

After clicking the "Insert Table" button in the Word plugin, our content controls are populated with a table, as shown below:


(End)





Previous:VSTO (2) Get the Word Chinese character length selection plug-in
Next:Introduction to the IParsable interface added to .NET 7
 Landlord| Posted on 2023-4-30 23:32:19 |
VSTO (1) Brief introduction and development tools
https://www.itsvse.com/thread-10573-1-1.html

VSTO (2) Get the Word Chinese character length selection plug-in
https://www.itsvse.com/thread-10574-1-1.html

VSTO (III) Inserts DataTable data into a Word document
https://www.itsvse.com/thread-10575-1-1.html
Posted on 2023-5-2 10:31:48 |
Learn it
 Landlord| Posted on 2023-5-2 11:25:35 |
rg. Tables.Add to

 Landlord| Posted on 2023-5-2 15:04:52 |


Control lock
 Landlord| Posted on 2023-5-7 09:27:07 |
VSTO (VI) cancels or blocks the Word document from being saved
https://www.itsvse.com/thread-10581-1-1.html

VSTO (V) Deletes content controls in Word
https://www.itsvse.com/thread-10579-1-1.html

VSTO (IV) Fill the picture into a Word document
https://www.itsvse.com/thread-10578-1-1.html
 Landlord| Posted on 2023-5-22 20:30:36 |
Aspose(1)Aspose.Words populates the table into a word document
https://www.itsvse.com/thread-10593-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com