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();
}
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();
}
}
}
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);
}
Aggregations