Search in sources :

Example 1 with CTDefinedNames

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

the class TestXSSFBugs method bug57176.

/**
     * CTDefinedNamesImpl should be included in the smaller
     * poi-ooxml-schemas jar
     */
@Test
public void bug57176() throws IOException {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57176.xlsx");
    CTDefinedNames definedNames = wb.getCTWorkbook().getDefinedNames();
    List<CTDefinedName> definedNameList = definedNames.getDefinedNameList();
    for (CTDefinedName defName : definedNameList) {
        assertNotNull(defName.getName());
        assertNotNull(defName.getStringValue());
    }
    assertEquals("TestDefinedName", definedNameList.get(0).getName());
    wb.close();
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CTDefinedName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName) CTDefinedNames(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames) Test(org.junit.Test)

Example 2 with CTDefinedNames

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

the class XSSFWorkbook method saveNamedRanges.

/**
     * marshal named ranges from the {@link #namedRanges} collection to the underlying CTWorkbook bean
     */
private void saveNamedRanges() {
    // Named ranges
    if (namedRanges.size() > 0) {
        CTDefinedNames names = CTDefinedNames.Factory.newInstance();
        CTDefinedName[] nr = new CTDefinedName[namedRanges.size()];
        int i = 0;
        for (XSSFName name : namedRanges) {
            nr[i] = name.getCTName();
            i++;
        }
        names.setDefinedNameArray(nr);
        if (workbook.isSetDefinedNames()) {
            workbook.unsetDefinedNames();
        }
        workbook.setDefinedNames(names);
        // Re-process the named ranges
        reprocessNamedRanges();
    } else {
        if (workbook.isSetDefinedNames()) {
            workbook.unsetDefinedNames();
        }
    }
}
Also used : CTDefinedName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName) CTDefinedNames(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames)

Example 3 with CTDefinedNames

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

the class XSSFWorkbook method createBuiltInName.

/**
     * Generates a NameRecord to represent a built-in region
     *
     * @return a new NameRecord
     * @throws IllegalArgumentException if sheetNumber is invalid
     * @throws POIXMLException if such a name already exists in the workbook
     */
XSSFName createBuiltInName(String builtInName, int sheetNumber) {
    validateSheetIndex(sheetNumber);
    CTDefinedNames names = workbook.getDefinedNames() == null ? workbook.addNewDefinedNames() : workbook.getDefinedNames();
    CTDefinedName nameRecord = names.addNewDefinedName();
    nameRecord.setName(builtInName);
    nameRecord.setLocalSheetId(sheetNumber);
    if (getBuiltInName(builtInName, sheetNumber) != null) {
        throw new POIXMLException("Builtin (" + builtInName + ") already exists for sheet (" + sheetNumber + ")");
    }
    return createAndStoreName(nameRecord);
}
Also used : CTDefinedName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName) POIXMLException(org.apache.poi.POIXMLException) CTDefinedNames(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames)

Aggregations

CTDefinedName (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName)3 CTDefinedNames (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames)3 POIXMLException (org.apache.poi.POIXMLException)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 Test (org.junit.Test)1