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