Search in sources :

Example 6 with CTTableColumn

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn in project poi by apache.

the class XSSFTable method updateHeaders.

/**
     * Synchronize table headers with cell values in the parent sheet.
     * Headers <em>must</em> be in sync, otherwise Excel will display a
     * "Found unreadable content" message on startup.
     * 
     * If calling both {@link #updateReferences()} and
     * {@link #updateHeaders()}, {@link #updateReferences()}
     * should be called first.
     */
public void updateHeaders() {
    XSSFSheet sheet = (XSSFSheet) getParent();
    CellReference ref = getStartCellReference();
    if (ref == null)
        return;
    int headerRow = ref.getRow();
    int firstHeaderColumn = ref.getCol();
    XSSFRow row = sheet.getRow(headerRow);
    if (row != null && row.getCTRow().validate()) {
        int cellnum = firstHeaderColumn;
        for (CTTableColumn col : getCTTable().getTableColumns().getTableColumnArray()) {
            XSSFCell cell = row.getCell(cellnum);
            if (cell != null) {
                col.setName(cell.getStringCellValue());
            }
            cellnum++;
        }
        ctColumns = null;
        columnMap = null;
        xmlColumnPr = null;
        commonXPath = null;
    }
}
Also used : CellReference(org.apache.poi.ss.util.CellReference) CTTableColumn(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn)

Aggregations

CTTableColumn (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn)6 FileOutputStream (java.io.FileOutputStream)2 CellReference (org.apache.poi.ss.util.CellReference)2 CTTable (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 AreaReference (org.apache.poi.ss.util.AreaReference)1 TempFile (org.apache.poi.util.TempFile)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)1 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)1 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)1 XSSFTable (org.apache.poi.xssf.usermodel.XSSFTable)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1 XSSFXmlColumnPr (org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr)1 Test (org.junit.Test)1 CTTableColumns (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumns)1