Export Grid or Listbox to PDF or Excel"
Line 60: | Line 60: | ||
Although export Listbox/Grid to PDF or Excel is quite straightforward. However, it does have some limitation. For instance, it cannot export full contents with Grid/Listbox ROD enabled. In such use case, you can use renderer to render raw data to PDF/Excel directly. | Although export Listbox/Grid to PDF or Excel is quite straightforward. However, it does have some limitation. For instance, it cannot export full contents with Grid/Listbox ROD enabled. In such use case, you can use renderer to render raw data to PDF/Excel directly. | ||
Another advantage of renderer is that you can highly customize the rendering result. | Another advantage of renderer is that you can highly customize the rendering result. | ||
+ | |||
+ | ====PDF==== | ||
+ | |||
+ | ====Excel==== | ||
==Summary== | ==Summary== |
Revision as of 08:08, 26 November 2012
Export Grid or Listbox to PDF or Excel
Sam Chuang, Engineer, Potix Corporation
November 26, 2012
ZK 6.0 and later
Introduction
Web application developers often require to transform data into different format. For instance, to PDF format that enhance read accessibility and to Excel format that can further analyze data. This smalltalk is going to introduce a easy way that can transform from Grid or Listbox to PDF/Excel.
Demo
Usage
Export Listbox/Grid
As you can see the following sample code, export Listbox/Grid to PDF or Excel is quite straightforward.
@Command
public void exportGrid(@BindingParam("ref") Grid grid) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PdfExporter exporter = new PdfExporter();
exporter.export(grid, out);
AMedia amedia = new AMedia("FirstReport.pdf", "pdf", "application/pdf", out.toByteArray());
Filedownload.save(amedia);
out.close();
}
Excel
@Command
public void exportListboxToExcel(@BindingParam("ref") Listbox listbox) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExcelExporter exporter = new ExcelExporter();
exporter.export(listbox, out);
AMedia amedia = new AMedia("FirstReport.xlsx", "xls", "application/file", out.toByteArray());
Filedownload.save(amedia);
out.close();
}
Export data by Renderer
Although export Listbox/Grid to PDF or Excel is quite straightforward. However, it does have some limitation. For instance, it cannot export full contents with Grid/Listbox ROD enabled. In such use case, you can use renderer to render raw data to PDF/Excel directly. Another advantage of renderer is that you can highly customize the rendering result.
Excel
Summary
Download
- The demo web application can be downloaded here - Github
- The export.jar can be downloaded here- Github
Comments
Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License. |