1

ExcelExporter form Grid only export only first page of data

asked 2013-07-15 05:37:13 +0800

adilramdan gravatar image adilramdan
11 1

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..

delete flag offensive retag edit

Comments

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

3 Answers

Sort by ยป oldest newest most voted
0

answered 2014-09-05 11:36:20 +0800

chillworld gravatar image chillworld flag of Belgium
5143 3 9
https://github.com/chillw...

updated 2014-09-05 11:37:19 +0800

Oke,

Had this problem myself and found the solution for it :

Zul:

<button label="Export"  onClick="@command('renderMeshElementAndExport', ref=idListboxOrGrid, name='someExcelName')"/>

or

<button label="Export"  onClick="@command('renderMeshElementAndExport', ref=idListboxOrGrid)"/>

Java:

@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;
}
link publish delete flag offensive edit

Comments

if you want the technical explication, just ask

chillworld ( 2014-09-05 11:38:47 +0800 )edit
0

answered 2014-09-08 04:03:33 +0800

Yoshihiro gravatar image Yoshihiro
1

thank you chillworld. I don't test but I use export excel by model. It's flexible. I can control it

link publish delete flag offensive edit

Comments

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 )edit
0

answered 2017-02-15 03:56:39 +0800

Ness gravatar image Ness flag of Mexico
1

Good 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.

link publish delete flag offensive edit

Comments

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 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-07-15 05:37:13 +0800

Seen: 80 times

Last updated: Feb 15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More