Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > creating word doc in website

Reply
Thread Tools

creating word doc in website

 
 
ton
Guest
Posts: n/a
 
      03-31-2009
Hi,

In VB6 I can create (generate) a word document based upon a template.
- The user click the tempate which I offer in a list
- based on the data he choosed upfront I cabn fill all the bookmarks with
the correct data
- I can save the document I even can print it
some code:
Dim Wordx As Word.Application
Dim thisWord As Word.Document
Set Wordx = CreateObject("Word.Application")
Set thisWord = Wordx.Documents.Add(Template)

' filling the bookmarks something like
Set range = thisWord.GoTo(What:=wdGoToBookmark, Name:=bmbookmark.Name)
If Trim(tekst) <> 0 Then
tekst = Trim(tekst)
End If
range.text = tekst
range.Select
Wordx.ActiveDocument.Bookmarks.Add a, range

and so on at the end:
mydoc="c:\temp\x.doc"
thisWord.BuiltinDocumentProperties(3) = " ton"
thisWord.SaveAs mydoc

easy

But how can it be done in in my webapp. I want to mail the result to the
user, or if possible show it on a webpage, whatever is possible

Can someone explain me how to do this.

Thanx

Ton


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      03-31-2009
On Mar 31, 11:40*am, "ton" <(E-Mail Removed)> wrote:
> Hi,
>
> In VB6 I can create (generate) a word document based upon a template.
> - The user click the tempate which I offer in a list
> - based on the data he choosed upfront I cabn fill all the bookmarks with
> the correct data
> - I can save the document I even can print it
> some code:
> Dim Wordx As Word.Application
> Dim thisWord As Word.Document
> Set Wordx = CreateObject("Word.Application")
> Set thisWord = Wordx.Documents.Add(Template)
>
> ' filling the bookmarks something like
> Set range = thisWord.GoTo(What:=wdGoToBookmark, Name:=bmbookmark.Name)
> If Trim(tekst) <> 0 Then
> * * tekst = Trim(tekst)
> End If
> range.text = tekst
> range.Select
> Wordx.ActiveDocument.Bookmarks.Add a, range
>
> and so on at the end:
> * * mydoc="c:\temp\x.doc"
> * * thisWord.BuiltinDocumentProperties(3) = " ton"
> * * thisWord.SaveAs mydoc
>
> easy
>
> But how can it be done in in my webapp. I want to mail the result to the
> user, or if possible show it on a webpage, whatever is possible
>
> Can someone explain me how to do this.
>
> Thanx
>
> Ton


Google the answer
http://www.google.com/search?q=creat...cument+asp.net
 
Reply With Quote
 
 
 
 
ton
Guest
Posts: n/a
 
      03-31-2009
Hi Mark,

I've just solved the problem. It is possible. I found a website with an
example http://www.freevbcode.com/ShowCode.Asp?ID=1727

I've used just the creating doc part which looks like: (and added the
bookmark substitution to it). It works in my development enciroment AND on
my server after publishing it !!!


Dim wordapp, worddoc, myrange1, worddocpath, bmbookmark,
UsedBookmarks, BookmarkName, range, tekst

' CREATE WORD DOCUMENT

WordApp = CreateObject("word.application")
worddoc = wordapp.Documents.Add("c:\temp\dbRecord.dot")

WordApp.Application.Visible = False

MyRange1 = WordDoc.Paragraphs.Add.Range
MyRange1.InsertBefore("Appraisal Form")
'' MyRange1.Style = "Heading 1"

MyRange1 = WordDoc.Paragraphs.Add.Range
myrange1.InsertBefore("Manager: " & "Ton" & vbCrLf & "Appraisee: ")
MyRange1.Font.Bold = True

