how to export in word format from vb.net windows application

tutu

Member
Joined
Apr 17, 2006
Messages
12
Location
india
Programming Experience
1-3
i need to generate a bill in tabular word format from my vb.net windows application ,using sql server 2000 as the backend .please help.
 
Once you got data in your frontend form you can produce a word document with the same content. I.e. You want to export an invoice in word document (notice that using of an empty word file as template is ussual - you just using word automation to fulfill that)
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oWord [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Word.Application
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oDoc [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Word.Document
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oTable [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Word.Table
[/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oRng [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Word.Range
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oShape [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Word.InlineShapes
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oLineNew [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Word.Shape
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oParagraf [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Word.Paragraph[/SIZE]
[SIZE=2] 
[/SIZE][/SIZE][SIZE=2][COLOR=#008000]'Start Word and open the document template.
[/COLOR][/SIZE][SIZE=2]oWord = CreateObject([/SIZE][SIZE=2][COLOR=#800000]"Word.Application"[/COLOR][/SIZE][SIZE=2])
oWord.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008000]'if it's true then you can see how it draws the lines, tables, text and stuff in real time ... if you don;t want that then turn visible to false
[/COLOR][/SIZE][SIZE=2]oDoc = oWord.Documents.Add(Application.StartupPath & [/SIZE][SIZE=2][COLOR=#800000]"\EmptyTemplate.dot"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][SIZE=2])[COLOR=darkgreen] 'call the empty template[/COLOR][/SIZE]
[SIZE=2][COLOR=#006400][/COLOR][/SIZE] 
[SIZE=2][SIZE=2]oParagraf = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item([/SIZE][SIZE=2][COLOR=#800000]"\endofdoc"[/COLOR][/SIZE][SIZE=2]).Range)
oParagraf.Range.InsertParagraphBefore()
oParagraf.Range.Text = [/SIZE][SIZE=2][COLOR=#800000]MyTextBox.Text [COLOR=darkgreen]'this will draw the text just on the top of the document[/COLOR]
[/COLOR][/SIZE][SIZE=2]oParagraf.Format.SpaceAfter = 30
{...}
You can draw Pie, lines, images and everything you can from within WinWord :) If you cannot find this ussual let me know and i'll make a complete demo that ilustrates word automation.

Regards ;)
[/SIZE][/SIZE]
 
Back
Top