Sending data to Word

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

I have an ASP.Net 2.0 intranet application and would like to be able to send
a name and address to an msword content type or something. I want to first
just send out the person's name and address to the upper-left portion of the
newly created .doc format so the user can finish the letter and save/print
the letter. I have done some exporting to Excel from a GridView but I'm not
sure how to create in Word.

All users have Microsoft Word and IE6+. Thanks.

David
 
I have an ASP.Net 2.0 intranet application and would like to be able to
send a name and address to an msword content type or something. I want to
first just send out the person's name and address to the upper-left portion
of the newly created .doc format so the user can finish the letter and
save/print the letter. I have done some exporting to Excel from a GridView
but I'm not sure how to create in Word.

All users have Microsoft Word and IE6+. Thanks.

Firstly, under no circumstances attempt to do Office automation in ASP.NET -
it's not supported by Microsoft because it's just not designed to work in
this environment:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

Luckily, your requirements do not require automation, and are extremely
simple.

Basically, just create an HTML document and then save it with a .doc
extension.

As an example, open Notepad, paste the text below, and then save it as
Bill.doc

<html>

<body>
Bill Gates<br />
Microsoft Corporation<br />
Redmond<br />
<br />
Dear Bill,<br />
<br />
</body>

</html>


Now double-click the newly created "Word" document - Word will treat it just
like a native Word document.
 
Mark,
I'm not sure if I was clear with my request. I want to do something similar
to below from the web page to have it create a Word document (instead of
Excel like the example). Thanks.

Response.Clear()

Response.ContentType = "application/vnd.excel"

Response.Charset = ""

Response.AddHeader("content-disposition", "attachment;filename=search.xls")


Dim gv As New GridView

Dim strSQL As String

Dim conFileData As SqlConnection

Dim cmdSel As SqlCommand

conFileData = New
SqlConnection(ConfigurationManager.ConnectionStrings("FiledataConnectionString").ConnectionString)

conFileData.Open()

strSQL = txtExcelSQL.Text


'Get records based on sql

cmdSel = New SqlCommand(strSQL, conFileData)

Dim dtr As SqlDataReader

dtr = cmdSel.ExecuteReader()

gv.DataSource = dtr

gv.DataBind()

dtr.Close()

conFileData.Close()


Dim sw As New StringWriter()

Dim htw As New System.Web.UI.HtmlTextWriter(sw)

EnableViewState = False

gv.RenderControl(htw)

Response.Write(sw.ToString())

Response.End()
 
Back
Top