473,395 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Word document from a DataGrid?

Another problem that I am having is that I want to make some type of
word or text document that is populated with data from my datagrid. Is
this possable? And how do I keep ot formatted? I.E. I have 7 columns
with values in all of them. How do I keep the columns straight on the
printout?

Thanks!

Nov 21 '05 #1
5 3011
Webbyz,

If you want to make a word document, than you have to use interop (Office
has to be on the clients computer)

The information to use is forever in your underlying datasource.

Here are some links for the interop

Office
http://support.microsoft.com/default...b;EN-US;311452

http://msdn.microsoft.com/office/

Pia Download
http://www.microsoft.com/downloads/d...displaylang=en

I hope this helps,

Cor
Nov 21 '05 #2
To use Word, add a refernce to Microsoft Word 9.0( or 10.0) Object Library.
Then add a Class module and add code similar to:

Public Class WordClass
Public WithEvents WordApp As Word.Application
Public Sub New()
WordApp = New Word.Application
End Sub
End Class

To get data from a datagrid into a Word document, use the original dataset
that filled the datagrid, create a Word table and populate it with code
similar to:

Dim Word As New WordClass
Dim RowCounter As Int16, ColumnCounter as Int16

' Add a blank document
Word.WordApp.Documents.Add()

' Add a table for the data to go into
Word.WordApp.Selection.Tables.Add(Range:=Word.Word App.Selection.Range,
numrows:=1, numcolumns:=6)

' Put the data from the dataset into the table
For RowCounter = 0 To ds.Tables("Table").Rows.Count - 1
For ColumnCounter = 0 to ds.Tables("Table").Columns.Count - 1
Word.WordApp.Selection.TypeText(ds.Tables("Table") .Rows(RowCounter).Item(ColumnCounter))
Word.WordApp.Selection.MoveRight(Unit:=12)
Next ColumnCounter
Next RowCounter

' Show the document
Word.WordApp.Visible = True

HTH
Helen

--
Helen
"Cor Ligthert [MVP]" wrote:
Webbyz,

If you want to make a word document, than you have to use interop (Office
has to be on the clients computer)

The information to use is forever in your underlying datasource.

Here are some links for the interop

Office
http://support.microsoft.com/default...b;EN-US;311452

http://msdn.microsoft.com/office/

Pia Download
http://www.microsoft.com/downloads/d...displaylang=en

I hope this helps,

Cor

Nov 21 '05 #3
Helen,

Nice answer, however have you any reason to slow your program down by
letting it every time convert an integer (the 32bit register size on 32bit
computers) to an int16?

Net is at the moment only working at 32bit and 64bits computers.

As addition, as far as I have understand in now, do you need in 64bits
computers have to change in future all your programs by hand to make it
optimized by changing 'integer' to 'long' if you want that to work the most
optimized. Than that is only optimized for 64 bits computers and do you have
the same effect as now in your programs with that int16 on 32bit computers

It is not delaying that much that the last is worth the work direct.

Just my thought,

Cor
Nov 21 '05 #4
Seems like it would work but I do not populate via a dataset. Here is
how I populate....

Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=wasa.mdb;User Id=admin;Password=;"
Dim conn As OleDb.OleDbConnection = New
OleDb.OleDbConnection(cs)
Dim dt As New DataTable
Dim sql As String = "SELECT g.game_id, g.game_date,
g.game_time, l.desc, gs.desc, ps.desc, referee.first_name,
referee.last_name FROM ((((game AS g LEFT JOIN ref_game AS rg ON
g.game_id = rg.game_id) LEFT JOIN referee ON rg.ref_id =
referee.ref_id) LEFT JOIN game_status AS gs ON g.played = gs.id) LEFT
JOIN payment_status AS ps ON rg.paid = ps.id) LEFT JOIN league AS l ON
g.game_type = l.league_id ORDER BY referee.last_name;"
Dim da As New OleDbDataAdapter(sql, conn)
da.Fill(dt)
Dim i As Integer = 0
For Each dr As DataRow In dt.Rows
lvGames.Items.Add(dr.Item(0).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(1).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(2).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(3).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(4).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(6).ToString & " " &
dr.Item(7).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(5).ToString)
i += 1
So there is no DS to pull from. Any other way to do this?

Nov 21 '05 #5
Webbyz,

This one I have searched for it is often provided by Paul Clement, the time
in the USA is now become daytime so maybe he will give a reaction soon.

Cor

"Webbyz" <ma*******@gmail.com> schreef in bericht
news:11**********************@g49g2000cwa.googlegr oups.com...
Seems like it would work but I do not populate via a dataset. Here is
how I populate....

Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=wasa.mdb;User Id=admin;Password=;"
Dim conn As OleDb.OleDbConnection = New
OleDb.OleDbConnection(cs)
Dim dt As New DataTable
Dim sql As String = "SELECT g.game_id, g.game_date,
g.game_time, l.desc, gs.desc, ps.desc, referee.first_name,
referee.last_name FROM ((((game AS g LEFT JOIN ref_game AS rg ON
g.game_id = rg.game_id) LEFT JOIN referee ON rg.ref_id =
referee.ref_id) LEFT JOIN game_status AS gs ON g.played = gs.id) LEFT
JOIN payment_status AS ps ON rg.paid = ps.id) LEFT JOIN league AS l ON
g.game_type = l.league_id ORDER BY referee.last_name;"
Dim da As New OleDbDataAdapter(sql, conn)
da.Fill(dt)
Dim i As Integer = 0
For Each dr As DataRow In dt.Rows
lvGames.Items.Add(dr.Item(0).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(1).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(2).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(3).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(4).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(6).ToString & " " &
dr.Item(7).ToString)
lvGames.Items(i).SubItems.Add(dr.Item(5).ToString)
i += 1
So there is no DS to pull from. Any other way to do this?

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jijo kuruvila | last post by:
I am having one grid..i want to export that grid to word..after doing only two fields r coming ie serial no: and total..product name, quantity and unitcost r not coming into the word...those three...
12
by: enak | last post by:
I have found some code that shows how to convert an html form to Word. The message said to simply put the following in the Page_load: Response.ContentType = "application/ms-word"...
1
by: Andrew | last post by:
I'm adding this as it to me a while to figure out all the pieces to be able to do this without using Microsoft.Office.Interop which caused me problems on the web-server. Streaming is the easy...
0
by: Webbyz | last post by:
Another problem that I am having is that I want to make some type of word or text document that is populated with data from my datagrid. Is this possable? And how do I keep ot formatted? I.E. I...
7
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the...
6
by: Mark Rae | last post by:
Hi, My client has asked me to provide a "quick and dirty" way to export the contents of a DataGrid to both Excel for analysis and Word for editing and printing, so I'm investigating client-side...
1
by: fab | last post by:
Hi, I'm developping a web-application on an intranet. I've got a datagrid with a button on each line. Each line represents a document (MS Word doc). These documents are on a share so that they...
6
by: SteveM | last post by:
Hi, I am needing some help/advice on how to display a word document in my ASP.NET web pages that can update itself from a word document located on the server. The idea here is that when the user...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.