title: How to insert a table in ms excel using apache java poi
body: <p>I am trying to insert a table in Excel using Java Apache Poi. But when I am opening the xlsx file it is throwing the following error and I could not solve it:</p>
  
  <pre><code>Removed Part: /xl/tables/table1.xml part with XML error. (Table) Load error. Line 2
  repaired records: table from /xl/tables/table1.xml part (table)
  </code></pre>
  
  <p>My code is the following:</p>
  
  <pre><code>import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFTable;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable;
  import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn;
  import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumns;
  import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo;
  
  public class Test {
  
    public static void main(String[] args) throws FileNotFoundException, IOException {
      XSSFWorkbook workbook = new XSSFWorkbook();
      XSSFSheet sheet = workbook.createSheet("Architecture");
  
      XSSFTable table = sheet.createTable();
      CTTable cttable = table.getCTTable();
  
  
      cttable.setDisplayName("Table1");
      cttable.setId(1);
      cttable.setName("Test");
      cttable.setRef("A1:C11");
      cttable.setTotalsRowShown(false);
  
      CTTableStyleInfo styleInfo = cttable.addNewTableStyleInfo();
      styleInfo.setShowColumnStripes(false);
      styleInfo.setShowRowStripes(true);
  
  
      CTTableColumns columns = cttable.addNewTableColumns();
      columns.setCount(3);
      for (int i = 1; i &lt;= 3; i++) {
        CTTableColumn column = columns.addNewTableColumn();
        column.setId(i);
        column.setName("Column" + i);
      }
  
      try (FileOutputStream outputStream = new FileOutputStream("C:\\Office\\TimeSheet\\JavaBooks.xlsx")) {
        workbook.write(outputStream);
      }
    }
  }
  </code></pre>
  
  <p>How can I insert a table in Microsft Excel using Apache Java Poi?</p>