If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Export data from datagrid to MS Word using vb.net

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-12-11, 13:07
shinichi90 shinichi90 is offline
Registered User
 
Join Date: Jul 2010
Posts: 8
Export data from datagrid to MS Word using vb.net

Hi!!

I was wondering if it's possible for me to export the data from the datagrid and output it into MS Word?

I'm actually storing strings of questions inside the database and I need to find a way to print out all those set of questions into MS Word.

Could someone show me a link or a guide as to how I can do this?

I saw many links that shows how to export the datagrid to Excel but I can't find any that export the data to Word yet.

Thank you.

Regards,
shinichi90
Reply With Quote
  #2 (permalink)  
Old 06-13-11, 12:49
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,612
If necessary you can overload the dataGrid.Serialize() method as needed, but I can always get by using the default Serialize method with a Tab or 0x09 for the columnSeparator value and the default EndOfLine value 0x0d0a from the DataGrid control.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 06-15-11, 15:23
OpK OpK is offline
Registered User
 
Join Date: Jun 2011
Posts: 9
Here is what I do for a CSV with excel but I don't know what you would need to do to encode it properly for word.

Dim dv2 As System.Data.DataView = CType(Me.SqlDataSource2.Select(DataSourceSelectArg uments.Empty), System.Data.DataView)
Dim dr2 As System.Data.DataRow = dv.Table.Rows(0)

If Not Directory.Exists("C:\Reports\" + bString) Then
Directory.CreateDirectory("C:\Reports\" + bString)
End If

If IsNumeric(DropDownList1.Text) Then
sw = New StreamWriter("c:\reports\" + bString + "\" + DropDownList3.Text + "_" + DropDownList1.Text + "_Inventory_Report.csv", False, Encoding.ASCII)
'sw = New StreamWriter(home + "\Desktop\" + DropDownList3.Text + "_" + DropDownList1.Text + "_Inventory_Report.csv", False, Encoding.ASCII)
Else
sw = New StreamWriter("c:\reports\" + bString + "\" + DropDownList3.Text + "_Complete_Inventory_Report.csv", False, Encoding.ASCII)
'sw = New StreamWriter(home + "\Desktop\" + DropDownList3.Text + "_Complete_Inventory_Report.csv", False, Encoding.ASCII)

End If

'StreamWriter sw = new StreamWriter("c:\\" + locationBox.Text + "_Inventory_Report.csv", false, Encoding.ASCII);
' int init = 0;

' /*do
' {
'sw.Write("TEST" + ", ")

If DropDownList3.Text.Contains("Non Reporting") Then
sw.Write("Row ID" + ", ")
'sw.Write("MAC Address" + ", ")
sw.Write("Barcode" + ", ")
'sw.Write("Domain" + ", ")
sw.Write("TagID" + ", ")
sw.Write("Description" + ", ")
sw.Write("Location" + ", ")
sw.Write("Serial" + ", ")
sw.Write("Unitcode" + ", ")
sw.Write("Purchase Date" + ", ")
sw.Write("Purchase Order" + ", ")
sw.Write("Purchase Price" + ", ")
sw.Write("UTSA User" + ", ")
sw.Write(System.Environment.NewLine)
Else
sw.Write("Computer Name" + ", ")
'sw.Write("MAC Address" + ", ")
sw.Write("Desription" + ", ")
'sw.Write("Domain" + ", ")
sw.Write("Serial" + ", ")
sw.Write("Processor" + ", ")
sw.Write("Operating System" + ", ")
sw.Write("Service Pack" + ", ")
sw.Write("Free Space on C:" + ", ")
sw.Write("RAM Amount" + ", ")

sw.Write("Last User" + ", ")

sw.Write("Manufacturer" + ", ")

sw.Write("Last Date Logged" + ", ")
sw.Write("OU" + ", ")
sw.Write(System.Environment.NewLine)
End If


If IsNumeric(DropDownList1.Text) Then

If DropDownList3.Text.Contains("Non Reporting") Then
For Each drz As DataRow In dv2.Table.Rows
If drz(6).Contains(DropDownList1.Text) Then
If drz(3).ToString.Contains("CPU") Then
sw.Write(drz(0).ToString + "," + drz(1).ToString + "," + drz(2).ToString + "," + drz(3).ToString + "," + drz(4).ToString + "," + drz(5).ToString + "," + drz(6).ToString + "," + drz(7).ToString + "," + drz(8).ToString + "," + drz(9).ToString + "," + drz(10).ToString)
sw.Write(System.Environment.NewLine)
End If
End If
Next
End If

Hope it helps. -Mike

This was also from a web application so the web.config contains my connection strings and then the aspx page contains my query:
<aspqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:CoehdITDataConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:CoehdITDataConnectionString2.Pro viderName %>"
SelectCommand="SELECT * from [inventory] as ci left join ComputersData as cd on cd.pc_serial = ci.serial where cd.pc_serial IS NULL">
</aspqlDataSource>

Last edited by OpK; 06-15-11 at 15:28.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On