By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

Output to Word & Excel

P: n/a
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/NewsletterA...200309so_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
May 25 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I know its scarry....but its this easy.....

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

Then render the page normally

oh....here's a list of some content types:
http://www.usf.uni-osnabrueck.de/inf...wwfaq/mime.htm
"Mark Rae" wrote:
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/NewsletterA...200309so_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

May 25 '06 #2

P: n/a
"David Jessee" <Da*********@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
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...

oh....here's a list of some content types:
http://www.usf.uni-osnabrueck.de/inf...wwfaq/mime.htm
"Mark Rae" wrote:
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/NewsletterA...200309so_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

May 25 '06 #3

P: n/a
Have you tried this free ExportPanel control?
http://SteveOrr.net/articles/ExportPanel.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:eB**************@TK2MSFTNGP05.phx.gbl...
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/NewsletterA...200309so_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

May 25 '06 #4

P: n/a
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:uf*************@TK2MSFTNGP02.phx.gbl...

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/NewsletterA...00309so_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

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:eB**************@TK2MSFTNGP05.phx.gbl...
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/NewsletterA...200309so_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


May 25 '06 #5

P: n/a
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.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:uf*************@TK2MSFTNGP02.phx.gbl...

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/NewsletterA...00309so_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

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:eB**************@TK2MSFTNGP05.phx.gbl...
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/NewsletterA...200309so_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



May 26 '06 #6

P: n/a
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:up**************@TK2MSFTNGP02.phx.gbl...
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...?
May 26 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.