Export to Excel"
From Documentation
(Created page with "{{ZKSpreadsheetEssentials3PageHeader}} One of Spreadsheet's powerful feature is to export its book model as an Excel file then we can open the file with Microsoft Excel. Besi...") |
|
(No difference)
|
Revision as of 06:59, 22 August 2013
One of Spreadsheet's powerful feature is to export its book model as an Excel file then we can open the file with Microsoft Excel. Besides, exporting to a file is also the only way to persist Spreadsheet's book model and then import it in the future. The following codes demonstrate how to export a book model to a temporary file with Exporter and make users download it in a browser:
public class ExportComposer extends SelectorComposer<Component> {
@Wire
private Spreadsheet ss;
@Listen("onClick = #exportExcel")
public void doExport() throws IOException{
Exporter exporter = Exporters.getExporter();
Book book = ss.getBook();
File file = File.createTempFile(Long.toString(System.currentTimeMillis()),"temp");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
exporter.export(book, fos);
}finally{
if(fos!=null){
fos.close();
}
}
//generate file name upon book type (2007,2003)
String dlname = BookUtil.suggestName(book);
Filedownload.save(new AMedia(dlname, null, null, file, true));
}
}
- Line 8: Get an Exporter instance.
- Line 14: Currently, we only support exporting whole book.
All source code listed in this book is at Github.