Click here to Skip to main content
15,611,074 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this code,
VB
' Create Word Application
       Dim oWord As Word.Application = DirectCast(CreateObject("Word.Application"), Word.Application)

       ' Create new word document
       Dim oDoc As Word.Document = oWord.Documents.Add()
       oWord.Visible = True

       Dim headers = (From ch In MyBase.Columns _
                Let header = DirectCast(ch, ColumnHeader) _
                Select header.Text).ToArray()

       Dim items() = (From item In MyBase.Items _
             Let lvi = DirectCast(item, ListViewItem) _
             Select (From subitem In lvi.SubItems _
                 Let si = DirectCast(subitem, ListViewItem.ListViewSubItem) _
                 Select si.Text).ToArray()).ToArray()

       Dim table As String = String.Join(vbTab, headers) & Environment.NewLine
       For Each a In items
           table &= String.Join(vbTab, a) & Environment.NewLine
       Next
       table = table.TrimEnd(CChar(Environment.NewLine))
       Clipboard.SetText(table)

       Dim oTable As Word.Table = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, items.Count + 1, headers.Count)
       oTable.Range.ParagraphFormat.SpaceAfter = 6

       oTable.Range.Paste()

       'make the first row bold, fs 14 + change textcolor
       oTable.Rows.Item(1).Range.Font.Bold = &H98967E
       oTable.Rows.Item(1).Range.Font.Size = 14
       oTable.Rows.Item(1).Range.Font.Color = Word.WdColor.wdColorWhite

       'change backcolor of first row
       oTable.Rows.Item(1).Range.Shading.Texture = Word.WdTextureIndex.wdTextureNone
       oTable.Rows.Item(1).Range.Shading.ForegroundPatternColor = Word.WdColor.wdColorAutomatic
       oTable.Rows.Item(1).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorPaleBlue






here we create new word file, then all datagridview data are add in word file instead of that, i want add all datagridview data in present word file, for that, what part of code i change for require output.


PLEASE TELL ME THE CHANGE IN CURRENT CODE FOR MY REQUIREMENT
Posted
Updated 3-Jun-12 4:31am
v2

The following code can be used to open an existing Word document
VB
Dim oWord As New Microsoft.Office.Interop.Word.Application
Dim oDoc = oWord.Documents.Open(fileName)
oWord.Visible = True
'Set the required WindowState
oWord.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMaximize

Instead of the following code given in the question
VB
' Create Word Application
Dim oWord As Word.Application = DirectCast(CreateObject("Word.Application"), Word.Application)

' Create new word document
Dim oDoc As Word.Document = oWord.Documents.Add()
oWord.Visible = True
 
Share this answer
 
 
Share this answer
 
Comments
harishtaware 3-Jun-12 10:35am    
PLEASE TELL ME THE CHANGE IN CURRENT CODE

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900