Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1388
  • Last Modified:

ASP/VB: Word Doc file generation

Hi,

We use the Word.Application component to convert our HTML report files into Word DOC files. This works good. But this process is inefficient, in that for generating every word document, we have to load the resource intensive Word.Application component every time and there is a known issue of some reports failing when a lot of our customers try to generate word reports at the same time.

We have looked at using some substitute components to perform this translation (SoftArtisans WordWriter, but the integration is not seamless enough and we need this done very quickly).   Now, to solve this issue, I am trying to use the Response.ContentType statement to transform the HTML output, and then save the resulting output as a ".doc" file.

Here're the statements:

Response.AddHeader "Content-Disposition", "attachment; filename=reportName.doc"
Response.Charset = "UTF-8"
Response.ContentType = "application/msword"

This works too! But not quite good enough.

The problem is that this removes the control over the format of the word file that I normally get when using the Word.Application component. Main problem is that the images in the word document are now linked to the images on the server:

1.  Is it possible to set the Word DOC properties like
SavePictureWithDocument = True
ActiveDocument.ActiveWindow.View.Type = wdPrintView
etc., using ASP?

2. Is there another way to do this; ie, altering the normal.doc template file on the server where these files are being saved, so that the image links are broken.

Thanks,
Raj
0
rb79
Asked:
rb79
  • 14
  • 10
  • 8
  • +4
1 Solution
 
rb79Author Commented:
Please do move it to the ASP section.
(While posting I had found an ASP.Net section, but no ASP section. But, now I think it should be ok.)
0
 
rb79Author Commented:
Thanks Venabili!
0
 
joeposter649Commented:
Perhaps you could keep the word.application object around and just create new documents.  Not sure if this would cause threading problems thought...
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q243/5/43.ASP&NoWebContent=1
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
fritz_the_blankCommented:
I would definitely stay away from launching word on the server as MS recommends against doing so:

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q257/7/57.ASP&NoWebContent=1

This is not supported without a component:

SavePictureWithDocument = True
ActiveDocument.ActiveWindow.View.Type = wdPrintView

FtB
0
 
fritz_the_blankCommented:
One other option to consider is using something like ActivePDF available at www.activePDF.com

FtB
0
 
