{"record":{"id":"d904b5ef7779cfb0","repo":"pentaho/pentaho-kettle","slug":"excelwriterstep-exception-templatenotfound","errorCode":"ExcelWriterStep.Exception.TemplateNotFound","errorMessage":"ExcelWriterStep.Exception.TemplateNotFound (localized message with template sheet name)","messagePattern":"ExcelWriterStep\\.Exception\\.TemplateNotFound \\(localized message with template sheet name\\)","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/excelwriter/ExcelWriterStep.java","lineNumber":832,"sourceCode":"    // Find last row and append accordingly\n    if ( !data.createNewSheet && meta.getAppendOffset() != 0 && appendingToSheet ) {\n      data.posY += meta.getAppendOffset();\n    }\n  }\n\n  /**\n   * Creates a new sheet\n   *\n   * @param replacingSheetAt\n   *          Order to place sheet in, if >= 0\n   * @throws KettleException\n   */\n  private void createSheet( int replacingSheetAt ) throws KettleException {\n    if ( meta.isTemplateSheetEnabled() ) {\n      Sheet ts = data.wb.getSheet( data.realTemplateSheetName );\n      // if template sheet is missing, break\n      if ( ts == null ) {\n        throw new KettleException(\n            BaseMessages.getString( PKG, \"ExcelWriterStep.Exception.TemplateNotFound\", data.realTemplateSheetName ) );\n      }\n      data.sheet = data.wb.cloneSheet( data.wb.getSheetIndex( ts ) );\n      data.wb.setSheetName( data.wb.getSheetIndex( data.sheet ), data.realSheetname );\n      // unhide sheet in case it was hidden\n      data.wb.setSheetHidden( data.wb.getSheetIndex( data.sheet ), false );\n      if ( meta.isTemplateSheetHidden() ) {\n        data.wb.setSheetHidden( data.wb.getSheetIndex( ts ), true );\n      }\n    } else {\n      // no template to use, simply create a new sheet\n      data.sheet = data.wb.createSheet( data.realSheetname );\n    }\n    if ( replacingSheetAt > -1 ) {\n      data.wb.setSheetOrder( data.sheet.getSheetName(), replacingSheetAt );\n    }\n  }\n","sourceCodeStart":814,"sourceCodeEnd":850,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/excelwriter/ExcelWriterStep.java#L814-L850","documentation":"When 'Use template' with a template sheet is enabled, createSheet() looks up data.realTemplateSheetName in the opened template workbook. If the sheet does not exist (getSheet returns null), this localized KettleException is thrown because the output sheet is produced by cloning the template sheet.","triggerScenarios":"Template sheet name field or static value does not match any sheet name in the template workbook (case-sensitive lookup via getSheet).","commonSituations":"Template workbook was edited and the sheet renamed; sheet name contains leading/trailing spaces; sheet name field resolves to a value that does not exist at runtime; using a template saved in another language/locale with differently named sheets.","solutions":["Verify the template sheet name exactly matches a sheet in the template file (case and spaces)","Open the template file and confirm the sheet exists","If the sheet name comes from a field, log/inspect the resolved value at runtime","Trim whitespace in the sheet name field before the step","Point the template to a workbook containing the expected sheet"],"exampleFix":"// before\nString templateSheet = \" Sheet1\"; // trailing space, getSheet returns null\n// after\nString templateSheet = \"Sheet1\"; // must exactly match the sheet in the template workbook","handlingStrategy":"validation","validationCode":"try (FileInputStream fis = new FileInputStream(templatePath);\n     Workbook wb = WorkbookFactory.create(fis)) {\n  String sheetName = environmentSubstitute(meta.getTemplateSheetName()).trim();\n  if (wb.getSheet(sheetName) == null) {\n    throw new IllegalStateException(\"Template sheet not found: \" + sheetName\n        + \"; available: \" + java.util.Arrays.toString(wb.getSheetNames()));\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim template sheet name; getSheet is exact-match","After editing templates, re-verify sheet names","Log resolved template sheet name when sourced from a field"],"tags":["excel","template","sheet-name","resource-not-found","kettle"],"backgroundTag":"resource-not-found","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"}