title: Apache POI full workbook copy
body: <p>Have an issue with Apache POI (3.8 final release).</p>
  
  <p>My task: create some xls/xlsx files according data from basic xls/xlsx document.</p>
  
  <p>First of all, I try to copy some data (Cell, CellStyle and etc) from base document to destinations document through <code>CellStyle.cloneFrom</code>. It looks good, but when I opened xlsx file (<code>xl/styles.xml</code>) I found that it had different count of style (and fonts) than my source document. </p>
  
  <p>Can I create full copy of source xls/xlsx document via POI API?</p>
  
  <p>Code that create template of base document and create new document:</p>
  
  <pre><code>public WorkbookTemplate constructTemplate(Workbook wb)
  {
      //copy styles from template
      styles = new HashSet&lt;CellStyle&gt;(wb.getNumCellStyles());
      for (short i = 0; i &lt; wb.getNumCellStyles(); i++)
      {
          styles.add(wb.getCellStyleAt(i));
      }
      System.out.println(wb.getNumCellStyles());
  
      for (int i = 0; i &lt; wb.getNumberOfSheets(); i++)
      {
          Sheet sheet = wb.getSheetAt(i);
          SheetTemplate sheetTemplate = new SheetTemplate(this);
          sheets.add(sheetTemplate.constructTemplate(sheet));
      }
  
      return this;
  }
  
  public Workbook applyTemplate(Workbook wb, JXPathContext context)
  {
      preProcessOfWorkBook(wb);
      System.out.println(wb.getNumCellStyles());
  
      for (SheetTemplate sheetTemplate : sheets)
      {
          Sheet newSheet = wb.createSheet(sheetTemplate.getSheetName());
          sheetTemplate.applyTemplate(newSheet, context);
      }
  
      return wb;
  }
  
  public void preProcessOfWorkBook(Workbook wb)
  {
      //Transfer of CellStyles
      styleConvert = new HashMap&lt;CellStyle, CellStyle&gt;(styles.size());
      for (CellStyle style : styles)
      {
          CellStyle bufStyle = wb.createCellStyle();
          bufStyle.cloneStyleFrom(style);
          styleConvert.put(style, bufStyle);
      }
  }
  </code></pre>
  
  <p>It's part of WorkbookTemplate class, constructTemplate - creates it, and applyTemplate - transfers data from template to Workbook instance </p>