-
FEATURED COMPONENTS
First time here? Check out the FAQ!
hallo i am newbie on zk.. i try to export data from grid to excel.. but i have problem.. the problem is only first page,, any wrong with my code? this is my code
@Command
public void exportListboxToExcel(@BindingParam("ref") Grid grid) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExcelExporter exporter = new ExcelExporter();
Grid newGrid = (Grid) grid.clone();
System.out.println(newGrid.getListModel().getSize()+"size data");
//the data is 20 but only 8 exported.. because only first page exported..
newGrid.setPageSize(10000);
exporter.export(newGrid, out);
AMedia amedia = new AMedia("data.xlsx", "xls", "application/file", out.toByteArray());
Filedownload.save(amedia);
out.close();
}
thanks very much for your help..
Oke,
Had this problem myself and found the solution for it :
<button label="Export" onClick="@command('renderMeshElementAndExport', ref=idListboxOrGrid, name='someExcelName')"/>
or
<button label="Export" onClick="@command('renderMeshElementAndExport', ref=idListboxOrGrid)"/>
@Command
public void renderMeshElementAndExport(@ContextParam(ContextType.BINDER) Binder binder, @BindingParam("ref") MeshElement meshElement,
@BindingParam("name") String name) throws Exception {
if (meshElement instanceof Grid) {
((Grid) meshElement).renderAll();
} else if (meshElement instanceof Listbox) {
((Listbox) meshElement).renderAll();
}
Map<String, Object> args = new HashMap<String, Object>();
args.put("ref", meshElement);
args.put("name", name);
binder.postCommand("exportMeshElementToExcel", args);
}
@Command
public void exportMeshElementToExcel(@BindingParam("ref") MeshElement meshElement, @BindingParam("name") String name)
throws Exception {
if (meshElement instanceof Listbox || meshElement instanceof Grid) {
if (name == null) {
name = meshElement.getParent().getPage().getTitle() == null ? "excelsheet" : meshElement.getParent().getPage().getTitle();
}
ByteArrayOutputStream out = export(meshElement);
logger.debug("file size : " + out.size());
AMedia amedia = new AMedia(name + ".xlsx", "xls", "application/file",
out.toByteArray());
Filedownload.save(amedia);
IOUtils.closeQuietly(out);
} else {
throw new IllegalArgumentException("We can only export grid or listbox");
}
}
private ByteArrayOutputStream export(MeshElement meshElement) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExcelExporter exporter = new ExcelExporter();
exporter.export(meshElement, out);
return out;
}
thank you chillworld. I don't test but I use export excel by model. It's flexible. I can control it
with a rowrenderer then, and do you have problems there? the Original question was exporting the listbox or grid.
chillworld ( 2014-09-08 05:29:26 +0800 )editGood day.
I have an error in the export line:
exporter.export(meshElement, out);
Give me the follow error description:
The type org.zkoss.poi.ss.usermodel.Row cannot be resolved. It is indirectly referenced from required .class files
Could you help me in this problem.
Thanks.
what meshelement are you trying to export and is it possible to send some (part) of the project to me?
chillworld ( 2017-02-15 11:22:39 +0800 )editAsked: 2013-07-15 05:37:13 +0800
Seen: 93 times
Last updated: Feb 15 '17
composite component help [closed]
EL in a forEach @command not working?
Different template for each grid row
Cardlayout animation is broken
Grid RowRender slow using 6.5.1 and sizable=true
setVisible(false), component will load or not
Decimalbox and doublebox value rounded on iPad
history management with page status
I have same problem. Can any one help me?
Yoshihiro ( 2014-09-05 11:18:57 +0800 )edit@Yoshihiro plz feedback if it helped
chillworld ( 2014-09-05 12:43:18 +0800 )edit