* @param sheetId the sheet Id of a sheet the formula belongs to.
* @param ref A1 style reference to the cell containing the formula.
*/
+ @SuppressWarnings("deprecation") // getXYZArray() array accessors are deprecated
public void removeItem(int sheetId, String ref){
//sheet Id of a sheet the cell belongs to
int id = -1;
- CTCalcCell[] c = new CTCalcCell[chain.getCList().size()];
- chain.getCList().toArray(c);
-
+ CTCalcCell[] c = chain.getCArray();
+
for (int i = 0; i < c.length; i++){
//If sheet Id is omitted, it is assumed to be the same as the value of the previous cell.
if(c[i].isSetI()) id = c[i].getI();
// Create the cache if needed
if(commentRefs == null) {
commentRefs = new HashMap<String, CTComment>();
- for (CTComment comment : comments.getCommentList().getCommentList()) {
+ for (CTComment comment : comments.getCommentList().getCommentArray()) {
commentRefs.put(comment.getRef(), comment);
}
}
*/
private int uniqueCount;
- public SstDocument _sstDoc;
+ private SstDocument _sstDoc;
public SharedStringsTable() {
super();
* @param is The input stream containing the XML document.
* @throws IOException if an error occurs while reading.
*/
+ @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
public void readFrom(InputStream is) throws IOException {
try {
int cnt = 0;
CTSst sst = _sstDoc.getSst();
count = (int)sst.getCount();
uniqueCount = (int)sst.getUniqueCount();
- for (CTRst st : sst.getSiList()) {
+ for (CTRst st : sst.getSiArray()) {
stmap.put(st.toString(), cnt);
strings.add(st);
cnt++;
* @param is The input stream containing the XML document.
* @throws IOException if an error occurs while reading.
*/
+ @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
protected void readFrom(InputStream is) throws IOException {
try {
doc = StyleSheetDocument.Factory.parse(is);
- // Grab all the different bits we care about
- if(doc.getStyleSheet().getNumFmts() != null)
- for (CTNumFmt nfmt : doc.getStyleSheet().getNumFmts().getNumFmtList()) {
- numberFormats.put((int)nfmt.getNumFmtId(), nfmt.getFormatCode());
- }
- if(doc.getStyleSheet().getFonts() != null){
+
+ CTStylesheet styleSheet = doc.getStyleSheet();
+
+ // Grab all the different bits we care about
+ CTNumFmts ctfmts = styleSheet.getNumFmts();
+ if( ctfmts != null){
+ for (CTNumFmt nfmt : ctfmts.getNumFmtArray()) {
+ numberFormats.put((int)nfmt.getNumFmtId(), nfmt.getFormatCode());
+ }
+ }
+
+ CTFonts ctfonts = styleSheet.getFonts();
+ if(ctfonts != null){
int idx = 0;
- for (CTFont font : doc.getStyleSheet().getFonts().getFontList()) {
+ for (CTFont font : ctfonts.getFontArray()) {
XSSFFont f = new XSSFFont(font, idx);
fonts.add(f);
idx++;
}
}
- if(doc.getStyleSheet().getFills() != null)
- for (CTFill fill : doc.getStyleSheet().getFills().getFillList()) {
- fills.add(new XSSFCellFill(fill));
- }
- if(doc.getStyleSheet().getBorders() != null)
- for (CTBorder border : doc.getStyleSheet().getBorders().getBorderList()) {
- borders.add(new XSSFCellBorder(border));
- }
- CTCellXfs cellXfs = doc.getStyleSheet().getCellXfs();
- if(cellXfs != null) xfs.addAll(cellXfs.getXfList());
+ CTFills ctfills = styleSheet.getFills();
+ if(ctfills != null){
+ for (CTFill fill : ctfills.getFillArray()) {
+ fills.add(new XSSFCellFill(fill));
+ }
+ }
+
+ CTBorders ctborders = styleSheet.getBorders();
+ if(ctborders != null) {
+ for (CTBorder border : ctborders.getBorderArray()) {
+ borders.add(new XSSFCellBorder(border));
+ }
+ }
+
+ CTCellXfs cellXfs = styleSheet.getCellXfs();
+ if(cellXfs != null) xfs.addAll(Arrays.asList(cellXfs.getXfArray()));
- CTCellStyleXfs cellStyleXfs = doc.getStyleSheet().getCellStyleXfs();
- if(cellStyleXfs != null) styleXfs.addAll(cellStyleXfs.getXfList());
+ CTCellStyleXfs cellStyleXfs = styleSheet.getCellStyleXfs();
+ if(cellStyleXfs != null) styleXfs.addAll(Arrays.asList(cellStyleXfs.getXfArray()));
- CTDxfs styleDxfs = doc.getStyleSheet().getDxfs();
- if(styleDxfs != null) dxfs.addAll(styleDxfs.getDxfList());
+ CTDxfs styleDxfs = styleSheet.getDxfs();
+ if(styleDxfs != null) dxfs.addAll(Arrays.asList(styleDxfs.getDxfArray()));
} catch (XmlException e) {
throw new IOException(e.getLocalizedMessage());
// Work on the current one
// Need to do this, as we don't handle
// all the possible entries yet
+ CTStylesheet styleSheet = doc.getStyleSheet();
// Formats
CTNumFmts formats = CTNumFmts.Factory.newInstance();
ctFmt.setNumFmtId(fmt.getKey());
ctFmt.setFormatCode(fmt.getValue());
}
- doc.getStyleSheet().setNumFmts(formats);
+ styleSheet.setNumFmts(formats);
int idx;
// Fonts
idx = 0;
for(XSSFFont f : fonts) ctfnt[idx++] = f.getCTFont();
ctFonts.setFontArray(ctfnt);
- doc.getStyleSheet().setFonts(ctFonts);
+ styleSheet.setFonts(ctFonts);
// Fills
CTFills ctFills = CTFills.Factory.newInstance();
idx = 0;
for(XSSFCellFill f : fills) ctf[idx++] = f.getCTFill();
ctFills.setFillArray(ctf);
- doc.getStyleSheet().setFills(ctFills);
+ styleSheet.setFills(ctFills);
// Borders
CTBorders ctBorders = CTBorders.Factory.newInstance();
idx = 0;
for(XSSFCellBorder b : borders) ctb[idx++] = b.getCTBorder();
ctBorders.setBorderArray(ctb);
- doc.getStyleSheet().setBorders(ctBorders);
+ styleSheet.setBorders(ctBorders);
// Xfs
if(xfs.size() > 0) {
ctXfs.setXfArray(
xfs.toArray(new CTXf[xfs.size()])
);
- doc.getStyleSheet().setCellXfs(ctXfs);
+ styleSheet.setCellXfs(ctXfs);
}
// Style xfs
ctSXfs.setXfArray(
styleXfs.toArray(new CTXf[styleXfs.size()])
);
- doc.getStyleSheet().setCellStyleXfs(ctSXfs);
+ styleSheet.setCellStyleXfs(ctSXfs);
}
// Style dxfs
ctDxfs.setCount(dxfs.size());
ctDxfs.setDxfArray(dxfs.toArray(new CTDxf[dxfs.size()])
);
- doc.getStyleSheet().setDxfs(ctDxfs);
+ styleSheet.setDxfs(ctDxfs);
}
// Save
* @param endIndex The end index to apply to font to (exclusive)
* @param font The index of the font to use.
*/
+ @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
public void applyFont(int startIndex, int endIndex, Font font) {
if (startIndex > endIndex)
throw new IllegalArgumentException("Start index must be less than end index.");
XSSFFont xssfFont = (XSSFFont)font;
ArrayList<CTRElt> runs = new ArrayList<CTRElt>();
- CTRElt[] r = new CTRElt[st.getRList().size()];
- st.getRList().toArray(r);
-
+ CTRElt[] r = st.getRArray();
int pos = 0;
for (int i = 0; i < r.length; i++) {
int rStart = pos;
return utfDecode(st.getT());
}
StringBuffer buf = new StringBuffer();
- for(CTRElt r : st.getRList()){
+ for(CTRElt r : st.getRArray()){
buf.append(r.getT());
}
return utfDecode(buf.toString());
return st;
}
+ @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
protected void setStylesTableReference(StylesTable tbl){
styles = tbl;
if(st.sizeOfRArray() > 0) {
- for (CTRElt r : st.getRList()) {
+ for (CTRElt r : st.getRArray()) {
CTRPrElt pr = r.getRPr();
if(pr != null){
String fontName = pr.getRFontArray(0).getVal();
* @param row the xml bean containing all cell definitions for this row.
* @param sheet the parent sheet.
*/
+ @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
protected XSSFRow(CTRow row, XSSFSheet sheet) {
_row = row;
_sheet = sheet;
_cells = new TreeMap<Integer, XSSFCell>();
- for (CTCell c : row.getCList()) {
+ for (CTCell c : row.getCArray()) {
XSSFCell cell = new XSSFCell(this, c);
_cells.put(cell.getColumnIndex(), cell);
sheet.onReadCell(cell);
hyperlinks = new ArrayList<XSSFHyperlink>();
}
+ @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
private void initRows(CTWorksheet worksheet) {
_rows = new TreeMap<Integer, XSSFRow>();
sharedFormulas = new HashMap<Integer, CTCellFormula>();
arrayFormulas = new ArrayList<CellRangeAddress>();
- for (CTRow row : worksheet.getSheetData().getRowList()) {
+ for (CTRow row : worksheet.getSheetData().getRowArray()) {
XSSFRow r = new XSSFRow(row, this);
_rows.put(r.getRowNum(), r);
}
getPackagePart().getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation());
// Turn each one into a XSSFHyperlink
- for(CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkList()) {
+ for(CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkArray()) {
PackageRelationship hyperRel = null;
if(hyperlink.getId() != null) {
hyperRel = hyperRels.getRelationshipByID(hyperlink.getId());
return new int[0];
}
- CTBreak[] brkArray = new CTBreak[worksheet.getColBreaks().getBrkList().size()];
- worksheet.getColBreaks().getBrkList().toArray(brkArray);
-
+ CTBreak[] brkArray = worksheet.getColBreaks().getBrkArray();
+
int[] breaks = new int[brkArray.length];
for (int i = 0 ; i < brkArray.length ; i++) {
CTBreak brk = brkArray[i];
return new int[0];
}
- CTBreak[] brkArray = new CTBreak[worksheet.getRowBreaks().getBrkList().size()];
- worksheet.getRowBreaks().getBrkList().toArray(brkArray);
-
+ CTBreak[] brkArray = worksheet.getRowBreaks().getBrkArray();
int[] breaks = new int[brkArray.length];
for (int i = 0 ; i < brkArray.length ; i++) {
CTBreak brk = brkArray[i];
}
- private short getMaxOutlineLevelCols(){
- CTCols ctCols=worksheet.getColsArray(0);
- short outlineLevel=0;
- for(CTCol col: ctCols.getColList()){
- outlineLevel=col.getOutlineLevel()>outlineLevel? col.getOutlineLevel(): outlineLevel;
+ private short getMaxOutlineLevelCols() {
+ CTCols ctCols = worksheet.getColsArray(0);
+ short outlineLevel = 0;
+ for (CTCol col : ctCols.getColArray()) {
+ outlineLevel = col.getOutlineLevel() > outlineLevel ? col.getOutlineLevel() : outlineLevel;
}
return outlineLevel;
}
* Removes a page break at the indicated column
*/
public void removeColumnBreak(int column) {
- CTBreak[] brkArray = new CTBreak[getSheetTypeColumnBreaks().getBrkList().size()];
- getSheetTypeColumnBreaks().getBrkList().toArray(brkArray);
-
+ CTBreak[] brkArray = getSheetTypeColumnBreaks().getBrkArray();
for (int i = 0 ; i < brkArray.length ; i++) {
if (brkArray[i].getId() == column) {
getSheetTypeColumnBreaks().removeBrk(i);
*/
public void removeRowBreak(int row) {
CTPageBreak pgBreak = worksheet.isSetRowBreaks() ? worksheet.getRowBreaks() : worksheet.addNewRowBreaks();
- CTBreak[] brkArray = new CTBreak[pgBreak.getBrkList().size()];
- pgBreak.getBrkList().toArray(brkArray);
+ CTBreak[] brkArray = pgBreak.getBrkArray();
for (int i = 0 ; i < brkArray.length ; i++) {
if (brkArray[i].getId() == row) {
pgBreak.removeBrk(i);
if(sheetComments != null){
//TODO shift Note's anchor in the associated /xl/drawing/vmlDrawings#.vml
CTCommentList lst = sheetComments.getCTComments().getCommentList();
- for (CTComment comment : lst.getCommentList()) {
+ for (CTComment comment : lst.getCommentArray()) {
CellReference ref = new CellReference(comment.getRef());
if(ref.getRow() == rownum){
ref = new CellReference(rownum + n, ref.getCol());
*/
public void setSelected(boolean value) {
CTSheetViews views = getSheetTypeSheetViews();
- for (CTSheetView view : views.getSheetViewList()) {
+ for (CTSheetView view : views.getSheetViewArray()) {
view.setTabSelected(value);
}
}
*/
private CTSheetView getDefaultSheetView() {
CTSheetViews views = getSheetTypeSheetViews();
- if (views == null || views.getSheetViewList() == null || views.getSheetViewList().size() <= 0) {
+ int sz = views == null ? 0 : views.sizeOfSheetViewArray();
+ if (sz == 0) {
return null;
}
- return views.getSheetViewArray(views.getSheetViewList().size() - 1);
+ return views.getSheetViewArray(sz - 1);
}
/**
protected void write(OutputStream out) throws IOException {
- if(worksheet.getColsList().size() == 1) {
+ if(worksheet.sizeOfColsArray() == 1) {
CTCols col = worksheet.getColsArray(0);
- if(col.getColList().size() == 0) {
+ if(col.sizeOfColArray() == 0) {
worksheet.setColsArray(null);
}
}
List<XSSFDataValidation> xssfValidations = new ArrayList<XSSFDataValidation>();
CTDataValidations dataValidations = this.worksheet.getDataValidations();
if( dataValidations!=null && dataValidations.getCount() > 0 ) {
- for (CTDataValidation ctDataValidation : dataValidations.getDataValidationList()) {
+ for (CTDataValidation ctDataValidation : dataValidations.getDataValidationArray()) {
CellRangeAddressList addressList = new CellRangeAddressList();
@SuppressWarnings("unchecked")
if( dataValidations==null ) {
dataValidations = worksheet.addNewDataValidations();
}
- int currentCount = dataValidations.getDataValidationList().size();
+ int currentCount = dataValidations.sizeOfDataValidationArray();
CTDataValidation newval = dataValidations.addNewDataValidation();
newval.set(xssfDataValidation.getCtDdataValidation());
dataValidations.setCount(currentCount + 1);
}
@Override
+ @SuppressWarnings("deprecation") // getXYZArray() array accessors are deprecated
protected void onDocumentRead() throws IOException {
try {
WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream());
// Load individual sheets. The order of sheets is defined by the order of CTSheet elements in the workbook
sheets = new ArrayList<XSSFSheet>(shIdMap.size());
- for (CTSheet ctSheet : this.workbook.getSheets().getSheetList()) {
+ for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
XSSFSheet sh = shIdMap.get(ctSheet.getId());
if(sh == null) {
logger.log(POILogger.WARN, "Sheet with name " + ctSheet.getName() + " and r:id " + ctSheet.getId()+ " was defined, but didn't exist in package, skipping");
// Process the named ranges
namedRanges = new ArrayList<XSSFName>();
if(workbook.isSetDefinedNames()) {
- for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameList()) {
+ for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) {
namedRanges.add(new XSSFName(ctName, this));
}
}
public void setActiveSheet(int index) {
validateSheetIndex(index);
- //activeTab (Active Sheet Index) Specifies an unsignedInt that contains the index to the active sheet in this book view.
- CTBookView[] arrayBook = new CTBookView[workbook.getBookViews().getWorkbookViewList().size()];
- workbook.getBookViews().getWorkbookViewList().toArray(arrayBook);
-
- for (int i = 0; i < arrayBook.length; i++) {
- workbook.getBookViews().getWorkbookViewArray(i).setActiveTab(index);
+
+ for (CTBookView arrayBook : workbook.getBookViews().getWorkbookViewArray()) {
+ arrayBook.setActiveTab(index);
}
}
private void saveCalculationChain(){
if(calcChain != null){
- int count = calcChain.getCTCalcChain().getCList().size();
+ int count = calcChain.getCTCalcChain().sizeOfCArray();
if(count == 0){
removeRelation(calcChain);
calcChain = null;
* @param excludeSheetIdx the sheet to exclude from the check or -1 to include all sheets in the check.
* @return true if the sheet contains the name, false otherwise.
*/
+ @SuppressWarnings("deprecation") // getXYZArray() array accessors are deprecated
private boolean containsSheet(String name, int excludeSheetIdx) {
- CTSheet[] ctSheetArray = new CTSheet[workbook.getSheets().getSheetList().size()];
- workbook.getSheets().getSheetList().toArray(ctSheetArray);
-
+ CTSheet[] ctSheetArray = workbook.getSheets().getSheetArray();
+
if (name.length() > MAX_SENSITIVE_SHEET_NAME_LEN) {
name = name.substring(0, MAX_SENSITIVE_SHEET_NAME_LEN);
}
cleanColumns();
}
+ @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
public void cleanColumns() {
this.newCols = CTCols.Factory.newInstance();
- CTCols[] colsArray = new CTCols[worksheet.getColsList().size()];
- worksheet.getColsList().toArray(colsArray);
-
+ CTCols[] colsArray = worksheet.getColsArray();
int i = 0;
for (i = 0; i < colsArray.length; i++) {
CTCols cols = colsArray[i];
- CTCol[] colArray = new CTCol[cols.getColList().size()];
- cols.getColList().toArray(colArray);
+ CTCol[] colArray = cols.getColArray();
for (int y = 0; y < colArray.length; y++) {
CTCol col = colArray[y];
newCols = addCleanColIntoCols(newCols, col);
worksheet.setColsArray(0, newCols);
}
+ @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
public static void sortColumns(CTCols newCols) {
- CTCol[] colArray = new CTCol[newCols.getColList().size()];
- newCols.getColList().toArray(colArray);
+ CTCol[] colArray = newCols.getColArray();
Arrays.sort(colArray, new CTColComparator());
newCols.setColArray(colArray);
}
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
+@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
public final class TestXSSFSheet extends BaseTestSheet {
public TestXSSFSheet() {
sheet.groupColumn(10, 11);
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
assertEquals(2, cols.sizeOfColArray());
- CTCol[] colArray = cols.getColList().toArray(new CTCol[2]);
+ CTCol[] colArray = cols.getColArray();
assertNotNull(colArray);
assertEquals(2 + 1, colArray[0].getMin()); // 1 based
assertEquals(7 + 1, colArray[0].getMax()); // 1 based
sheet.groupColumn(1, 2);
cols = sheet.getCTWorksheet().getColsArray(0);
assertEquals(4, cols.sizeOfColArray());
- colArray = cols.getColList().toArray(new CTCol[0]);
+ colArray = cols.getColArray();
assertEquals(2, colArray[1].getOutlineLevel());
//three level
sheet.groupColumn(2, 3);
cols = sheet.getCTWorksheet().getColsArray(0);
assertEquals(7, cols.sizeOfColArray());
- colArray = cols.getColList().toArray(new CTCol[0]);
+ colArray = cols.getColArray();
assertEquals(3, colArray[1].getOutlineLevel());
assertEquals(3, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol());
sheet.ungroupColumn(8, 10);
- colArray = cols.getColList().toArray(new CTCol[0]);
+ colArray = cols.getColArray();
//assertEquals(3, colArray[1].getOutlineLevel());
sheet.ungroupColumn(4, 6);
sheet.ungroupColumn(2, 2);
- colArray = cols.getColList().toArray(new CTCol[0]);
+ colArray = cols.getColArray();
assertEquals(4, colArray.length);
assertEquals(2, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol());
}
XSSFSheet xs = sheet;
CTWorksheet cts = xs.getCTWorksheet();
- CTCols[] cols_s = cts.getColsList().toArray(new CTCols[1]);
+ CTCols[] cols_s = cts.getColsArray();
assertEquals(1, cols_s.length);
CTCols cols = cols_s[0];
assertEquals(1, cols.sizeOfColArray());
// Now set another
sheet.setColumnWidth(3, 33 * 256);
- cols_s = cts.getColsList().toArray(new CTCols[1]);
+ cols_s = cts.getColsArray();
assertEquals(1, cols_s.length);
cols = cols_s[0];
assertEquals(2, cols.sizeOfColArray());
row3.createCell(5);
- CTRow[] xrow = sheetData.getRowList().toArray(new CTRow[3]);
+ CTRow[] xrow = sheetData.getRowArray();
assertEquals(3, xrow.length);
//rows are unsorted: {2, 1, 0}
assertEquals(1, xrow[2].getR());
assertTrue(xrow[2].equals(row3.getCTRow()));
- CTCell[] xcell = xrow[2].getCList().toArray(new CTCell[4]);
+ CTCell[] xcell = xrow[2].getCArray();
assertEquals("D1", xcell[0].getR());
assertEquals("A1", xcell[1].getR());
assertEquals("C1", xcell[2].getR());
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
sheet = workbook.getSheetAt(0);
wsh = sheet.getCTWorksheet();
- xrow = sheetData.getRowList().toArray(new CTRow[3]);
+ xrow = sheetData.getRowArray();
assertEquals(3, xrow.length);
//rows are sorted: {0, 1, 2}
assertEquals(4, xrow[0].sizeOfCArray());
assertEquals(1, xrow[0].getR());
//cells are now sorted
- xcell = xrow[0].getCList().toArray(new CTCell[4]);
+ xcell = xrow[0].getCArray();
assertEquals("A1", xcell[0].getR());
assertEquals("C1", xcell[1].getR());
assertEquals("D1", xcell[2].getR());