Running Excel macro that opened from web

Discussion in 'Java' started by Sam, Jun 25, 2004.

  1. Sam

    Sam Guest

    Things to do:
    What I need is to open an Excel file from a web site and run a macro
    on that file by clicking a button.

    Issue/problem:
    Now I created an Excel file with a button to call a macro: PrintMacro.
    It works fine. Then I have a web appliation using weblogic and struts.
    It loads the Excel file from the file server and open the Excel file
    with data and a button. So far so good. But when clicking the button,
    it fails to trigger the macro. The Excel message said: The macro
    ''reportaction.do?file=20040625'!PrintMacro' cannot be found. If run
    the macro from Tools/Macro, it works. Or if save the Excel file then
    reopen it, the button does the work. That's to say: the macro itself
    is OK but the button could find the right reference. I noticed that
    the Excel file name was "YYYYMMDD" (eg. 20040625). After getting it
    from the web app, its name seems to append to
    'reportaction.do?file=20040625'. The 'reportaction' is an action class
    the web app uses and the 'file=20040605' is a request that the user
    selects.

    Question:
    I think it's because of its name change that makes the button lost its
    reference. The button looks for '20040625'!PrintMacro, but not
    'reportaction.do?file=20040625'!PrintMacro.
    I don't know if this an Excel or java issue. I looked some Excel Q&A
    sites and post questions there, but couldn't find any hint. It seems
    they don't deal with Excel with java web issues.
    So I come back to ask the java gurus: is it possible to get rid of the
    appending part ('reportaction.do?file=)? Or some other way to open the
    file and click the buuton to run the macro?

    Code snippet for retrieving the Excel:
    ....
    response.setContentType("application/vnd.ms-excel");
    FileInputStream is = new FileInputStream(theFile);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    while ( is.available() > 0 ) {
    os.write(is.read());
    }
    is.close();
    os.writeTo(response.getOutputStream());
    response.setHeader("Content-Disposition", "attachment; filename=" +
    theFile + ".xls" + ";");
    response.getOutputStream().flush();
    response.getOutputStream().close();

    Thanks
    Sam
     
    Sam, Jun 25, 2004
    #1
    1. Advertising

  2. Sam

    Sam Guest

    I got it fixed. I removed the parameter part from servlet by sending a
    hidden value. So the browser opens the Excel without that
    "?file=20040625". Then the button works.
    It seems the Excel doesn't like "?" as its file name, I think.
    Hope this may help those who might come into this problem.

    Thanks anyway.
    Sam

    (Sam) wrote in message news:<>...
    > Things to do:
    > What I need is to open an Excel file from a web site and run a macro
    > on that file by clicking a button.
    >
    > Issue/problem:
    > Now I created an Excel file with a button to call a macro: PrintMacro.
    > It works fine. Then I have a web appliation using weblogic and struts.
    > It loads the Excel file from the file server and open the Excel file
    > with data and a button. So far so good. But when clicking the button,
    > it fails to trigger the macro. The Excel message said: The macro
    > ''reportaction.do?file=20040625'!PrintMacro' cannot be found. If run
    > the macro from Tools/Macro, it works. Or if save the Excel file then
    > reopen it, the button does the work. That's to say: the macro itself
    > is OK but the button could find the right reference. I noticed that
    > the Excel file name was "YYYYMMDD" (eg. 20040625). After getting it
    > from the web app, its name seems to append to
    > 'reportaction.do?file=20040625'. The 'reportaction' is an action class
    > the web app uses and the 'file=20040605' is a request that the user
    > selects.
    >
    > Question:
    > I think it's because of its name change that makes the button lost its
    > reference. The button looks for '20040625'!PrintMacro, but not
    > 'reportaction.do?file=20040625'!PrintMacro.
    > I don't know if this an Excel or java issue. I looked some Excel Q&A
    > sites and post questions there, but couldn't find any hint. It seems
    > they don't deal with Excel with java web issues.
    > So I come back to ask the java gurus: is it possible to get rid of the
    > appending part ('reportaction.do?file=)? Or some other way to open the
    > file and click the buuton to run the macro?
    >
    > Code snippet for retrieving the Excel:
    > ...
    > response.setContentType("application/vnd.ms-excel");
    > FileInputStream is = new FileInputStream(theFile);
    > ByteArrayOutputStream os = new ByteArrayOutputStream();
    > while ( is.available() > 0 ) {
    > os.write(is.read());
    > }
    > is.close();
    > os.writeTo(response.getOutputStream());
    > response.setHeader("Content-Disposition", "attachment; filename=" +
    > theFile + ".xls" + ";");
    > response.getOutputStream().flush();
    > response.getOutputStream().close();
    >
    > Thanks
    > Sam
     
    Sam, Jun 30, 2004
    #2
    1. Advertising

  3. Sam

    toharikr

    Joined:
    Nov 4, 2007
    Messages:
    1
    hey..I need your help.

    i have written macros in excel 2003 and deploying in weblogic server 8.1 , using structs framework..

    but i am getting error "error occurred initializing the VBA libraries" once i tries to open excel.

    This works normally when i open the excel and runs. Problem is only after deploying..Please help me ..I am trying for this for last one week...

    Thanks.
     
    toharikr, Nov 4, 2007
    #3
    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. Dead RAM
    Replies:
    20
    Views:
    1,131
    John Harrison
    Jul 14, 2004
  2. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    590
    Jack Klein
    Sep 21, 2003
  3. =?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,548
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  4. sakons
    Replies:
    2
    Views:
    123
    Shlomy akons
    Sep 26, 2005
  5. Replies:
    4
    Views:
    156
    somesh g
    Sep 27, 2013
Loading...

Share This Page