Selaa lähdekoodia

revert usages of getXYZList() back to getXYZArray() in XSSF, also misc performance optimizations

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1022420 13f79535-47bb-0310-9956-ffa450edef68
tags/POI-3.7
Yegor Kozlov 13 vuotta sitten
vanhempi
commit
3eea555e41

+ 3
- 3
src/ooxml/java/org/apache/poi/xssf/model/CalculationChain.java Näytä tiedosto

@@ -78,12 +78,12 @@ public class CalculationChain extends POIXMLDocumentPart {
* @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();

+ 1
- 1
src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java Näytä tiedosto

@@ -116,7 +116,7 @@ public class CommentsTable extends POIXMLDocumentPart {
// 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);
}
}

+ 3
- 2
src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java Näytä tiedosto

@@ -84,7 +84,7 @@ public class SharedStringsTable extends POIXMLDocumentPart {
*/
private int uniqueCount;

public SstDocument _sstDoc;
private SstDocument _sstDoc;

public SharedStringsTable() {
super();
@@ -103,6 +103,7 @@ public class SharedStringsTable extends POIXMLDocumentPart {
* @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;
@@ -110,7 +111,7 @@ public class SharedStringsTable extends POIXMLDocumentPart {
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++;

+ 43
- 28
src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Näytä tiedosto

@@ -106,38 +106,52 @@ public class StylesTable extends POIXMLDocumentPart {
* @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());
@@ -328,6 +342,7 @@ public class StylesTable extends POIXMLDocumentPart {
// 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();
@@ -337,7 +352,7 @@ public class StylesTable extends POIXMLDocumentPart {
ctFmt.setNumFmtId(fmt.getKey());
ctFmt.setFormatCode(fmt.getValue());
}
doc.getStyleSheet().setNumFmts(formats);
styleSheet.setNumFmts(formats);

int idx;
// Fonts
@@ -347,7 +362,7 @@ public class StylesTable extends POIXMLDocumentPart {
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();
@@ -356,7 +371,7 @@ public class StylesTable extends POIXMLDocumentPart {
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();
@@ -365,7 +380,7 @@ public class StylesTable extends POIXMLDocumentPart {
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) {
@@ -374,7 +389,7 @@ public class StylesTable extends POIXMLDocumentPart {
ctXfs.setXfArray(
xfs.toArray(new CTXf[xfs.size()])
);
doc.getStyleSheet().setCellXfs(ctXfs);
styleSheet.setCellXfs(ctXfs);
}

// Style xfs
@@ -384,7 +399,7 @@ public class StylesTable extends POIXMLDocumentPart {
ctSXfs.setXfArray(
styleXfs.toArray(new CTXf[styleXfs.size()])
);
doc.getStyleSheet().setCellStyleXfs(ctSXfs);
styleSheet.setCellStyleXfs(ctSXfs);
}

// Style dxfs
@@ -393,7 +408,7 @@ public class StylesTable extends POIXMLDocumentPart {
ctDxfs.setCount(dxfs.size());
ctDxfs.setDxfArray(dxfs.toArray(new CTDxf[dxfs.size()])
);
doc.getStyleSheet().setDxfs(ctDxfs);
styleSheet.setDxfs(ctDxfs);
}

// Save

+ 5
- 5
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java Näytä tiedosto

@@ -132,6 +132,7 @@ public class XSSFRichTextString implements RichTextString {
* @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.");
@@ -151,9 +152,7 @@ public class XSSFRichTextString implements RichTextString {
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;
@@ -345,7 +344,7 @@ public class XSSFRichTextString implements RichTextString {
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());
@@ -429,10 +428,11 @@ public class XSSFRichTextString implements RichTextString {
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();

+ 2
- 1
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java Näytä tiedosto

@@ -59,11 +59,12 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
* @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);

+ 22
- 26
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Näytä tiedosto

@@ -170,11 +170,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
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);
}
@@ -194,7 +195,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
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());
@@ -547,9 +548,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
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];
@@ -1003,9 +1003,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
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];
@@ -1179,11 +1177,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
}


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;
}
@@ -1327,9 +1325,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* 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);
@@ -1385,8 +1381,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/
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);
@@ -2159,7 +2154,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
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());
@@ -2285,7 +2280,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/
public void setSelected(boolean value) {
CTSheetViews views = getSheetTypeSheetViews();
for (CTSheetView view : views.getSheetViewList()) {
for (CTSheetView view : views.getSheetViewArray()) {
view.setTabSelected(value);
}
}
@@ -2361,10 +2356,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/
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);
}

/**
@@ -2438,9 +2434,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {

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);
}
}
@@ -2895,7 +2891,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
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")
@@ -2923,7 +2919,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
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);

+ 10
- 12
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Näytä tiedosto

@@ -199,6 +199,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
}

@Override
@SuppressWarnings("deprecation") // getXYZArray() array accessors are deprecated
protected void onDocumentRead() throws IOException {
try {
WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream());
@@ -224,7 +225,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X

// 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");
@@ -238,7 +239,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
// 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));
}
}
@@ -881,12 +882,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
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);
}
}

@@ -1163,7 +1161,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X

private void saveCalculationChain(){
if(calcChain != null){
int count = calcChain.getCTCalcChain().getCList().size();
int count = calcChain.getCTCalcChain().sizeOfCArray();
if(count == 0){
removeRelation(calcChain);
calcChain = null;
@@ -1230,10 +1228,10 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
* @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);
}

+ 5
- 7
src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java Näytä tiedosto

@@ -53,16 +53,14 @@ public class ColumnHelper {
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);
@@ -75,9 +73,9 @@ public class ColumnHelper {
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);
}

+ 12
- 11
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Näytä tiedosto

@@ -29,6 +29,7 @@ import org.apache.poi.hssf.record.PasswordRecord;
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() {
@@ -291,7 +292,7 @@ public final class TestXSSFSheet extends BaseTestSheet {
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
@@ -301,7 +302,7 @@ public final class TestXSSFSheet extends BaseTestSheet {
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
@@ -309,17 +310,17 @@ public final class TestXSSFSheet extends BaseTestSheet {
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());
}
@@ -701,7 +702,7 @@ public final class TestXSSFSheet extends BaseTestSheet {
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());
@@ -716,7 +717,7 @@ public final class TestXSSFSheet extends BaseTestSheet {
// 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());
@@ -922,7 +923,7 @@ public final class TestXSSFSheet extends BaseTestSheet {
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}
@@ -938,7 +939,7 @@ public final class TestXSSFSheet extends BaseTestSheet {
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());
@@ -954,14 +955,14 @@ public final class TestXSSFSheet extends BaseTestSheet {
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());

Loading…
Peruuta
Tallenna