Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add new sheets to existing excel workbook using apache POI and PrimeFaces
    primarykey
    data
    text
    <p>I'm trying to create a new sheet in an existing excel workbook using apache POI using primefaces and java but have been unsuccessful so far. Can anyone please tell me how it is done? I am able to do it for single sheet </p> <p>The below code i have written for creating multiple sheets in one xls file, where i given the condition that it has no of rows greater than 65535 create new sheet and iterate it, but it is showing error</p> <p>WARNING: Invalid row number (65536) outside allowable range (0..65535) java.lang.IllegalArgumentException: Invalid row number (65536) outside allowable range (0..65535)</p> <p>My code is</p> <pre><code> public void postProcessXLS(Object document) { HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet sheet = wb.getSheetAt(0); HSSFFont font = wb.createFont(); font.setFontName(HSSFFont.FONT_ARIAL); Iterator rowIterator = sheet.rowIterator(); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setWrapText(false); cellStyle.setAlignment(HSSFCellStyle.ALIGN_GENERAL); cellStyle.setFont(font); System.out.println("Row number:"+sheet.getLastRowNum()); while (rowIterator.hasNext()) { System.out.println("Row number:"+sheet.getLastRowNum()); //sheet.rowIterator().next().getRowNum(); if(sheet.getLastRowNum() &gt;= 65535) { String sheetName = ""; for(int i=0;i&lt;searchResults.size();i++) { sheetName = "Document-" + i; HSSFSheet mySheet = wb.createSheet(sheetName); HSSFRow hssfRow = (HSSFRow) rowIterator.next(); Iterator iterator = hssfRow.cellIterator(); while (iterator.hasNext()) { HSSFCell hssfCell = (HSSFCell) iterator.next(); hssfCell.setCellStyle(cellStyle); } } } } } </code></pre> <p>and in my xhtml</p> <pre><code> &lt;h:commandLink&gt; &lt;p:graphicImage value="resources/images/excel.png" /&gt; &lt;p:dataExporter type="xls" target="nmeadata" postProcessor="#{decodeNMEAMessageAction.postProcessNmeaXLS}" fileName="decoded_all_nmeadata" /&gt; &lt;/h:commandLink&gt; &lt;h:commandLink&gt; &lt;p:graphicImage value="resources/images/excel.png" /&gt; &lt;p:dataExporter type="xls" target="nmeadata" postProcessor="#{decodeNMEAMessageAction.postProcessNmeaXLS}" fileName="decoded_page_nmeadata" pageOnly="true" /&gt; &lt;/h:commandLink&gt; </code></pre> <p><img src="https://i.stack.imgur.com/FY2VD.png" alt="Datatable which is imported to excel sheet"></p> <p>Is it possible to export data to multiple sheets using primefaces. Other wise please tell me how it can be done using servlets.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload