Search in sources :

Example 1 with CTXf

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

the class TestColumnHelper method testGetSetColDefaultStyle.

@Test
public void testGetSetColDefaultStyle() throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet();
    CTWorksheet ctWorksheet = sheet.getCTWorksheet();
    ColumnHelper columnHelper = sheet.getColumnHelper();
    // POI column 3, OOXML column 4
    CTCol col = columnHelper.getOrCreateColumn1Based(4, false);
    assertNotNull(col);
    assertNotNull(columnHelper.getColumn(3, false));
    columnHelper.setColDefaultStyle(3, 2);
    assertEquals(2, columnHelper.getColDefaultStyle(3));
    assertEquals(-1, columnHelper.getColDefaultStyle(4));
    StylesTable stylesTable = workbook.getStylesSource();
    CTXf cellXf = CTXf.Factory.newInstance();
    cellXf.setFontId(0);
    cellXf.setFillId(0);
    cellXf.setBorderId(0);
    cellXf.setNumFmtId(0);
    cellXf.setXfId(0);
    stylesTable.putCellXf(cellXf);
    CTCol col_2 = ctWorksheet.getColsArray(0).addNewCol();
    col_2.setMin(10);
    col_2.setMax(12);
    col_2.setStyle(1);
    assertEquals(1, columnHelper.getColDefaultStyle(11));
    XSSFCellStyle cellStyle = new XSSFCellStyle(0, 0, stylesTable, null);
    columnHelper.setColDefaultStyle(11, cellStyle);
    assertEquals(0, col_2.getStyle());
    assertEquals(1, columnHelper.getColDefaultStyle(10));
    workbook.close();
}
Also used : CTXf(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) CTCol(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol) StylesTable(org.apache.poi.xssf.model.StylesTable) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Test(org.junit.Test)

Example 2 with CTXf

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

the class TestXSSFSheet method setDefaultColumnStyle.

@Test
public void setDefaultColumnStyle() throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet();
    CTWorksheet ctWorksheet = sheet.getCTWorksheet();
    StylesTable stylesTable = workbook.getStylesSource();
    XSSFFont font = new XSSFFont();
    font.setFontName("Cambria");
    stylesTable.putFont(font);
    CTXf cellStyleXf = CTXf.Factory.newInstance();
    cellStyleXf.setFontId(1);
    cellStyleXf.setFillId(0);
    cellStyleXf.setBorderId(0);
    cellStyleXf.setNumFmtId(0);
    stylesTable.putCellStyleXf(cellStyleXf);
    CTXf cellXf = CTXf.Factory.newInstance();
    cellXf.setXfId(1);
    stylesTable.putCellXf(cellXf);
    XSSFCellStyle cellStyle = new XSSFCellStyle(1, 1, stylesTable, null);
    assertEquals(1, cellStyle.getFontIndex());
    sheet.setDefaultColumnStyle(3, cellStyle);
    assertEquals(1, ctWorksheet.getColsArray(0).getColArray(0).getStyle());
    workbook.close();
}
Also used : CTXf(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf) CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) StylesTable(org.apache.poi.xssf.model.StylesTable) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Test(org.junit.Test)

Example 3 with CTXf

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

the class XSSFCellStyle method clone.

/**
     * Make a copy of this style. The underlying CTXf bean is cloned,
     * the references to fills and borders remain.
     *
     * @return a copy of this style
     */
@Override
public Object clone() {
    CTXf xf = (CTXf) _cellXf.copy();
    int xfSize = _stylesSource._getStyleXfsSize();
    int indexXf = _stylesSource.putCellXf(xf);
    return new XSSFCellStyle(indexXf - 1, xfSize - 1, _stylesSource, _theme);
}
Also used : CTXf(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf)

Aggregations

CTXf (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf)3 StylesTable (org.apache.poi.xssf.model.StylesTable)2 Test (org.junit.Test)2 CTWorksheet (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet)2 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)1 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1 CTCol (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)1