Output to Word & Excel

Discussion in 'ASP .Net' started by Mark Rae, May 25, 2006.

  1. Mark Rae

    Mark Rae Guest

    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
     
    Mark Rae, May 25, 2006
    #1
    1. Advertising

  2. 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/infoservice/wwwfaq/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/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
    >
    >
    >
     
    =?Utf-8?B?RGF2aWQgSmVzc2Vl?=, May 25, 2006
    #2
    1. Advertising

  3. Mark Rae

    Mark Rae Guest

    "David Jessee" <> wrote in message
    news:...

    >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/infoservice/wwwfaq/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/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
    >>
    >>
    >>
     
    Mark Rae, May 25, 2006
    #3
  4. 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" <> wrote in message
    news:eBi4bf$...
    > 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
    >
     
    Steve C. Orr [MVP, MCSD], May 25, 2006
    #4
  5. Mark Rae

    Mark Rae Guest

    "Steve C. Orr [MVP, MCSD]" <> wrote in message
    news:...

    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


    > --
    > I hope this helps,
    > Steve C. Orr, MCSD, MVP
    > http://SteveOrr.net
    >
    >
    > "Mark Rae" <> wrote in message
    > news:eBi4bf$...
    >> 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
    >>

    >
    >
     
    Mark Rae, May 25, 2006
    #5
  6. 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" <> wrote in message
    news:%...
    > "Steve C. Orr [MVP, MCSD]" <> wrote in message
    > news:...
    >
    > 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
    >
    >
    >> --
    >> I hope this helps,
    >> Steve C. Orr, MCSD, MVP
    >> http://SteveOrr.net
    >>
    >>
    >> "Mark Rae" <> wrote in message
    >> news:eBi4bf$...
    >>> 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
    >>>

    >>
    >>

    >
    >
     
    Steve C. Orr [MVP, MCSD], May 26, 2006
    #6
  7. Mark Rae

    Mark Rae Guest

    "Steve C. Orr [MVP, MCSD]" <> wrote in message
    news:...

    > 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...?
     
    Mark Rae, May 26, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laura
    Replies:
    1
    Views:
    536
    Gunnar Hjalmarsson
    Jun 5, 2004
  2. Stephen Witter

    opening a word doc in word not browser

    Stephen Witter, May 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    498
    Stephen Witter
    May 18, 2004
  3. Luis Esteban Valencia
    Replies:
    2
    Views:
    2,948
    sanjupillai
    Sep 26, 2008
  4. Sharon
    Replies:
    0
    Views:
    608
    Sharon
    Jul 27, 2005
  5. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,523
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
Loading...

Share This Page