Search in sources :

Example 6 with CTDefinedName

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