Apache POI 3.6 (最新) を使用して Excel レポートを生成しようとしています。
POI ではヘッダーとフッターの生成 (テキストのみ) のサポートが制限されているため、ヘッダーが既に用意されている空白の Excel ファイルから開始し、POI を使用して Excel セルに入力することにしました (質問714172を参照)。
残念ながら、POI を含むワークブックを開いてすぐに (セル操作なしで) ディスクに書き込むと、ヘッダーが失われるようです。
この動作をテストするために使用したコードは次のとおりです。
public final class ExcelWorkbookCreator {
public static void main(String[] args) {
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(new File("dump.xls"));
InputStream inputStream = ExcelWorkbookCreator.class.getResourceAsStream("report_template.xls");
HSSFWorkbook workbook = new HSSFWorkbook(inputStream, true);
workbook.write(outputStream);
} catch (Exception exception) {
throw new RuntimeException(exception);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException exception) {
// Nothing much to do
}
}
}
}
}