{"record":{"id":"40ee3c1e7fb9537c","repo":"pentaho/pentaho-kettle","slug":"kettleexception-e-poiworkbook","errorCode":null,"errorMessage":"KettleException( e )","messagePattern":"KettleException\\( e \\)","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/excelinput/poi/PoiWorkbook.java","lineNumber":89,"sourceCode":"            opcpkg = OPCPackage.open( excelFile );\n            workbook = XSSFWorkbookFactory.createWorkbook( opcpkg );\n          } catch ( Exception ex ) {\n            workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( excelFile, password );\n          }\n        }\n      } else {\n          //default value for maximum allowed size we are maintaining 150MB  150 * 1024 * 1024\n          int maxSize = Const.toInt( EnvUtil.getSystemProperty( Const.POI_BYTE_ARRAY_MAX_SIZE ), 157286400 );\n          // Increase the maximum allowed size\n          org.apache.poi.util.IOUtils.setByteArrayMaxOverride( maxSize );\n          internalIS = KettleVFS.getInstance( bowl ).getInputStream( filename );\n          workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( internalIS, password );\n      }\n    } catch ( EncryptedDocumentException e ) {\n      log.logError( \"Unable to open spreadsheet.  If the spreadsheet is password protected please double check the password is correct.\" );\n      throw new KettleException( e.getLocalizedMessage() );\n    } catch ( Exception e ) {\n      throw new KettleException( e );\n    }\n  }\n\n  public PoiWorkbook( InputStream inputStream, String encoding ) throws KettleException {\n    this.encoding = encoding;\n\n    try {\n      workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( inputStream );\n    } catch ( Exception e ) {\n      throw new KettleException( e );\n    }\n  }\n\n  public void close() {\n    try {\n      if ( internalIS != null ) {\n        internalIS.close();\n      }","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/excelinput/poi/PoiWorkbook.java#L71-L107","documentation":"The catch-all branch of PoiWorkbook's filename constructor wraps any non-encryption Exception from opening the workbook (invalid file, wrong format, IOUtils byte-array limit exceeded, corrupt ZIP) in a KettleException with the original as cause. It is the generic 'could not load this workbook' failure.","triggerScenarios":"new PoiWorkbook(bowl, filename, password, encoding, log) when WorkbookFactory.create or KettleVFS.getInputStream throws anything other than EncryptedDocumentException: FileNotFound, InvalidFormatException, IOException, POI's IOUtils limit breach.","commonSituations":"Pointing the step at an .ods, .csv, or HTML file mislabeled as .xlsx; file locked or unreadable by the service account; very large workbooks exceeding POI's default byte-array max override configured via maxSize.","solutions":["Verify the file exists, is readable, and is a genuine xls/xlsx (check with `file` command).","Inspect e.getCause(); if it mentions a byte-array max, increase the maxSize configuration.","Select the correct reader (ODS vs POI) for the actual file format.","Re-save/export the workbook from Excel to repair structural corruption."],"exampleFix":"// before\nWorkbook wb = new PoiWorkbook(bowl, filename, password, encoding, log);\n// after\nif (!filename.endsWith(\".xls\") && !filename.endsWith(\".xlsx\"))\n  throw new KettleException(\"Expected xls/xlsx, got: \" + filename);\nWorkbook wb = new PoiWorkbook(bowl, filename, password, encoding, log);","handlingStrategy":"validation","validationCode":"File f = new File(filename);\nif (!f.exists() || !f.canRead()) throw new KettleException(\"Cannot read: \" + filename);\ntry (FileInputStream in = new FileInputStream(f)) {\n  byte[] hdr = new byte[4]; in.read(hdr);\n  boolean xls = hdr[0]=='D'&&hdr[1]=='C'; boolean xlsx = hdr[0]=='P'&&hdr[1]=='K';\n  if (!xls && !xlsx) throw new KettleException(\"Not an xls/xlsx file: \" + filename);\n}","typeGuard":null,"tryCatchPattern":"try { wb = new PoiWorkbook(bowl, filename, password, encoding, log); } catch (KettleException e) { throw new KettleException(\"Open failed for '\" + filename + \"'; cause: \" + e.getCause(), e); }","preventionTips":["Sniff magic bytes to confirm xls/xlsx before opening","Size-check large files and raise POI's byte-array max override if needed","Ensure the service account has read permissions and the file is not locked","Route ods/csv to the appropriate reader"],"tags":["poi","workbook-open","kettle-exception","file-format"],"backgroundTag":"file-open-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}