| Issue 307: | Could we just create an excel export without showing the table on jsp? | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Hello, One of the client req is to get a logging report in xls. We are having a similar table in our app. However, we were trying to use Jmesa code to create an xls output even when we dont show the table? Is this possible as I feel it should be and pretty easy to do. Could you give me a path that I can follow to achieve this? (BTW, the clients think Jmesa rocks! They just cant get enough of it ;))
Mar 11, 2011
Project Member
#1
jeff.johnston.mn@gmail.com
Mar 14, 2011
Thank You very much for your response.
Could you tell me which version of jmesa this code reflects?
I am trying it in 2.3.4 and there is no renderExport(ExportType exportType,
View view) method in ExcelViewExporter.
I also checked in 2.5 and 3.0
The view does not get set in my tableFacade.
Dont know where its going wrong.
I am trying to tweak this code to write out the export into a file in a dir
and not into response.
Could you please help?
Thanks.
*
public* String render() {
Limit l = getLimit();
View view = getView();
*try* {
*if* (l.getExportType() == ExportType.*EXCEL*) {
*new* CustomExcelViewExporter(view, "", response).export();
*return* "export successful";
} *else* {
*return* *super*.render();
//return "export successful";
}
} *catch* (Exception e) {
//logger.error("Not able to perform the " + exportType + " export.", e);
e.printStackTrace();
*return* e.getMessage();
}
}
Mar 14, 2011
Ok, try this. Instead of doing (from the example): tableFacade.render(); Try doing: View view = tableFacade.getView(); byte[] bytes = view.getBytes();
Mar 14, 2011
Instead I tried this :
*
public* *void* export(String fileName)
*throws* Exception
{
HSSFWorkbook workbook = (HSSFWorkbook)getView().render();
// responseHeaders(response);
// workbook.write(response.getOutputStream());
// File *temp* = new File("C:\\DevWork\\Releases\\*nci*
-release-3_9\\Project404\\target\\web-*app*\\exports\\manualExport.xls");
File temp = *new* File((fileName!=*null* ? fileName : "manualExport")+".xls"
);
*try* {
FileOutputStream out = *new* FileOutputStream (temp);
out.write(workbook.getBytes());
out.close();
} *catch* (IOException e) {
}
}
I do get the xls files in the dir. However, when I open them, the export is
not rendered properly.
It says, Microsoft Exccel as to recver this file. After a couple of times of
'recovering' the file is displayed with the data.
Any thoughts?
Mar 14, 2011
I am doing it this way now.
Still the Recovevry error.
File temp = *new* File((fileName!=*null* ? fileName : "manualExport")+".xls"
);
*try* {
FileOutputStream out = *new* FileOutputStream (temp);
out.write(getView().getBytes());
out.close();
} *catch* (IOException e) {
}
Mar 14, 2011
Strange...but the data does show up correctly? Maybe try a Google search and see if you can find anything out? You could also try JExcel...that would just require you to put the jar file in and then change the export type.
Mar 14, 2011
Yes. The data does show up correctly after 'recovering it twice' Let me try the JEXCEL too.
Mar 14, 2011
Could it be because I am giving the fileName while writing and also the extension as .xls?
Mar 14, 2011
I figured it out.
I did this and it works fine now.
*
try* {
FileOutputStream out = *new* FileOutputStream (temp);
workbook.write(out);
//out.write(workbook.getBytes());
out.close();
} *catch* (IOException e) {
}
Many thanks!
Mar 15, 2011
Awesome!
Status:
Fixed
|