title: Preserve images in Excel headers using Apache POI
body: <p>I am trying to generate Excel reports using Apache POI 3.6 (latest).</p>
  
  <p>Since POI has limited support for header and footer generation (text only), I decided to start from a blank excel file with the header already prepared and fill the Excel cells using POI (cf. question <a href="https://stackoverflow.com/questions/714172/poi-using-excel-templates">714172</a>).</p>
  
  <p>Unfortunately, when opening the workbook with POI and writing it immediately to disk (without any cell manpulation), the header seems to be lost.</p>
  
  <p>Here is the code I used to test this behavior:</p>
  
  <pre><code>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
          }
        }
      }
    }
  }
  </code></pre>