0

Zk Excel export problem

asked 2015-02-03 09:10:54 +0800

emreturka gravatar image emreturka
9 2

updated 2015-02-04 13:14:46 +0800

I want to export an excel from Listbox.I have researched and used zk's documentation codes.Here is the codes;

@Listen("onClick = #excelImageId")
public void getExcelFile() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    ExcelExporter exporter = new ExcelExporter();
    exporter.export(kayitListBoxId, out);

    AMedia amedia = new AMedia("FirstReport.xlsx", "xls",
            "application/file", out.toByteArray());
    Filedownload.save(amedia);
    out.close();
}

Here is the zul file;

                <listbox id="kayitListBoxId"
                    emptyMessage="Kayıt yok!" model="${win$composer.kayitModelList}"
                    checkmark="true" mold="paging" pageSize="9">
                    <auxhead>
                        <auxheader colspan="2">
                            <textbox id="filterName" instant="true"
                                width="100px" />
                        </auxheader>
                        <auxheader colspan="2">
                            <hlayout>
                                <textbox id="filterSurname"
                                    instant="true" width="100px" />
                                <space width="85px" />
                                <textbox id="filterEposta"
                                    width="100px" />
                            </hlayout>
                        </auxheader>
                        <auxheader colspan="2">
                            <hlayout>
                                <textbox id="filterDogumTarihi"
                                    instant="true" width="100px" />
                                <space width="80px" />
                                <combobox id="filterCinsiyet" />
                            </hlayout>
                        </auxheader>
                        <auxheader colspan="2">
                            <combobox id="filterStudyDeg" />
                        </auxheader>
                    </auxhead>
                    <listhead>
                        <listheader width="32px" />
                        <listheader label="Ad" align="center"
                            sort="auto(ad)" width="190px" />
                        <listheader label="Soyad" align="center"
                            sort="auto(soyad)" width="190px" />
                        <listheader label="E-Posta" align="center"
                            width="190px" sort="auto(eposta)" />
                        <listheader label="Doğum Tarihi"
                            width="190px" align="center" sort="auto(dogumtarihi)" />
                        <listheader label="Cinsiyet" align="center"
                            sort="auto(cinsiyet)" width="190px" />
                        <listheader label="Tahsil" align="center"
                            sort="auto(tahsil)" width="190px" />
                    </listhead>
                    <template name="model">
                        <listitem>
                            <listcell />
                            <listcell label="${each.ad}" />
                            <listcell label="${each.soyad}" />
                            <listcell label="${each.eposta}" />
                            <listcell label="${each.dogumtarihi}" />
                            <listcell label="${each.cinsiyet}" />
                            <listcell label="${each.tahsil}" />
                        </listitem>
                    </template>
                </listbox>
                <separator width="700px" />
                <button id="deleteButtonId" label="Sil"
                    image="/widgets/img/delete.png" />
                <space spacing="20px" />
                <button id="updateButtonId" label="Güncelle"
                    image="/widgets/img/update.png" />
                <space spacing="20px" />
                <image id="excelImageId"
                    src="/widgets/img/excelFile.png" />
                <space spacing="100px" />
                <label id="recordNumberLabel" />
            </window>

exporter.export(kayitListBoxId, out); is giving error.The error is that "The type org.zkoss.poi.ss.usermodel.Row cannot be resolved. It is indirectly referenced from required .class files".What is the best or short way export an excel in zk framework.

delete flag offensive retag edit

Comments

can you show the listbox in the zul?

chillworld ( 2015-02-03 11:05:25 +0800 )edit

Yes I can

emreturka ( 2015-02-03 11:49:36 +0800 )edit

I mean edit your question and put the zul code of the listbox there.

chillworld ( 2015-02-03 12:11:49 +0800 )edit

No.My problem is about libraries.exporter.export(kayitListBoxId, out); is underlying eclipse.

emreturka ( 2015-02-03 12:28:59 +0800 )edit

you use ZK exporter (http://books.zkoss.org/wiki/SmallTalks/2012/December/ExportGridorListboxtoPDForExcel)or another exporter?

chillworld ( 2015-02-03 13:16:22 +0800 )edit

3 Answers

Sort by » oldest newest most voted
0

answered 2015-02-03 10:46:19 +0800

demizon gravatar image demizon
179 1 6

from my app...

        File file = new File("")
        byte[] buffer = new byte[(int) file.length()];
        FileInputStream fs = new FileInputStream(file);
        fs.read(buffer);
        fs.close();
        ByteArrayInputStream is = new ByteArrayInputStream(buffer);
        AMedia amedia = new AMedia("file.csv", "csv", "application/file", is);
        Filedownload.save(amedia);
link publish delete flag offensive edit
0

answered 2015-02-03 14:28:35 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Another way here

link publish delete flag offensive edit
0

answered 2015-02-05 09:46:09 +0800

emreturka gravatar image emreturka
9 2

I have find solution. Here is the codes;

    Workbook workbook = new HSSFWorkbook();
    Sheet listSheet = workbook.createSheet("Kişi Listesi");

    int rowIndex = 0;
    for (KayitParam kp : kayitList) {
        Row row = listSheet.createRow(rowIndex++);
        int cellIndex = 0;
        row.createCell(cellIndex++).setCellValue(kp.getAd());
        row.createCell(cellIndex++).setCellValue(kp.getSoyad());
        row.createCell(cellIndex++).setCellValue(kp.getEposta());
        row.createCell(cellIndex++).setCellValue(kp.getCinsiyet());
        row.createCell(cellIndex++).setCellValue(kp.getDogumtarihi());
        row.createCell(cellIndex++).setCellValue(kp.getTahsil());
    }

    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        workbook.write(baos);
        AMedia amedia = new AMedia("Kisiler.xls", "xls",
                "application/file", baos.toByteArray());
        Filedownload.save(amedia);
        baos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
link publish delete flag offensive 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: 2015-02-03 09:10:54 +0800

Seen: 69 times

Last updated: Feb 05 '15

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