title: Using XSSF to write xlsx using Apache POI
body: <p>Can someone give me an example of using <code>XSSF</code> to write <code>xlsx</code> files please?</p>
  
  <p><strong>Edit:</strong> aha...I did it myself the jars you'd need are-</p>
  
  <p>dom4j
  poi-3.8.jar
  poi-ooxml-3.8.jar
  poi-ooxml-schemas-3.8.jar
  xbean.jar</p>
  
  <p>Sample code -</p>
  
  <pre><code>package com.angrydog.impl;
  
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.util.Date;
  import java.util.Enumeration;
  import java.util.Iterator;
  import java.util.Vector;
  
  import org.apache.poi.xssf.usermodel.XSSFCell;
  import org.apache.poi.xssf.usermodel.XSSFRow;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  public class XSSFWorkBookWriter  {
  
      public void writeWorkBook(Vector table) throws WorkBookException {      
  
          XSSFWorkbook workBook = new XSSFWorkbook();
          XSSFSheet sheet = workBook.createSheet();
          table=new Vector();
          table.add(new String("Howdy"));
          table.add(new java.sql.Date(2012,06,20));
          table.add(new Double(13.35D));
          table.add(new String("Fine"));
          table.add(new java.sql.Date(2012,06,20));
          table.add(new Double(13.38D));
  
          Iterator rows=table.iterator();
          Enumeration rowsOfVector=table.elements();
          int totalNoOfRows=table.size()/2;
          int currentRow=0;
          while (rows.hasNext () &amp;&amp; currentRow&lt;totalNoOfRows){
              XSSFRow row =  sheet.createRow(currentRow++);               
  
              for (int i = 0; i &lt; 3; i++) {
                  XSSFCell cell=row.createCell(i);
                  Object val=rows.next();
                  if( val instanceof String){
                      cell.setCellValue(val.toString());
                  }
                  else if(val instanceof Date){
                      cell.setCellValue((java.sql.Date)val);
                  }
                  else if(val instanceof Double){
                      cell.setCellValue((Double)val);
                  }
              }
          }
  
          FileOutputStream outPutStream = null;
          try {
              outPutStream = new FileOutputStream("C:\\\\"+"Try.xlsx");
              workBook.write(outPutStream);
          } catch (IOException e) {
              e.printStackTrace();
          } finally {
              if (outPutStream != null) {
                  try {
                      outPutStream.flush();
                      outPutStream.close();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
      }
  
      public static void main(String[] args) {
          XSSFWorkBookWriter bookWriter=new XSSFWorkBookWriter();
          try {
              bookWriter.writeWorkBook(new Vector());
          } catch (WorkBookException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  }
  </code></pre>