MyRange1 = WordDoc.Paragraphs.Add.Range
MyRange1.InsertBefore(vbCrLf & "Please fill in all the required
sections and return to HR via the internal mail system.")

' Set the directory location to store the generated documents
'' worddocpath = Server.MapPath("\document")
' Use the unique session ID as the filename.
UsedBookmarks = ","
For Each bmbookmark In worddoc.Bookmarks
BookmarkName = bmbookmark.Name
If InStr(UsedBookmarks, "," + BookmarkName + ",") = 0 Then
tekst = BookmarkName
If Mid$(BookmarkName, 1, 3) <> "tab" Then
'' replacebookmark(range, tekst, bmbookmark)
range = worddoc.GoTo(-1, , , BookmarkName) ''
wdGoToBookmark=-1
If Trim(tekst) <> "" Then
tekst = Trim(tekst)
End If
range.text = tekst
range.Select()
End If
UsedBookmarks = UsedBookmarks & BookmarkName & ","
End If

Next

worddoc.SaveAs("c:\temp\" & Session.SessionID & ".doc")
worddoc.Close()
wordapp.Quit()

worddoc = Nothing
wordapp = Nothing


Thanx

Ton



"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> "ton" <(E-Mail Removed)> wrote in message
> news:c7f75$49d1f0aa$541ec4bd$(E-Mail Removed)1.n b.home.nl...
>
>> Is it possible to run an exe file instead (without any dialog), but a exe
>> who just create the doc and save it.

>
> Anything which would require a copy of Word to be installed on the server
> is potentially subject to the same problems, so no.
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net


 
Reply With Quote
 
Paul Shapiro
Guest
Posts: n/a
 
      03-31-2009
But as Mark already indicated, this only works if you install Word on your
webserver, and this is both unsupported and a license violation. And while
it might work fine for a single user, it probably fails with even a moderate
number of users.

"ton" <(E-Mail Removed)> wrote in message
news:1ad7a$49d2052e$541ec4bd$(E-Mail Removed)1.n b.home.nl...
> Hi Mark,
>
> I've just solved the problem. It is possible. I found a website with an
> example http://www.freevbcode.com/ShowCode.Asp?ID=1727
>
> I've used just the creating doc part which looks like: (and added the
> bookmark substitution to it). It works in my development enciroment AND on
> my server after publishing it !!!
>
>
> Dim wordapp, worddoc, myrange1, worddocpath, bmbookmark,
> UsedBookmarks, BookmarkName, range, tekst
>
> ' CREATE WORD DOCUMENT
>
> WordApp = CreateObject("word.application")
> worddoc = wordapp.Documents.Add("c:\temp\dbRecord.dot")
>
> WordApp.Application.Visible = False
>
> MyRange1 = WordDoc.Paragraphs.Add.Range
> MyRange1.InsertBefore("Appraisal Form")
> '' MyRange1.Style = "Heading 1"
>
> MyRange1 = WordDoc.Paragraphs.Add.Range
> myrange1.InsertBefore("Manager: " & "Ton" & vbCrLf & "Appraisee: ")
> MyRange1.Font.Bold = True
>
> MyRange1 = WordDoc.Paragraphs.Add.Range
> MyRange1.InsertBefore(vbCrLf & "Please fill in all the required
> sections and return to HR via the internal mail system.")
>
> ' Set the directory location to store the generated documents
> '' worddocpath = Server.MapPath("\document")
> ' Use the unique session ID as the filename.
> UsedBookmarks = ","
> For Each bmbookmark In worddoc.Bookmarks
> BookmarkName = bmbookmark.Name
> If InStr(UsedBookmarks, "," + BookmarkName + ",") = 0 Then
> tekst = BookmarkName
> If Mid$(BookmarkName, 1, 3) <> "tab" Then
> '' replacebookmark(range, tekst, bmbookmark)
> range = worddoc.GoTo(-1, , , BookmarkName) ''
> wdGoToBookmark=-1
> If Trim(tekst) <> "" Then
> tekst = Trim(tekst)
> End If
> range.text = tekst
> range.Select()
> End If
> UsedBookmarks = UsedBookmarks & BookmarkName & ","
> End If
>
> Next
>
> worddoc.SaveAs("c:\temp\" & Session.SessionID & ".doc")
> worddoc.Close()
> wordapp.Quit()
>
> worddoc = Nothing
> wordapp = Nothing
>
>
> "Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
>> "ton" <(E-Mail Removed)> wrote in message
>> news:c7f75$49d1f0aa$541ec4bd$(E-Mail Removed)1.n b.home.nl...
>>
>>> Is it possible to run an exe file instead (without any dialog), but a
>>> exe who just create the doc and save it.

>>
>> Anything which would require a copy of Word to be installed on the server
>> is potentially subject to the same problems, so no.
>>
>>
>> --
>> Mark Rae
>> ASP.NET MVP
>> http://www.markrae.net


 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      03-31-2009
After serious thinking ton wrote :
> Hi Mark,
>
> I've just solved the problem. It is possible. I found a website with an
> example ...



The phrase "Office may exhibit unstable behavior and/or deadlock" (from
the URL Mark pointed out) could be translated as:

"it just might work in some situations (my personal guess: when 1 user
at a time requests a word document to be generated) but *unpredictably
fail* in other situations (personal guess: when multiple users request
it at the same time)"

So the fact that that one test seems to succeed doesn't mean that it
will continue to work when the website is in "regular use".

Hans Kesting


 
Reply With Quote
 
ton
Guest
Posts: n/a
 
      04-01-2009
to bad, I read your link with the ms warning just now, it is clear to me now

thanx anyhow


"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:u6%(E-Mail Removed)...
> "ton" <(E-Mail Removed)> wrote in message
> news:1ad7a$49d2052e$541ec4bd$(E-Mail Removed)1.n b.home.nl...
>
>> I've just solved the problem.

>
> You may think you have, but you haven't...
>
>> It is possible.

>
> I didn't say that it wasn't possible! I advised you not to do it because
> it's unsupported by Microsoft and will almost certainly fail very soon...
>
> Did you not actually understand why I advised you not to do this...?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net


 
Reply With Quote
 
cubaman
Guest
Posts: n/a
 
      04-01-2009
On Mar 31, 12:15*pm, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> "ton" <(E-Mail Removed)> wrote in message
>
> news:5f964$49d1e526$541ec4bd$(E-Mail Removed)1.n b.home.nl...
>
> > But how can it be done in in my webapp. I want to mail the result to the
> > user, or if possible show it on a webpage, whatever is possible

>
> You can't use the same method in a server-side technology like ASP.NET. Word
> (and the rest of Office) simply wasn't designed to be instantiated like
> this. Microsoft won't provide any support for this:http://support.microsoft.com/default...S;q257757#kb2- note
> the paragraph in bold.
>
> So, you have three choices:
>
> 1) Use Aspose:http://www.aspose.com/categories/fil.../aspose.words-...
> The advantage of this is that it provides all of the functionality you're
> familiar with from VB6 - the syntax is essentially identical - but without
> needing to have a copy of Word installed on the webserver. The disadvantage
> is that it's not free. However, it's not *very* expensive, and your time may
> be more valuable anyway...
> See also:http://www.aspose.com/categories/pro...total-for-.net...
>
> 2) Use HTML
> Word (like the rest of Office) simply "understands" HTML. So you can create
> an HTML document, give it a Word extension, and Word will treat it like a
> regular Word document. The advantage of this is that it's free. The
> disadvantage is that it doesn't support all of the features of Word that
> Aspose does but, if your requirements are fairly basic, it may be
> sufficient.
>
> 3) Create Word 2007 documents directly.
> Word 2007 documents are, essentially, zipped up XML documents. The advantage
> of this that it's free. The disadvantage is that it's quite difficult and
> time-consuming, as even the simplest of Word documents requires fairly
> complex XML. Also, it will require your users to have either Word 2007 or
> the Word 2007 viewer.
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


