{"record":{"id":"cac58cc4c6e53437","repo":"pentaho/pentaho-kettle","slug":"kettleexception-e-excelwriterstep","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/excelwriter/ExcelWriterStep.java","lineNumber":299,"sourceCode":"        extendDataValidationRanges();\n      }\n\n      // force recalculation of formulas if requested\n      if ( meta.isForceFormulaRecalculation() ) {\n        recalculateAllWorkbookFormulas();\n      }\n      data.wb.write( out );\n      if( data.wb instanceof SXSSFWorkbook ) {\n        SXSSFWorkbook sxssfWorkbook = (SXSSFWorkbook) data.wb;\n        sxssfWorkbook.dispose();\n        sxssfWorkbook.close();\n      }\n      else {\n        data.wb.close();\n      }\n\n    } catch ( IOException e ) {\n      throw new KettleException( e );\n    } finally {\n      IOUtils.closeQuietly( data.wb );\n      data.wb = null;\n    }\n  }\n\n  private void extendDataValidationRanges() {\n    DataValidationHelper helper = data.sheet.getDataValidationHelper();\n    for ( DataValidation validation : data.sheet.getDataValidations() ) {\n      CellRangeAddressList rangeList = validation.getRegions();\n      // extend ranges that include data rows\n      boolean updated = false;\n      for ( CellRangeAddress range : rangeList.getCellRangeAddresses() ) {\n        // extend any ranges that apply to the first data row but not the last\n        if ( range.containsRow( data.startingRow ) && !range.containsRow( data.posY ) ) {\n          range.setLastRow( data.posY );\n          updated = true;\n        }","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/excelwriter/ExcelWriterStep.java#L281-L317","documentation":"ExcelWriterStep.closeOutputFile closes the underlying workbook (data.wb) and wraps any IOException in a bare KettleException. It means the generated Excel workbook could not be flushed/closed, so the output file may be incomplete or corrupt.","triggerScenarios":"closeOutputFile() calls data.wb.close() (or write()) and an IOException occurs — disk full, stream already closed, file locked by another process, or the underlying output stream failed.","commonSituations":"Target disk quota/full filesystem; the output file is open in Excel or another reader while the transformation writes; permission changes on the output directory; network drive disconnect during write of a large sheet.","solutions":["Check the wrapped IOException cause for disk/permission/lock details.","Ensure the output file is not open in Excel or held by another process during the run.","Verify free disk space and write permissions in the output directory.","Write to a local temp file and move it to the final location after success.","If writing to a network share, confirm the share is stable or write locally first."],"exampleFix":"// before: closing workbook while file is locked\nFileOutputStream fos = new FileOutputStream( lockedFile ); // Excel has it open\n// after: verify writability and write atomically\nFile tmp = File.createTempFile( \"out\", \".xlsx\", outputDir );\n// write workbook to tmp, then:\nFiles.move( tmp.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING );","handlingStrategy":"try-catch","validationCode":"File target = new File( outputPath );\nif ( target.exists() && !target.canWrite() ) throw new IllegalStateException( \"Output file locked: \" + target );\nif ( target.getFreeSpace() < minRequiredBytes ) throw new IllegalStateException( \"Low disk space\" );","typeGuard":null,"tryCatchPattern":"try { workbook.close(); } catch ( IOException | KettleException e ) { logError( \"Workbook close failed, output may be corrupt: \" + e.getMessage(), e ); }","preventionTips":["Never open the output file in Excel while the transformation runs.","Monitor free disk space on the output volume.","Write to a temp file and atomically move to the final name."],"tags":["pentaho-kettle","excel-writer","io","workbook-close"],"backgroundTag":"file-write-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"}