Заполнение шаблона Word - Visual Basic .NET
Формулировка задачи:
В шаблоне есть таблица, как заполнить ее построчно из текстбокса?
Решение задачи: «Заполнение шаблона Word»
textual
Листинг программы
Imports Microsoft.Office.Interop
Public Class Form2
Private objWD As New Word.Application
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
With objWD
.Documents.Add("C:\00\tstTemplate.dot")
Dim doc As Word.Document = .ActiveDocument
Dim ir As Integer = 1
With doc.Tables(1)
For Each str As String In TextBox1.Lines
Dim ccs() As String = str.Split(ChrW(32))
ir += 1
For ic = 1 To 4
.Cell(ir, ic).Range.Text = ccs(ic - 1)
Next
If ir < TextBox1.Lines.Count Then .Rows.Add()
Next
End With
.Visible = True
End With
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
objWD.ActiveDocument.SaveAs("C:\00\tstDocument.doc")
objWD.Documents.Close()
objWD.Quit()
End Sub
End Class