I disagree with you. It's possible to create Word 2003 documents based
on xsl templates. I do that even with excell workbooks. Office 2003
allows to save and read documents in xml format, without compression.
And is not very complicated.
Best regards.
Oscar Acosta
Best regards.
 
Reply With Quote
 
cubaman
Guest
Posts: n/a
 
      04-01-2009
On Mar 31, 11:40*am, "ton" <(E-Mail Removed)> wrote:
> Hi,
>
> In VB6 I can create (generate) a word document based upon a template.
> - The user click the tempate which I offer in a list
> - based on the data he choosed upfront I cabn fill all the bookmarks with
> the correct data
> - I can save the document I even can print it
> some code:
> Dim Wordx As Word.Application
> Dim thisWord As Word.Document
> Set Wordx = CreateObject("Word.Application")
> Set thisWord = Wordx.Documents.Add(Template)
>
> ' filling the bookmarks something like
> Set range = thisWord.GoTo(What:=wdGoToBookmark, Name:=bmbookmark.Name)
> If Trim(tekst) <> 0 Then
> * * tekst = Trim(tekst)
> End If
> range.text = tekst
> range.Select
> Wordx.ActiveDocument.Bookmarks.Add a, range
>
> and so on at the end:
> * * mydoc="c:\temp\x.doc"
> * * thisWord.BuiltinDocumentProperties(3) = " ton"
> * * thisWord.SaveAs mydoc
>
> easy
>
> But how can it be done in in my webapp. I want to mail the result to the
> user, or if possible show it on a webpage, whatever is possible
>
> Can someone explain me how to do this.
>
> Thanx
>
> Ton


First, create a word document using word 2003. It would be your
template. Format the document according to your requirements.
Save it as xml document.
Create an xslt template with this document.
Get your data as xml.
Apply a transform to insert relevant data in your template.
Best regards.
Oscar Acosta
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.pdf doc to word doc PWB Computer Support 14 09-19-2008 10:41 PM
XML from Word -- formerly Create pdf from existing Word doc (asp.net) Sharon ASP .Net 0 07-27-2005 02:07 AM
String[] files = {"a.doc, b.doc"}; VERSUS String[] files = new String[] {"a.doc, b.doc"}; Matt Java 3 09-17-2004 10:28 PM
opening a word doc in word not browser Stephen Witter ASP .Net 0 05-18-2004 02:48 AM
Parsing MS Word client doc into server-side doc... John Wallace ASP .Net 0 07-22-2003 06:49 PM



Advertisments