Output to Word & Excel

M

Mark Rae

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 automation.

N.B. the environment is a totally enclosed intranet, all the client machines
have WinXP, IE6 and Office Pro 2003 with all the latest SPs, and the IE
security settings are sufficient to allow the Local Intranet Zone to
instantiate Word & Excel. Therefore, there's no need for any 3rd-party tools
like Aspose or whatever in this case.

I found the following extremely helpful site:
http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp
which demonstrates a method of client-side Excel automation using VBScript.
It also says that it's possible to automate Word in a similar way by
changing a couple of lines, but doesn't say which lines they are or how to
modify them.

I'm also trying to write the client-side automaton in JavaScript rather than
VBScript, though there would be no harm I suppose in keeping it in VBScript.
This is how far I've got:

function exportReport(pstrOutput, strHTML)
{
switch(pstrOutput)
{
case 'Excel' :
{
var objXL = new ActiveXObject("Excel.Application");
var objWB = objXL.Workbooks.Add;
objWB.HTMLProject.HTMLProjectItems('Sheet1').Text = strHTML;
objWB.HTMLProject.RefreshDocument;
objXL.Visible = true;
objXL = null;
}
case 'Word' :
{

}
}
}

This works well enough. Two questions:

1) This always leaves an instance of EXCEL.exe running even if the user
closes Excel down manually - is there a way round this?

2) Does anyone know how to do the equivalent Word automation?

Any assistance gratefully received.

Mark
 
M

Mark Rae

I know it's scary....but it's this easy.....

Change your page's content-type to word or excel....

Then render the page normally

See below - I need to *open* Excel and/or Word, not render MIME types in
IE...
 
M

Mark Rae

Hi Steve,
Have you tried this free ExportPanel control?
http://SteveOrr.net/articles/ExportPanel.aspx

I haven't, though I'm sure it's fab. I will be sure to check it out ASAP.

However, in the meantime, what I'd really love to know relates to your
excellent web article
(http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp),
specifically where you say:
Figure 7. Modify a couple of code lines, and voila! - your data is now
output as a Word document instead of Excel.

What actually are the couple of code lines in question, and what are the
modifications required?

Also, if you have time, do you happen to know if there is a way to stop the
code always leaving an instance of EXCEL.exe (and, I imagine, WINWORD.exe)
running even if the user closes Excel down manually?

Thanks a lot.

Mark
 
S

Steve C. Orr [MVP, MCSD]

The couple of lines are referring to the HTML output option. Both the Word
and Excel code is shown in the article for that option.

As for client side techniques, I haven't tried to output Word from the
client side, but I imagine the code would require slightly more significant
changes than the server side HTML output code. For the client side code
you'd need to use Word's object model instead of Excel so you wouldn't be
creating worksheets, you'd be creating documents & such.
 
M

Mark Rae

The couple of lines are referring to the HTML output option. Both the
Word and Excel code is shown in the article for that option.
As for client side techniques, I haven't tried to output Word from the
client side, but I imagine the code would require slightly more
significant changes than the server side HTML output code. For the client
side code you'd need to use Word's object model instead of Excel so you
wouldn't be creating worksheets, you'd be creating documents & such.

Ah yes - it's the client-side code for Word I was referring to...

S'OK - I figured it out, and in JavaScript too.

Incidentally, do you know if there any way to prevent the instance of
Excel.exe / Winword.exe persisting even after the user has closed either
app, and even closed their browser...?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top