Fill table in Word Template using vb.net
I have a template with various fields that I want to fill programmatically from my VB application. The first part of the following code works fine and has no issue finding and opening the template, filling the various fields labeled with bookmarks, and then in later code, printing the template and closing.
Dim oWord As Word.Application = CreateObject("Word.Application")
Dim oDoc As Word.Document = Word.Documents.Open("C:...itemReceipt2.dotx")
oDoc.Bookmarks.Item("Date").Range.Text = Date.Now.ToShortDateString
oDoc.Bookmarks.Item("PONum").Range.Text = strPoNum
oDoc.Bookmarks.Item("Vendor").Range.Text = strVendor
oDoc.Bookmarks.Item("Memo").Range.Text = strMemo
The following does not fill the table I have built in my template.
For i = 0 To listReceiptItem.Count - 1
oDoc.Tables(1).Rows.Add(1)
oDoc.Tables.Item(1).Cell(i + 2, 1).Range.Text = listReceiptItem.Item(i).ManufacturerPartNumber
oDoc.Tables.Item(1).Cell(i + 2, 2).Range.Text = listReceiptItem.Item(i).Desc
oDoc.Tables.Item(1).Cell(i + 2, 3).Range.Text = listReceiptItem.Item(i).Quantity
oDoc.Tables.Item(1).Cell(i + 2, 4).Range.Text = listReceiptItem.Item(i).UnitOfMeasure
oDoc.Tables.Item(1).Cell(i + 2, 5).Range.Text = listReceiptItem.Item(i).Cost
oDoc.Tables.Item(1).Cell(i + 2, 6).Range.Text = listReceiptItem.Item(i).Amount
oDoc.Tables.Item(1).Cell(i + 2, 7).Range.Text = listReceiptItem.Item(i).Customer
Next
I guess I don't understand how I am supposed to reference the table in my template. I have tried building the table programmatically but making it look any good was way more effort than I expected. Obviously, it would be much simpler to just stuff each cell in the table in a manner similar to what I have above (but that works!).
Does anyone have experience filling a Word table programmatically or can point me in the right direction that would be great. Thanks!
vb.net ms-word
add a comment |
I have a template with various fields that I want to fill programmatically from my VB application. The first part of the following code works fine and has no issue finding and opening the template, filling the various fields labeled with bookmarks, and then in later code, printing the template and closing.
Dim oWord As Word.Application = CreateObject("Word.Application")
Dim oDoc As Word.Document = Word.Documents.Open("C:...itemReceipt2.dotx")
oDoc.Bookmarks.Item("Date").Range.Text = Date.Now.ToShortDateString
oDoc.Bookmarks.Item("PONum").Range.Text = strPoNum
oDoc.Bookmarks.Item("Vendor").Range.Text = strVendor
oDoc.Bookmarks.Item("Memo").Range.Text = strMemo
The following does not fill the table I have built in my template.
For i = 0 To listReceiptItem.Count - 1
oDoc.Tables(1).Rows.Add(1)
oDoc.Tables.Item(1).Cell(i + 2, 1).Range.Text = listReceiptItem.Item(i).ManufacturerPartNumber
oDoc.Tables.Item(1).Cell(i + 2, 2).Range.Text = listReceiptItem.Item(i).Desc
oDoc.Tables.Item(1).Cell(i + 2, 3).Range.Text = listReceiptItem.Item(i).Quantity
oDoc.Tables.Item(1).Cell(i + 2, 4).Range.Text = listReceiptItem.Item(i).UnitOfMeasure
oDoc.Tables.Item(1).Cell(i + 2, 5).Range.Text = listReceiptItem.Item(i).Cost
oDoc.Tables.Item(1).Cell(i + 2, 6).Range.Text = listReceiptItem.Item(i).Amount
oDoc.Tables.Item(1).Cell(i + 2, 7).Range.Text = listReceiptItem.Item(i).Customer
Next
I guess I don't understand how I am supposed to reference the table in my template. I have tried building the table programmatically but making it look any good was way more effort than I expected. Obviously, it would be much simpler to just stuff each cell in the table in a manner similar to what I have above (but that works!).
Does anyone have experience filling a Word table programmatically or can point me in the right direction that would be great. Thanks!
vb.net ms-word
Do I understand correctly: you're building this table from scratch? Or does it exist already? See if the information in this post helps stackoverflow.com/questions/51156083/…
– Cindy Meister
Nov 14 '18 at 21:57
add a comment |
I have a template with various fields that I want to fill programmatically from my VB application. The first part of the following code works fine and has no issue finding and opening the template, filling the various fields labeled with bookmarks, and then in later code, printing the template and closing.
Dim oWord As Word.Application = CreateObject("Word.Application")
Dim oDoc As Word.Document = Word.Documents.Open("C:...itemReceipt2.dotx")
oDoc.Bookmarks.Item("Date").Range.Text = Date.Now.ToShortDateString
oDoc.Bookmarks.Item("PONum").Range.Text = strPoNum
oDoc.Bookmarks.Item("Vendor").Range.Text = strVendor
oDoc.Bookmarks.Item("Memo").Range.Text = strMemo
The following does not fill the table I have built in my template.
For i = 0 To listReceiptItem.Count - 1
oDoc.Tables(1).Rows.Add(1)
oDoc.Tables.Item(1).Cell(i + 2, 1).Range.Text = listReceiptItem.Item(i).ManufacturerPartNumber
oDoc.Tables.Item(1).Cell(i + 2, 2).Range.Text = listReceiptItem.Item(i).Desc
oDoc.Tables.Item(1).Cell(i + 2, 3).Range.Text = listReceiptItem.Item(i).Quantity
oDoc.Tables.Item(1).Cell(i + 2, 4).Range.Text = listReceiptItem.Item(i).UnitOfMeasure
oDoc.Tables.Item(1).Cell(i + 2, 5).Range.Text = listReceiptItem.Item(i).Cost
oDoc.Tables.Item(1).Cell(i + 2, 6).Range.Text = listReceiptItem.Item(i).Amount
oDoc.Tables.Item(1).Cell(i + 2, 7).Range.Text = listReceiptItem.Item(i).Customer
Next
I guess I don't understand how I am supposed to reference the table in my template. I have tried building the table programmatically but making it look any good was way more effort than I expected. Obviously, it would be much simpler to just stuff each cell in the table in a manner similar to what I have above (but that works!).
Does anyone have experience filling a Word table programmatically or can point me in the right direction that would be great. Thanks!
vb.net ms-word
I have a template with various fields that I want to fill programmatically from my VB application. The first part of the following code works fine and has no issue finding and opening the template, filling the various fields labeled with bookmarks, and then in later code, printing the template and closing.
Dim oWord As Word.Application = CreateObject("Word.Application")
Dim oDoc As Word.Document = Word.Documents.Open("C:...itemReceipt2.dotx")
oDoc.Bookmarks.Item("Date").Range.Text = Date.Now.ToShortDateString
oDoc.Bookmarks.Item("PONum").Range.Text = strPoNum
oDoc.Bookmarks.Item("Vendor").Range.Text = strVendor
oDoc.Bookmarks.Item("Memo").Range.Text = strMemo
The following does not fill the table I have built in my template.
For i = 0 To listReceiptItem.Count - 1
oDoc.Tables(1).Rows.Add(1)
oDoc.Tables.Item(1).Cell(i + 2, 1).Range.Text = listReceiptItem.Item(i).ManufacturerPartNumber
oDoc.Tables.Item(1).Cell(i + 2, 2).Range.Text = listReceiptItem.Item(i).Desc
oDoc.Tables.Item(1).Cell(i + 2, 3).Range.Text = listReceiptItem.Item(i).Quantity
oDoc.Tables.Item(1).Cell(i + 2, 4).Range.Text = listReceiptItem.Item(i).UnitOfMeasure
oDoc.Tables.Item(1).Cell(i + 2, 5).Range.Text = listReceiptItem.Item(i).Cost
oDoc.Tables.Item(1).Cell(i + 2, 6).Range.Text = listReceiptItem.Item(i).Amount
oDoc.Tables.Item(1).Cell(i + 2, 7).Range.Text = listReceiptItem.Item(i).Customer
Next
I guess I don't understand how I am supposed to reference the table in my template. I have tried building the table programmatically but making it look any good was way more effort than I expected. Obviously, it would be much simpler to just stuff each cell in the table in a manner similar to what I have above (but that works!).
Does anyone have experience filling a Word table programmatically or can point me in the right direction that would be great. Thanks!
vb.net ms-word
vb.net ms-word
edited Nov 14 '18 at 21:24
Filburt
13.5k94891
13.5k94891
asked Nov 14 '18 at 21:17
WammyWammy
11
11
Do I understand correctly: you're building this table from scratch? Or does it exist already? See if the information in this post helps stackoverflow.com/questions/51156083/…
– Cindy Meister
Nov 14 '18 at 21:57
add a comment |
Do I understand correctly: you're building this table from scratch? Or does it exist already? See if the information in this post helps stackoverflow.com/questions/51156083/…
– Cindy Meister
Nov 14 '18 at 21:57
Do I understand correctly: you're building this table from scratch? Or does it exist already? See if the information in this post helps stackoverflow.com/questions/51156083/…
– Cindy Meister
Nov 14 '18 at 21:57
Do I understand correctly: you're building this table from scratch? Or does it exist already? See if the information in this post helps stackoverflow.com/questions/51156083/…
– Cindy Meister
Nov 14 '18 at 21:57
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308856%2ffill-table-in-word-template-using-vb-net%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308856%2ffill-table-in-word-template-using-vb-net%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do I understand correctly: you're building this table from scratch? Or does it exist already? See if the information in this post helps stackoverflow.com/questions/51156083/…
– Cindy Meister
Nov 14 '18 at 21:57