title: Apache POI - formatting output to HTML
body: <p>I am writing to an Excel file using Apache POI, but I want my output to be formatted as HTML not as literal text.</p>
  
  <pre><code>SXSSFWorkbook workbook = new SXSSFWorkbook();
  Sheet sheet0 = workbook.createSheet("sheet0");
  Row row0 = sheet0.createRow(2);
  Cell cell0 = row0.createCell(2);
  
  cell0.setCellValue("&lt;html&gt;&lt;b&gt;blah blah blah&lt;/b&gt;&lt;/html&gt;");
  </code></pre>
  
  <p>What appears when I open the Excel file is:</p>
  
  <pre><code>"&lt;html&gt;&lt;b&gt;blah blah blah&lt;/b&gt;&lt;/html&gt;"
  </code></pre>
  
  <p>but I want:</p>
  
  <p><strong>"blah blah blah"</strong></p>
  
  <p>essentially I am looking for a piece of code along the lines of:</p>
  
  <pre><code>cell0.setCellFormat(CellFormat.HTML);
  </code></pre>
  
  <p>Except, that doesn't exist.</p>
  
  <p>here is some info on this topic</p>
  
  <p><a href="http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java" rel="nofollow">http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java</a></p>
  
  <p>I will try this for now:</p>
  
  <pre><code>public void printPage() throws IOException {
      try {
          ensureOut();
          if (completeHTML) {
              out.format(
                      "&lt;?xml version=\"1.0\" encoding=\"iso-8859-1\" ?&gt;%n");
              out.format("&lt;html&gt;%n");
              out.format("&lt;head&gt;%n");
              out.format("&lt;/head&gt;%n");
              out.format("&lt;body&gt;%n");
          }
  
          print();
  
          if (completeHTML) {
              out.format("&lt;/body&gt;%n");
              out.format("&lt;/html&gt;%n");
          }
      } finally {
          if (out != null)
              out.close();
          if (output instanceof Closeable) {
              Closeable closeable = (Closeable) output;
              closeable.close();
          }
      }
  }
  </code></pre>