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