-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
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);
Another way here
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();
}
Asked: 2015-02-03 09:10:54 +0800
Seen: 69 times
Last updated: Feb 05 '15
can you show the listbox in the zul?
chillworld ( 2015-02-03 11:05:25 +0800 )editYes I can
emreturka ( 2015-02-03 11:49:36 +0800 )editI mean edit your question and put the zul code of the listbox there.
chillworld ( 2015-02-03 12:11:49 +0800 )editNo.My problem is about libraries.exporter.export(kayitListBoxId, out); is underlying eclipse.
emreturka ( 2015-02-03 12:28:59 +0800 )edityou use ZK exporter (http://books.zkoss.org/wiki/SmallTalks/2012/December/ExportGridorListboxtoPDForExcel)or another exporter?
chillworld ( 2015-02-03 13:16:22 +0800 )edit