rb79Author Commented:
All your help is appreciated. Also found TX Text Control (http://www.textcontrol.com) looks very promising. But I would still be inclined to use ASP to generate the Word DOC file, rather than a third party control.

FYI This same issue has been left hanging here: http://forums.devarticles.com/t2648/s.html

My question is that is there a MS Word script that I could add to the doc file that I generate.
Something like the following that allegedly adds header text to the word doc file. Don't know how to use it though in our application.
/* Page Definitions */
@page
{mso-footnote-separator:url("<%=Application("ServerPath")%>header.htm") fs;
mso-footnote-continuation-separator:url("<%=Application("ServerPath")%>header.htm") fcs;
mso-endnote-separator:url("<%=Application("ServerPath")%>header.htm") es;
mso-endnote-continuation-separator:url("<%=Application("ServerPath")%>header.htm") ecs;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:35.4pt;
mso-footer-margin:35.4pt;
mso-header:url("<%=Application("ServerPath")%>header.htm") h1;
mso-footer:url("<%=Application("ServerPath")%>header.htm") f1;
mso-paper-source:0;
mso-gutter-direction:rtl;}
div.Section1
{page:Section1;}
0
 
rb79Author Commented:
Right now I think I need a good conversion tool (that will work like the Office Automation Word object)

1.  Tried TX Text Control ... very poor performance. They accepted the inadequacy of the control. Rejected.
2. Looking at WordWriter from SoftArtisans. Problem is that they ask you to create template Word files with mergefields for text and images(recently added feature). This is not the best conversion but should work.
3. Also checked CZ Document converter. Extremely slow and I am pretty certain that it uses Microsoft Word object in the background. Worst of the lot.

What I really need is a conversion tool, and I would be really thankful if somebody could suggest a few good conversion tools.

Thanks,
Raj
0
 
fritz_the_blankCommented:
I don't really know of anything like that. If you were just using simple text, then you could use the file system object to create the document and then you could just stream it. Otherwise, I don't know what else you could do instead.

FtB
0
 
joeposter649Commented:
Perhaps you can convert your html to mhtml and then have Word open it.
http://www.codeproject.com/aspnet/aspnethtml2mht.asp
I'm really busy right now so I can't help much...
0
 
rb79Author Commented:
Thanks for the suggestion, but MHTML is not good enough.
The images are linked files on the server in the MHTML document that get deleted every couple of days.
The Word document should have the images embedded, not linked to a remote server.
0
 
joeposter649Commented:
MHTML uses mime encoding to embed images in a single file.
Just do a save as in IE or Word and you'll see what I mean.  Choose "Web Archive" for the mht file extension.
0
 
rb79Author Commented:
Okay, I'll give it a try using the codeproject website link you provided earlier.
BTW my previous comment was based on the following observation:
I tried to save a random webpage in IE using the "Save as type" of "Web Archive, single file (*.mht)". That saved the webpage as a single file on my computer, but the links to the images were hardcoded, and I didn't see any sort of mime encoding. But maybe these are two different things.
0
 
Sparky191Commented:
Did you get any further with this? I'm looking to do something similar, and while I'm familiar with Word VBA I'm new to ASP and ASP.NET in particular.

Could you give me some more info re: issue reports failing etc.?
0
 
rb79Author Commented:
Actually, I haven't gotten much further. I am trying out Softartisan's WordWriter product. WordWriter lets you insert text and images in a pre-built Word template file. But I have been facing some problems with that.

The issues we are facing currently with Word file generation using the Office Automation object are that the process is extremely slow and is prone to failure if the load on the server is too high.
0
 
Sparky191Commented:
Have you identified that the VBA is slower when run through ASP as opposed to across the LAN as opposed to run locally? Is it definately only when via ASP that is particularly slow? Sorry if thats an obvious thing you've tried.

In my experience  if you write word VBA using a lot of selections instead of using ranges it can slow drastically. We had one macro that took 10 mins before we otimised the code and 30 sec afterwards. Tables and selections being the main culprits.

I've never done a lot of VBA via ASP so it may well be a problem at another level entirely.
0
 
rb79Author Commented:
Our ASP code calls a COM+ object created in VB6 that in turn loads the Word.Application object. The bottleneck is the Word application object that consumes a lot of server memory.
0
 
fritz_the_blankCommented:
>>The issues we are facing currently with Word file generation using the Office Automation object are that the process is extremely slow and is prone to failure if the load on the server is too high.<<

Ahhhh...it seems to me that someone mentioned that issue earlier in the thread....

FtB

0
 
rb79Author Commented:
That's ok. Probably I might not get a satisfactory answer here anytime soon. But I presumed conversion to MS Word was a common operation. Probably not, and so I will have to look for an answer myself.
0
 
rb79Author Commented:
Guess I will have to stick with MS Word for a while.
Anyways, I have a different query about Word programming that I have posted here: http://www.experts-exchange.com/Applications/MS_Office/Q_21205380.html
0
 
Sparky191Commented:
fritz_the_blank - the issue haven't been clearly defined. The object being slow, consuming large amounts of memeory and failing are different problems. Theres been no purposeful discussion of these issues. Sugesting a complelely different product is not answering the question, but answering a question that wasn't asked.

rb79  - I have built a VBA active X control which I run in a ASP page which is passed in parameters by the ASP. The active X contains VBA which uses word on the client machine (not the server) to create a new document and automate some things in the doc. I'm not having problem with performance. This is working across a intranet which spans a few offices. TBH I don't see why you are doing this on the server when you've been told its v.bad idea and the solution to you problem is not to do it and use your word on the client instead. Unless you know that most of your users won't have word, theres no reason NOT to use word on the client.

I have built lots of reporting solutions using word automation and I've never had problems with performance or frequent errors. At leaast none that I couldn't resolve eventually.
0
 
fritz_the_blankCommented:
Hey Sparky191--

Thank you for telling me how to post (I guess that an old dog can learn new tricks). I regret to inform you that sometimes the correct answer is that you shouldn't do it a certain way. Please take a moment to read the link that I gave above and you'll see that is exactly what Microsoft has to say about it. But hang on, later in your post, you repeat the very point that I made.

FtB

0
 
Sparky191Commented:
I'm suggesting that you CAN use word, but just in a different way. I don't see a posted solution that solves the problem USING word as opposed to NOT using word. To me the question is how to automate word for reports from a web page. Not how can I run word on a server.

The code I'm running from within a OCX on an ASP page runs on Word on the client. Word is not installed on the server.  Its been live for 2 months. Mind you its only very basic automation. Something along the lines of. User queries asp/database to get data. Loads ActiveX in ASP. Download data and word template if not on client to client. Open on client, import data to template.







0
 
Sparky191Commented:
I was concerned on reading joeposter649 post about threading. But I destroy the object once the doc is finshed and my understanding is that threading issues only occur if you persist the objects.
0
 
fritz_the_blankCommented:
@Sparky191 :

Capitals ALWAYS make things CLEARER....

Please don't misunderstand me. I really appreciate the content of your posts--they are presenting an option that has not been discussed earlier, and depending on rb79's needs, may very well solve the problem (although I suspect that the need for ActiveX may be a no starter for many because of security reasons).

I am taking issue with your characterization of my respones to date--essentially I am pointing out that using server-side automation with Word is a very, very bad idea, and I haven't changed my mind about that. Moreover, I was simply suggesting an alternative approach. Again, I stand by that post even if you feel that it addresses a question that was not asked (after you answer questions here for awhile, you find out that the solution very often is not one explicitly asked for in the thread). What I fail to understand is why you feel the need to unjustly criticize the posts of other while making your own very good contributions.

FtB
0
 
Sparky191Commented:
I'm only commenting on the technical issues at hand. Any personal inflection was unintentional. Apologies if the impression was otherwise. I use CAPS to emphasis code and comments in code to aid clarity. I was taught that is good practise. But this is the web and obviously its taken as shouting. Perhaps I should have had my forum hat on and not my programming one. I'll go change.






0
 
fritz_the_blankCommented:
Sorry to have snapped at you in return.

FtB
0
 
rb79Author Commented:
Okay, a final comment before this thread closes.

We are still using the Word component :(  BUT we have been able to optimize the word doc generation for a performance gain of about 80% from before. DOC generation now takes ~4 seconds instead of ~15 seconds. We did this by removing the SavePictureWithDocument for each InlineShape and by just doing .Unlink and .Update for each Shape. This should do for now.
0
 
fritz_the_blankCommented:
@rb79--

Please be sure to close this thread out by accepting the comment(s) that helped you the most as an answer.

FtB
0
 
rb79Author Commented:
I appreciate all the helpful comments.
Apparently, the original question for a good third party component is still unresolved. I will keep looking at the other ones in the market.
Also I fixed the SavePictureWithDocument without any help.

Probably, this question should be better deleted.
0
 
fritz_the_blankCommented:
Well, if my post regarding Microsoft's warning against running Word as an automation object was of no use whatsoever, then I suppose a delete is fine.

FtB
0
 
Sparky191Commented:
Theres a lot you can do to improve performance of word vba. Use ranges instead of selections where ever possible. I've seen macros go from 10 mins to 10 sec just by doing that alone.
0
 
Sparky191Commented:
Has your recoding reduced the amount of errors, memory utilisation and failed reports?
0
 
rb79Author Commented:
Errors were in the form of slow response times and failed reports. We are yet to stress test the application after this change was implemented.
Memory utilization is the same though the time to run a report has reduced significantly.
0
 
fozyletCommented:
@rb79,
Would be great if you close the question yourself by accepting a comment or requesting a delete.
0
 
fritz_the_blankCommented:
I still think that ID: 11883095 is relevant here, but if rb79 doesn't think so, then I suppose that a PAQ is fine.

FtB
0
 
moduloCommented:
PAQed with no points refunded (of 500)

modulo
Community Support Moderator
0
 
starship_warsCommented:
Hi there rb79 -- hope you can help me, I am also using:
    Response.ContentType = "application/msword"
You said you were able to "remove the SavePictureWithDocument for each InlineShape and by just doing .Unlink and .Update for each Shape."

Could you elaborate or share the code to do this, my images are linked to the server, and I need them embedded in the word doc.
0
 
rb79Author Commented:
@starship_wars:
d is the document object.  Code below:
foreach (MOI.Word.Section s in d.Sections) {
	s.Range.Fields.Update();
	s.Range.Fields.Unlink();
}

Open in new window

0
 
starship_warsCommented:
Thank you Raj!

I was hoping it was possible with the Response object.  But doesn't look like it.  Here's what I'm using:
            Response.Clear()
            Response.AddHeader("Content-Disposition", "attachment;filename=doc.doc")
            Response.AddHeader("Content-Length", s.Length.ToString())
            Response.ContentType = "application/msword"  
            Response.Write(s) 's includes the <img="http://web.com/img/x.gif">
            Response.End()
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 14
  • 10
  • 8
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now