S
scorpion53061
I figured it out.........
I felt I owed it to the groups I harassed with this quesiton to tell the
solution....
special thanks to Ken and William Ryan who kept at it with me!!
Originally used a string. But all of you in the information "business" know
sometimes we have to work with large amounts of data and strings do have
limitaitons believe it or not on the amount of data it will carry......so I
used an Array. It is actually slower using an array. You are redoing the
text each loop. But of course as usual I am open to suggestions....If anyone
sees anything here that will not work with Word 2000 and up I would
appreciate a heads up.......
It is messy and it aint pretty but it works
Can anyone tell I am happy?
'establishing counts
Dim rows As Integer = dscopy1.Tables.Item(0).Rows.Count
Dim columns As Integer = dscopy1.Tables.Item(0).Columns.Count
Dim r As Integer
Dim c As Integer
Dim Word As New Word.Application
Word.Visible = True
'opening word
Dim oDoc As New Word.Document
oDoc = Word.Documents.Add()
'make an array of the data
Dim DataArray(rows, columns) As Object
'filling the array
For c = 0 To columns - 1
DataArray(r, c) = dscopy1.Tables(0).Columns.Item(c).ColumnName
For r = 0 To rows - 1
DataArray(r, c) = dscopy1.Tables(0).Rows(r).Item(c)
Next
Next
'where we are going with the data
Dim oRange = oDoc.Content.Application.Selection.Range
With oDoc.Application.Selection.Font
.Bold = False
End With
'filling orange for table using array due to string limitation
For r = 0 To rows - 1
For c = 0 To columns - 1
oRange.Text = oRange.Text & DataArray(r, c) & vbTab
Next
Next
'converting our text to table
oRange.ConvertToTable(Separator:=wdSeparateByTabs,
NumColumns:=dscopy1.Tables(0).Columns.Count, _
NumRows:=dscopy1.Tables(0).Rows.Count, AutoFitBehavior:=wdAutoFitContent)
'correction needed here to get it to cooperate
With oDoc.Application.Selection.Range.Tables.Item(1)
.AllowAutoFit = True
End With
'selecting top row
oDoc.Application.Selection.Tables.Item(1).Rows.Item(1).Select()
'SelectRow
'for header row
oDoc.Application.Selection.InsertRowsAbove(1)
With oDoc.Application.Selection.Font
.Bold = True
End With
'doing this late........havent had time to test whether it will matter
oDoc.Application.Selection.Rows.Item(1).HeadingFormat = True
'header row
For c = 0 To columns - 1
oDoc.Application.Selection.Tables.Item(1).Rows.Item(1).Cells.Item(c +
1).Range.Text = dscopy1.Tables(0).Columns.Item(c).ColumnName
Next
oDoc.ActiveWindow.Activate()
I felt I owed it to the groups I harassed with this quesiton to tell the
solution....
special thanks to Ken and William Ryan who kept at it with me!!
Originally used a string. But all of you in the information "business" know
sometimes we have to work with large amounts of data and strings do have
limitaitons believe it or not on the amount of data it will carry......so I
used an Array. It is actually slower using an array. You are redoing the
text each loop. But of course as usual I am open to suggestions....If anyone
sees anything here that will not work with Word 2000 and up I would
appreciate a heads up.......
It is messy and it aint pretty but it works
Can anyone tell I am happy?
'establishing counts
Dim rows As Integer = dscopy1.Tables.Item(0).Rows.Count
Dim columns As Integer = dscopy1.Tables.Item(0).Columns.Count
Dim r As Integer
Dim c As Integer
Dim Word As New Word.Application
Word.Visible = True
'opening word
Dim oDoc As New Word.Document
oDoc = Word.Documents.Add()
'make an array of the data
Dim DataArray(rows, columns) As Object
'filling the array
For c = 0 To columns - 1
DataArray(r, c) = dscopy1.Tables(0).Columns.Item(c).ColumnName
For r = 0 To rows - 1
DataArray(r, c) = dscopy1.Tables(0).Rows(r).Item(c)
Next
Next
'where we are going with the data
Dim oRange = oDoc.Content.Application.Selection.Range
With oDoc.Application.Selection.Font
.Bold = False
End With
'filling orange for table using array due to string limitation
For r = 0 To rows - 1
For c = 0 To columns - 1
oRange.Text = oRange.Text & DataArray(r, c) & vbTab
Next
Next
'converting our text to table
oRange.ConvertToTable(Separator:=wdSeparateByTabs,
NumColumns:=dscopy1.Tables(0).Columns.Count, _
NumRows:=dscopy1.Tables(0).Rows.Count, AutoFitBehavior:=wdAutoFitContent)
'correction needed here to get it to cooperate
With oDoc.Application.Selection.Range.Tables.Item(1)
.AllowAutoFit = True
End With
'selecting top row
oDoc.Application.Selection.Tables.Item(1).Rows.Item(1).Select()
'SelectRow
'for header row
oDoc.Application.Selection.InsertRowsAbove(1)
With oDoc.Application.Selection.Font
.Bold = True
End With
'doing this late........havent had time to test whether it will matter
oDoc.Application.Selection.Rows.Item(1).HeadingFormat = True
'header row
For c = 0 To columns - 1
oDoc.Application.Selection.Tables.Item(1).Rows.Item(1).Cells.Item(c +
1).Range.Text = dscopy1.Tables(0).Columns.Item(c).ColumnName
Next
oDoc.ActiveWindow.Activate()