mnabeelkhan / tableexport-for-vaadin

Automatically exported from code.google.com/p/tableexport-for-vaadin
0 stars 0 forks source link

Sheet index (-1) is out of range #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
1. Use Hierarchical container
2. excelExport.setDisplayTotals(false);
3. see exception below

com.vaadin.event.ListenerMethod$MethodException
Cause: java.lang.IllegalArgumentException: Sheet index (-1) is out of range 
(0..0)
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:532)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
    at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219)
    at com.vaadin.ui.Button.fireClick(Button.java:550)
    at com.vaadin.ui.Button.changeVariables(Button.java:217)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1445)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1393)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1312)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:763)
    at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
    at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
    at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:905)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:592)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2036)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: Sheet index (-1) is out of range 
(0..0)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.validateSheetIndex(HSSFWorkbook.java:403)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.removeSheetAt(HSSFWorkbook.java:822)
    at com.vaadin.addon.tableexport.ExcelExport.finalSheetFormat(ExcelExport.java:730)
    at com.vaadin.addon.tableexport.ExcelExport.convertTable(ExcelExport.java:271)
    at com.vaadin.addon.tableexport.TableExport.export(TableExport.java:80)

Solution
ExcelExport.java:730

workbook.removeSheetAt(workbook.getSheetIndex(hierarchicalTotalsSheet)); 
//should be checked as it's done in initialSheetSetup()

Original issue reported on code.google.com by alexey.b...@gmail.com on 3 Feb 2012 at 11:53

GoogleCodeExporter commented 8 years ago
//Override with fix error 
@Override
protected void finalSheetFormat()
{
    final FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
    if (isHierarchical())
    {
        for (final Row r : sheet)
        {
            for (final Cell c : r)
            {
                if (c.getCellType() == Cell.CELL_TYPE_FORMULA)
                {
                    evaluator.evaluateInCell(c);
                }
            }
        }
        workbook.setActiveSheet(workbook.getSheetIndex(sheet));                             
        int index = workbook.getSheetIndex(hierarchicalTotalsSheet); //fix error
        if (index > -1) workbook.removeSheetAt(index);
    }
    else
    {
        evaluator.evaluateAll();
    }
    for (int col = 0; col < getPropIds().size(); col++)
    {
        sheet.autoSizeColumn(col);
    }
}

Original comment by the.one....@gmail.com on 6 Feb 2012 at 5:25

GoogleCodeExporter commented 8 years ago
I am incorporating a change suggested on the Vaadin discussion area for this 
project (https://vaadin.com/forum/-/message_boards/view_message/1236773).  
Where the.one.nexus has these two lines:

        int index = workbook.getSheetIndex(hierarchicalTotalsSheet); //fix error
        if (index > -1) workbook.removeSheetAt(index);

I have instead:

            if (hierarchicalTotalsSheet != null) {
                workbook.removeSheetAt(workbook.getSheetIndex(hierarchicalTotalsSheet));
            }

This should fix the same bug you're talking about. let me know if it does not.

Original comment by jnas...@gmail.com on 17 Mar 2012 at 11:56

GoogleCodeExporter commented 8 years ago
fixed

Original comment by jnas...@gmail.com on 18 Mar 2012 at 12:06