Search in sources :

Example 1 with CTDefinedName

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName 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 CTDefinedName

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName 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 CTDefinedName

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

the class XSSFWorkbook method createName.

@Override
public XSSFName createName() {
    CTDefinedName ctName = CTDefinedName.Factory.newInstance();
    ctName.setName("");
    return createAndStoreName(ctName);
}
Also used : CTDefinedName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName)

Example 4 with CTDefinedName

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

the class XSSFWorkbook method reprocessNamedRanges.

private void reprocessNamedRanges() {
    namedRangesByName = new ArrayListValuedHashMap<String, XSSFName>();
    namedRanges = new ArrayList<XSSFName>();
    if (workbook.isSetDefinedNames()) {
        for (CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) {
            createAndStoreName(ctName);
        }
    }
}
Also used : CTDefinedName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName)

Example 5 with CTDefinedName

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

the class XSSFWorkbook method onSheetDelete.

/**
     * Gracefully remove references to the sheet being deleted
     *
     * @param index the 0-based index of the sheet to delete
     */
private void onSheetDelete(int index) {
    //delete the CTSheet reference from workbook.xml
    workbook.getSheets().removeSheet(index);
    //calculation chain is auxiliary, remove it as it may contain orphan references to deleted cells
    if (calcChain != null) {
        removeRelation(calcChain);
        calcChain = null;
    }
    //adjust indices of names ranges
    List<XSSFName> toRemove = new ArrayList<XSSFName>();
    for (XSSFName nm : namedRanges) {
        CTDefinedName ct = nm.getCTName();
        if (!ct.isSetLocalSheetId()) {
            continue;
        }
        if (ct.getLocalSheetId() == index) {
            toRemove.add(nm);
        } else if (ct.getLocalSheetId() > index) {
            // Bump down by one, so still points at the same sheet
            ct.setLocalSheetId(ct.getLocalSheetId() - 1);
        }
    }
    for (XSSFName nm : toRemove) {
        removeName(nm);
    }
}
Also used : ArrayList(java.util.ArrayList) CTDefinedName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName)

Aggregations

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