Export to Excel"

From Documentation
(Created page with '{{ZKSpreadsheetEssentialsPageHeader}} __TOC__ ===Purpose=== Export ZK Spreadsheet to Excel format === PdfExporter=== ZK Spreadsheet comes with <javadoc>org.zkoss.zss.model.Expor…')
 
Line 4: Line 4:
 
Export ZK Spreadsheet to Excel format
 
Export ZK Spreadsheet to Excel format
  
=== PdfExporter===
+
=== Getting Excel Exporter===
 
ZK Spreadsheet comes with <javadoc>org.zkoss.zss.model.Exporter</javadoc> implementation that allows ZK Spreadsheet contents to be exported to Excel format.
 
ZK Spreadsheet comes with <javadoc>org.zkoss.zss.model.Exporter</javadoc> implementation that allows ZK Spreadsheet contents to be exported to Excel format.
 
To export ZK Spreadsheet to Excel format use <javadoc method="getExporter(java.lang.String)">org.zkoss.zss.model.Exporters</javadoc> as shown below.
 
To export ZK Spreadsheet to Excel format use <javadoc method="getExporter(java.lang.String)">org.zkoss.zss.model.Exporters</javadoc> as shown below.
Line 12: Line 12:
  
 
<references/>
 
<references/>
 +
 
===ZUML===
 
===ZUML===
 
Here is an example ZUML file that display an Excel book file and has a button to export entire workbook.
 
Here is an example ZUML file that display an Excel book file and has a button to export entire workbook.

Revision as of 01:48, 14 December 2010


Purpose

Export ZK Spreadsheet to Excel format

Getting Excel Exporter

ZK Spreadsheet comes with Exporter implementation that allows ZK Spreadsheet contents to be exported to Excel format. To export ZK Spreadsheet to Excel format use Exporters.getExporter(String) as shown below.

Exporter c = Exporters.getExporter("excel");


ZUML

Here is an example ZUML file that display an Excel book file and has a button to export entire workbook.

<?page title="ZSS Export to Different File Format" contentType="text/html;charset=UTF-8"?>
<window width="100" height="100%"
	apply="org.zkoss.zssessentials.export.ExportComposer">
	<hbox>
		<button id="exportBtn" label="Export All"></button>
	</hbox>
	<spreadsheet id="spreadsheet"
		src="/WEB-INF/excel/export/export.xlsx" maxrows="200" maxcolumns="40"
		vflex="1" width="100%">
	</spreadsheet>
</window>

Composer

In composer there is one event handler for export button defined in above ZUML.

Exporting entire workbook

To export entire ZK Spreadsheet workbook contents use Exporter#export(Book,OutputStream) API. You should be able to get Book instance either by importing Excel book file using Importer interface or using Spreadsheet.getBook() API if ZK Spreadsheet component is already initialized with an Excel book file. You should also prepare OutputStream to which Excel format should be written to. For example

	public void onClick$exportBtn(Event evt) throws IOException {
		Book wb = spreadsheet.getBook();
		Exporter c = Exporters.getExporter("excel");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		c.export(wb, baos);
		Filedownload.save(baos.toByteArray(), "application/file",
				wb.getBookName());
	}

Here I am using Exporters to get Exporter implementation to export ZK Spreadsheet contents to Excel format.

See the full source code for Composer here

Version History

Last Update : 2010/12/14


Version Date Content
     


All source code listed in this book is at Github.


Last Update : 2010/12/14

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.