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