Bug 56854 - XMLBeans performance when using getXXXList() and other proxy methods
+ modification to XSSFSheet.removeMergedRegion git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1624922 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
21046dc43a
commit
21f01ab737
@ -98,9 +98,11 @@ public class CommentsTable extends POIXMLDocumentPart {
|
|||||||
return comments.getAuthors().getAuthorArray((int)authorId);
|
return comments.getAuthors().getAuthorArray((int)authorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public int findAuthor(String author) {
|
public int findAuthor(String author) {
|
||||||
for (int i = 0 ; i < comments.getAuthors().sizeOfAuthorArray() ; i++) {
|
String[] authorArray = comments.getAuthors().getAuthorArray();
|
||||||
if (comments.getAuthors().getAuthorArray(i).equals(author)) {
|
for (int i = 0 ; i < authorArray.length; i++) {
|
||||||
|
if (authorArray[i].equals(author)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,9 +152,9 @@ public class CommentsTable extends POIXMLDocumentPart {
|
|||||||
public boolean removeComment(String cellRef) {
|
public boolean removeComment(String cellRef) {
|
||||||
CTCommentList lst = comments.getCommentList();
|
CTCommentList lst = comments.getCommentList();
|
||||||
if(lst != null) {
|
if(lst != null) {
|
||||||
int commentCount = lst.sizeOfCommentArray();
|
CTComment[] commentArray = lst.getCommentArray();
|
||||||
for(int i=0; i < commentCount; i++) {
|
for (int i = 0; i < commentArray.length; i++) {
|
||||||
CTComment comment = lst.getCommentArray(i);
|
CTComment comment = commentArray[i];
|
||||||
if (cellRef.equals(comment.getRef())) {
|
if (cellRef.equals(comment.getRef())) {
|
||||||
lst.removeComment(i);
|
lst.removeComment(i);
|
||||||
|
|
||||||
|
@ -439,16 +439,18 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
|
|||||||
*
|
*
|
||||||
* @see org.apache.poi.xssf.usermodel.XSSFSheet#write(java.io.OutputStream) ()
|
* @see org.apache.poi.xssf.usermodel.XSSFSheet#write(java.io.OutputStream) ()
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
protected void onDocumentWrite(){
|
protected void onDocumentWrite(){
|
||||||
// check if cells in the CTRow are ordered
|
// check if cells in the CTRow are ordered
|
||||||
boolean isOrdered = true;
|
boolean isOrdered = true;
|
||||||
if(_row.sizeOfCArray() != _cells.size()) {
|
CTCell[] cArray = _row.getCArray();
|
||||||
|
if (cArray.length != _cells.size()) {
|
||||||
isOrdered = false;
|
isOrdered = false;
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (XSSFCell cell : _cells.values()) {
|
for (XSSFCell cell : _cells.values()) {
|
||||||
CTCell c1 = cell.getCTCell();
|
CTCell c1 = cell.getCTCell();
|
||||||
CTCell c2 = _row.getCArray(i++);
|
CTCell c2 = cArray[i++];
|
||||||
|
|
||||||
String r1 = c1.getR();
|
String r1 = c1.getR();
|
||||||
String r2 = c2.getR();
|
String r2 = c2.getR();
|
||||||
@ -460,17 +462,17 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!isOrdered){
|
if(!isOrdered){
|
||||||
CTCell[] cArray = new CTCell[_cells.size()];
|
cArray = new CTCell[_cells.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Map.Entry<Integer, XSSFCell> entry : _cells.entrySet()) {
|
for (XSSFCell xssfCell : _cells.values()) {
|
||||||
cArray[i] = (CTCell) entry.getValue().getCTCell().copy();
|
cArray[i] = (CTCell) xssfCell.getCTCell().copy();
|
||||||
|
|
||||||
// we have to copy and re-create the XSSFCell here because the
|
// we have to copy and re-create the XSSFCell here because the
|
||||||
// elements as otherwise setCArray below invalidates all the columns!
|
// elements as otherwise setCArray below invalidates all the columns!
|
||||||
// see Bug 56170, XMLBeans seems to always release previous objects
|
// see Bug 56170, XMLBeans seems to always release previous objects
|
||||||
// in the CArray, so we need to provide completely new ones here!
|
// in the CArray, so we need to provide completely new ones here!
|
||||||
//_cells.put(entry.getKey(), new XSSFCell(this, cArray[i]));
|
//_cells.put(entry.getKey(), new XSSFCell(this, cArray[i]));
|
||||||
entry.getValue().setCTCell(cArray[i]);
|
xssfCell.setCTCell(cArray[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,16 @@ import org.apache.poi.poifs.crypt.HashAlgorithm;
|
|||||||
import org.apache.poi.ss.SpreadsheetVersion;
|
import org.apache.poi.ss.SpreadsheetVersion;
|
||||||
import org.apache.poi.ss.formula.FormulaShifter;
|
import org.apache.poi.ss.formula.FormulaShifter;
|
||||||
import org.apache.poi.ss.formula.SheetNameFormatter;
|
import org.apache.poi.ss.formula.SheetNameFormatter;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.CellRange;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.DataValidation;
|
||||||
|
import org.apache.poi.ss.usermodel.DataValidationHelper;
|
||||||
|
import org.apache.poi.ss.usermodel.Footer;
|
||||||
|
import org.apache.poi.ss.usermodel.Header;
|
||||||
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.util.AreaReference;
|
import org.apache.poi.ss.util.AreaReference;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||||
@ -64,7 +73,47 @@ import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
|
|||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAutoFilter;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidation;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidations;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDrawing;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHyperlink;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTLegacyDrawing;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCell;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCells;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOutlinePr;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPane;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPrintOptions;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetCalcPr;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTablePart;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableParts;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCalcMode;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPaneState;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* High level representation of a SpreadsheetML worksheet.
|
* High level representation of a SpreadsheetML worksheet.
|
||||||
@ -602,6 +651,28 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private int[] getBreaks(CTPageBreak ctPageBreak) {
|
||||||
|
CTBreak[] brkArray = ctPageBreak.getBrkArray();
|
||||||
|
int[] breaks = new int[brkArray.length];
|
||||||
|
for (int i = 0 ; i < brkArray.length ; i++) {
|
||||||
|
breaks[i] = (int) brkArray[i].getId() - 1;
|
||||||
|
}
|
||||||
|
return breaks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private void removeBreak(int index, CTPageBreak ctPageBreak) {
|
||||||
|
int index1 = index + 1;
|
||||||
|
CTBreak[] brkArray = ctPageBreak.getBrkArray();
|
||||||
|
for (int i = 0 ; i < brkArray.length ; i++) {
|
||||||
|
if (brkArray[i].getId() == index1) {
|
||||||
|
ctPageBreak.removeBrk(i);
|
||||||
|
// TODO: check if we can break here, i.e. if a page can have more than 1 break on the same id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vertical page break information used for print layout view, page layout view, drawing print breaks
|
* Vertical page break information used for print layout view, page layout view, drawing print breaks
|
||||||
* in normal view, and for printing the worksheet.
|
* in normal view, and for printing the worksheet.
|
||||||
@ -609,20 +680,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* @return column indexes of all the vertical page breaks, never <code>null</code>
|
* @return column indexes of all the vertical page breaks, never <code>null</code>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
|
|
||||||
public int[] getColumnBreaks() {
|
public int[] getColumnBreaks() {
|
||||||
if (!worksheet.isSetColBreaks() || worksheet.getColBreaks().sizeOfBrkArray() == 0) {
|
return worksheet.isSetColBreaks() ? getBreaks(worksheet.getColBreaks()) : new int[0];
|
||||||
return new int[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
CTBreak[] brkArray = worksheet.getColBreaks().getBrkArray();
|
|
||||||
|
|
||||||
int[] breaks = new int[brkArray.length];
|
|
||||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
|
||||||
CTBreak brk = brkArray[i];
|
|
||||||
breaks[i] = (int)brk.getId() - 1;
|
|
||||||
}
|
|
||||||
return breaks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -705,8 +764,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* @param value true for right to left, false otherwise.
|
* @param value true for right to left, false otherwise.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setRightToLeft(boolean value)
|
public void setRightToLeft(boolean value) {
|
||||||
{
|
|
||||||
CTSheetView view = getDefaultSheetView();
|
CTSheetView view = getDefaultSheetView();
|
||||||
view.setRightToLeft(value);
|
view.setRightToLeft(value);
|
||||||
}
|
}
|
||||||
@ -717,10 +775,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* @return whether the text is displayed in right-to-left mode in the window
|
* @return whether the text is displayed in right-to-left mode in the window
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isRightToLeft()
|
public boolean isRightToLeft() {
|
||||||
{
|
|
||||||
CTSheetView view = getDefaultSheetView();
|
CTSheetView view = getDefaultSheetView();
|
||||||
return view == null ? false : view.getRightToLeft();
|
return view != null && view.getRightToLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -757,7 +814,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isDisplayZeros(){
|
public boolean isDisplayZeros(){
|
||||||
CTSheetView view = getDefaultSheetView();
|
CTSheetView view = getDefaultSheetView();
|
||||||
return view == null ? true : view.getShowZeros();
|
return view == null || view.getShowZeros();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -779,7 +836,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getFirstRowNum() {
|
public int getFirstRowNum() {
|
||||||
return _rows.size() == 0 ? 0 : _rows.firstKey();
|
return _rows.isEmpty() ? 0 : _rows.firstKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -897,7 +954,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLastRowNum() {
|
public int getLastRowNum() {
|
||||||
return _rows.size() == 0 ? 0 : _rows.lastKey();
|
return _rows.isEmpty() ? 0 : _rows.lastKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1032,9 +1089,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of phsyically defined rows (NOT the number of rows in the sheet)
|
* Returns the number of physically defined rows (NOT the number of rows in the sheet)
|
||||||
*
|
*
|
||||||
* @return the number of phsyically defined rows
|
* @return the number of physically defined rows
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getPhysicalNumberOfRows() {
|
public int getPhysicalNumberOfRows() {
|
||||||
@ -1122,19 +1179,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* @return row indexes of all the horizontal page breaks, never <code>null</code>
|
* @return row indexes of all the horizontal page breaks, never <code>null</code>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
|
|
||||||
public int[] getRowBreaks() {
|
public int[] getRowBreaks() {
|
||||||
if (!worksheet.isSetRowBreaks() || worksheet.getRowBreaks().sizeOfBrkArray() == 0) {
|
return worksheet.isSetRowBreaks() ? getBreaks(worksheet.getRowBreaks()) : new int[0];
|
||||||
return new int[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
CTBreak[] brkArray = worksheet.getRowBreaks().getBrkArray();
|
|
||||||
int[] breaks = new int[brkArray.length];
|
|
||||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
|
||||||
CTBreak brk = brkArray[i];
|
|
||||||
breaks[i] = (int)brk.getId() - 1;
|
|
||||||
}
|
|
||||||
return breaks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1334,22 +1381,22 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private short getMaxOutlineLevelRows(){
|
private short getMaxOutlineLevelRows(){
|
||||||
short outlineLevel=0;
|
int outlineLevel = 0;
|
||||||
for (XSSFRow xrow : _rows.values()) {
|
for (XSSFRow xrow : _rows.values()) {
|
||||||
outlineLevel=xrow.getCTRow().getOutlineLevel()>outlineLevel? xrow.getCTRow().getOutlineLevel(): outlineLevel;
|
outlineLevel = Math.max(outlineLevel, xrow.getCTRow().getOutlineLevel());
|
||||||
}
|
}
|
||||||
return outlineLevel;
|
return (short) outlineLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private short getMaxOutlineLevelCols() {
|
private short getMaxOutlineLevelCols() {
|
||||||
CTCols ctCols = worksheet.getColsArray(0);
|
CTCols ctCols = worksheet.getColsArray(0);
|
||||||
short outlineLevel = 0;
|
int outlineLevel = 0;
|
||||||
for (CTCol col : ctCols.getColArray()) {
|
for (CTCol col : ctCols.getColArray()) {
|
||||||
outlineLevel = col.getOutlineLevel() > outlineLevel ? col.getOutlineLevel() : outlineLevel;
|
outlineLevel = Math.max(outlineLevel, col.getOutlineLevel());
|
||||||
}
|
}
|
||||||
return outlineLevel;
|
return (short) outlineLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1357,8 +1404,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isColumnBroken(int column) {
|
public boolean isColumnBroken(int column) {
|
||||||
int[] colBreaks = getColumnBreaks();
|
for (int colBreak : getColumnBreaks()) {
|
||||||
for (int colBreak : colBreaks) {
|
|
||||||
if (colBreak == column) {
|
if (colBreak == column) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1477,8 +1523,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isRowBroken(int row) {
|
public boolean isRowBroken(int row) {
|
||||||
int[] rowBreaks = getRowBreaks();
|
for (int rowBreak : getRowBreaks()) {
|
||||||
for (int rowBreak : rowBreaks) {
|
|
||||||
if (rowBreak == row) {
|
if (rowBreak == row) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1486,6 +1531,17 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setBreak(int id, CTPageBreak ctPgBreak, int lastIndex) {
|
||||||
|
CTBreak brk = ctPgBreak.addNewBrk();
|
||||||
|
brk.setId(id + 1); // this is id of the element which is 1-based: <row r="1" ... >
|
||||||
|
brk.setMan(true);
|
||||||
|
brk.setMax(lastIndex); //end column of the break
|
||||||
|
|
||||||
|
int nPageBreaks = ctPgBreak.sizeOfBrkArray();
|
||||||
|
ctPgBreak.setCount(nPageBreaks);
|
||||||
|
ctPgBreak.setManualBreakCount(nPageBreaks);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a page break at the indicated row
|
* Sets a page break at the indicated row
|
||||||
* Breaks occur above the specified row and left of the specified column inclusive.
|
* Breaks occur above the specified row and left of the specified column inclusive.
|
||||||
@ -1499,15 +1555,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setRowBreak(int row) {
|
public void setRowBreak(int row) {
|
||||||
CTPageBreak pgBreak = worksheet.isSetRowBreaks() ? worksheet.getRowBreaks() : worksheet.addNewRowBreaks();
|
|
||||||
if (!isRowBroken(row)) {
|
if (!isRowBroken(row)) {
|
||||||
CTBreak brk = pgBreak.addNewBrk();
|
CTPageBreak pgBreak = worksheet.isSetRowBreaks() ? worksheet.getRowBreaks() : worksheet.addNewRowBreaks();
|
||||||
brk.setId(row + 1); // this is id of the row element which is 1-based: <row r="1" ... >
|
setBreak(row, pgBreak, SpreadsheetVersion.EXCEL2007.getLastColumnIndex());
|
||||||
brk.setMan(true);
|
|
||||||
brk.setMax(SpreadsheetVersion.EXCEL2007.getLastColumnIndex()); //end column of the break
|
|
||||||
|
|
||||||
pgBreak.setCount(pgBreak.sizeOfBrkArray());
|
|
||||||
pgBreak.setManualBreakCount(pgBreak.sizeOfBrkArray());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1515,20 +1565,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* Removes a page break at the indicated column
|
* Removes a page break at the indicated column
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
|
|
||||||
public void removeColumnBreak(int column) {
|
public void removeColumnBreak(int column) {
|
||||||
if (!worksheet.isSetColBreaks()) {
|
if (worksheet.isSetColBreaks()) {
|
||||||
// no breaks
|
removeBreak(column, worksheet.getColBreaks());
|
||||||
return;
|
} // else no breaks
|
||||||
}
|
|
||||||
|
|
||||||
CTPageBreak pgBreak = worksheet.getColBreaks();
|
|
||||||
CTBreak[] brkArray = pgBreak.getBrkArray();
|
|
||||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
|
||||||
if (brkArray[i].getId() == (column + 1)) {
|
|
||||||
pgBreak.removeBrk(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1537,21 +1577,15 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* @param index of the region to unmerge
|
* @param index of the region to unmerge
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void removeMergedRegion(int index) {
|
public void removeMergedRegion(int index) {
|
||||||
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
if (!worksheet.isSetMergeCells()) return;
|
||||||
|
|
||||||
|
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
||||||
int size = ctMergeCells.sizeOfMergeCellArray();
|
int size = ctMergeCells.sizeOfMergeCellArray();
|
||||||
CTMergeCell[] mergeCellsArray = new CTMergeCell[size - 1];
|
assert(0 <= index && index < size);
|
||||||
for (int i = 0 ; i < size ; i++) {
|
if (size > 1) {
|
||||||
if (i < index) {
|
ctMergeCells.removeMergeCell(index);
|
||||||
mergeCellsArray[i] = ctMergeCells.getMergeCellArray(i);
|
|
||||||
}
|
|
||||||
else if (i > index) {
|
|
||||||
mergeCellsArray[i - 1] = ctMergeCells.getMergeCellArray(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(mergeCellsArray.length > 0){
|
|
||||||
ctMergeCells.setMergeCellArray(mergeCellsArray);
|
|
||||||
} else {
|
} else {
|
||||||
worksheet.unsetMergeCells();
|
worksheet.unsetMergeCells();
|
||||||
}
|
}
|
||||||
@ -1566,21 +1600,23 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
*
|
*
|
||||||
* @param indices A set of the regions to unmerge
|
* @param indices A set of the regions to unmerge
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void removeMergedRegions(Set<Integer> indices) {
|
public void removeMergedRegions(Set<Integer> indices) {
|
||||||
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
if (!worksheet.isSetMergeCells()) return;
|
||||||
|
|
||||||
int size = ctMergeCells.sizeOfMergeCellArray();
|
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
||||||
CTMergeCell[] mergeCellsArray = new CTMergeCell[size - indices.size()];
|
List<CTMergeCell> newMergeCells = new ArrayList<CTMergeCell>(ctMergeCells.sizeOfMergeCellArray());
|
||||||
for (int i = 0, d = 0 ; i < size ; i++) {
|
|
||||||
if(!indices.contains(i)) {
|
int idx = 0;
|
||||||
mergeCellsArray[d] = ctMergeCells.getMergeCellArray(i);
|
for (CTMergeCell mc : ctMergeCells.getMergeCellArray()) {
|
||||||
d++;
|
if (!indices.contains(idx++)) newMergeCells.add(mc);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(mergeCellsArray.length > 0){
|
if (newMergeCells.isEmpty()) {
|
||||||
ctMergeCells.setMergeCellArray(mergeCellsArray);
|
|
||||||
} else{
|
|
||||||
worksheet.unsetMergeCells();
|
worksheet.unsetMergeCells();
|
||||||
|
} else{
|
||||||
|
CTMergeCell[] newMergeCellsArray = new CTMergeCell[newMergeCells.size()];
|
||||||
|
ctMergeCells.setMergeCellArray(newMergeCells.toArray(newMergeCellsArray));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1609,18 +1645,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* Removes the page break at the indicated row
|
* Removes the page break at the indicated row
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
|
|
||||||
public void removeRowBreak(int row) {
|
public void removeRowBreak(int row) {
|
||||||
if(!worksheet.isSetRowBreaks()) {
|
if (worksheet.isSetRowBreaks()) {
|
||||||
return;
|
removeBreak(row, worksheet.getRowBreaks());
|
||||||
}
|
} // else no breaks
|
||||||
CTPageBreak pgBreak = worksheet.getRowBreaks();
|
|
||||||
CTBreak[] brkArray = pgBreak.getBrkArray();
|
|
||||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
|
||||||
if (brkArray[i].getId() == (row + 1)) {
|
|
||||||
pgBreak.removeBrk(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1736,13 +1764,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
public void setColumnBreak(int column) {
|
public void setColumnBreak(int column) {
|
||||||
if (!isColumnBroken(column)) {
|
if (!isColumnBroken(column)) {
|
||||||
CTPageBreak pgBreak = worksheet.isSetColBreaks() ? worksheet.getColBreaks() : worksheet.addNewColBreaks();
|
CTPageBreak pgBreak = worksheet.isSetColBreaks() ? worksheet.getColBreaks() : worksheet.addNewColBreaks();
|
||||||
CTBreak brk = pgBreak.addNewBrk();
|
setBreak(column, pgBreak, SpreadsheetVersion.EXCEL2007.getLastRowIndex());
|
||||||
brk.setId(column + 1); // this is id of the row element which is 1-based: <row r="1" ... >
|
|
||||||
brk.setMan(true);
|
|
||||||
brk.setMax(SpreadsheetVersion.EXCEL2007.getLastRowIndex()); //end row of the break
|
|
||||||
|
|
||||||
pgBreak.setCount(pgBreak.sizeOfBrkArray());
|
|
||||||
pgBreak.setManualBreakCount(pgBreak.sizeOfBrkArray());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1772,23 +1794,23 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
.getOutlineLevel(), true);
|
.getOutlineLevel(), true);
|
||||||
|
|
||||||
// write collapse field
|
// write collapse field
|
||||||
setColumn(lastColMax + 1, null, 0, null, null, Boolean.TRUE);
|
setColumn(lastColMax + 1, 0, null, null, Boolean.TRUE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setColumn(int targetColumnIx, Short xfIndex, Integer style,
|
@SuppressWarnings("deprecation")
|
||||||
|
private void setColumn(int targetColumnIx, Integer style,
|
||||||
Integer level, Boolean hidden, Boolean collapsed) {
|
Integer level, Boolean hidden, Boolean collapsed) {
|
||||||
CTCols cols = worksheet.getColsArray(0);
|
CTCols cols = worksheet.getColsArray(0);
|
||||||
CTCol ci = null;
|
CTCol ci = null;
|
||||||
int k = 0;
|
for (CTCol tci : cols.getColArray()) {
|
||||||
for (k = 0; k < cols.sizeOfColArray(); k++) {
|
long tciMin = tci.getMin();
|
||||||
CTCol tci = cols.getColArray(k);
|
long tciMax = tci.getMax();
|
||||||
if (tci.getMin() >= targetColumnIx
|
if (tciMin >= targetColumnIx && tciMax <= targetColumnIx) {
|
||||||
&& tci.getMax() <= targetColumnIx) {
|
|
||||||
ci = tci;
|
ci = tci;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (tci.getMin() > targetColumnIx) {
|
if (tciMin > targetColumnIx) {
|
||||||
// call column infos after k are for later columns
|
// call column infos after k are for later columns
|
||||||
break; // exit now so k will be the correct insert pos
|
break; // exit now so k will be the correct insert pos
|
||||||
}
|
}
|
||||||
@ -1805,36 +1827,32 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean styleChanged = style != null
|
boolean styleChanged = style != null && ci.getStyle() != style;
|
||||||
&& ci.getStyle() != style;
|
boolean levelChanged = level != null && ci.getOutlineLevel() != level;
|
||||||
boolean levelChanged = level != null
|
boolean hiddenChanged = hidden != null && ci.getHidden() != hidden;
|
||||||
&& ci.getOutlineLevel() != level;
|
boolean collapsedChanged = collapsed != null && ci.getCollapsed() != collapsed;
|
||||||
boolean hiddenChanged = hidden != null
|
boolean columnChanged = levelChanged || hiddenChanged || collapsedChanged || styleChanged;
|
||||||
&& ci.getHidden() != hidden;
|
|
||||||
boolean collapsedChanged = collapsed != null
|
|
||||||
&& ci.getCollapsed() != collapsed;
|
|
||||||
boolean columnChanged = levelChanged || hiddenChanged
|
|
||||||
|| collapsedChanged || styleChanged;
|
|
||||||
if (!columnChanged) {
|
if (!columnChanged) {
|
||||||
// do nothing...nothing changed.
|
// do nothing...nothing changed.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ci.getMin() == targetColumnIx && ci.getMax() == targetColumnIx) {
|
long ciMin = ci.getMin();
|
||||||
|
long ciMax = ci.getMax();
|
||||||
|
if (ciMin == targetColumnIx && ciMax == targetColumnIx) {
|
||||||
// ColumnInfo ci for a single column, the target column
|
// ColumnInfo ci for a single column, the target column
|
||||||
unsetCollapsed(collapsed, ci);
|
unsetCollapsed(collapsed, ci);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ci.getMin() == targetColumnIx || ci.getMax() == targetColumnIx) {
|
if (ciMin == targetColumnIx || ciMax == targetColumnIx) {
|
||||||
// The target column is at either end of the multi-column ColumnInfo
|
// The target column is at either end of the multi-column ColumnInfo
|
||||||
// ci
|
// ci
|
||||||
// we'll just divide the info and create a new one
|
// we'll just divide the info and create a new one
|
||||||
if (ci.getMin() == targetColumnIx) {
|
if (ciMin == targetColumnIx) {
|
||||||
ci.setMin(targetColumnIx + 1);
|
ci.setMin(targetColumnIx + 1);
|
||||||
} else {
|
} else {
|
||||||
ci.setMax(targetColumnIx - 1);
|
ci.setMax(targetColumnIx - 1);
|
||||||
k++; // adjust insert pos to insert after
|
|
||||||
}
|
}
|
||||||
CTCol nci = columnHelper.cloneCol(cols, ci);
|
CTCol nci = columnHelper.cloneCol(cols, ci);
|
||||||
nci.setMin(targetColumnIx);
|
nci.setMin(targetColumnIx);
|
||||||
@ -1843,12 +1861,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// split to 3 records
|
// split to 3 records
|
||||||
CTCol ciStart = ci;
|
|
||||||
CTCol ciMid = columnHelper.cloneCol(cols, ci);
|
CTCol ciMid = columnHelper.cloneCol(cols, ci);
|
||||||
CTCol ciEnd = columnHelper.cloneCol(cols, ci);
|
CTCol ciEnd = columnHelper.cloneCol(cols, ci);
|
||||||
int lastcolumn = (int) ci.getMax();
|
int lastcolumn = (int) ciMax;
|
||||||
|
|
||||||
ciStart.setMax(targetColumnIx - 1);
|
ci.setMax(targetColumnIx - 1);
|
||||||
|
|
||||||
ciMid.setMin(targetColumnIx);
|
ciMid.setMin(targetColumnIx);
|
||||||
ciMid.setMax(targetColumnIx);
|
ciMid.setMax(targetColumnIx);
|
||||||
@ -1877,14 +1894,16 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* the col info index of the start of the outline group
|
* the col info index of the start of the outline group
|
||||||
* @return the column index of the last column in the outline group
|
* @return the column index of the last column in the outline group
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private int setGroupHidden(int pIdx, int level, boolean hidden) {
|
private int setGroupHidden(int pIdx, int level, boolean hidden) {
|
||||||
CTCols cols = worksheet.getColsArray(0);
|
CTCols cols = worksheet.getColsArray(0);
|
||||||
int idx = pIdx;
|
int idx = pIdx;
|
||||||
CTCol columnInfo = cols.getColArray(idx);
|
CTCol[] colArray = cols.getColArray();
|
||||||
while (idx < cols.sizeOfColArray()) {
|
CTCol columnInfo = colArray[idx];
|
||||||
|
while (idx < colArray.length) {
|
||||||
columnInfo.setHidden(hidden);
|
columnInfo.setHidden(hidden);
|
||||||
if (idx + 1 < cols.sizeOfColArray()) {
|
if (idx + 1 < colArray.length) {
|
||||||
CTCol nextColumnInfo = cols.getColArray(idx + 1);
|
CTCol nextColumnInfo = colArray[idx + 1];
|
||||||
|
|
||||||
if (!isAdjacentBefore(columnInfo, nextColumnInfo)) {
|
if (!isAdjacentBefore(columnInfo, nextColumnInfo)) {
|
||||||
break;
|
break;
|
||||||
@ -1901,17 +1920,19 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAdjacentBefore(CTCol col, CTCol other_col) {
|
private boolean isAdjacentBefore(CTCol col, CTCol other_col) {
|
||||||
return (col.getMax() == (other_col.getMin() - 1));
|
return col.getMax() == other_col.getMin() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private int findStartOfColumnOutlineGroup(int pIdx) {
|
private int findStartOfColumnOutlineGroup(int pIdx) {
|
||||||
// Find the start of the group.
|
// Find the start of the group.
|
||||||
CTCols cols = worksheet.getColsArray(0);
|
CTCols cols = worksheet.getColsArray(0);
|
||||||
CTCol columnInfo = cols.getColArray(pIdx);
|
CTCol[] colArray = cols.getColArray();
|
||||||
|
CTCol columnInfo = colArray[pIdx];
|
||||||
int level = columnInfo.getOutlineLevel();
|
int level = columnInfo.getOutlineLevel();
|
||||||
int idx = pIdx;
|
int idx = pIdx;
|
||||||
while (idx != 0) {
|
while (idx != 0) {
|
||||||
CTCol prevColumnInfo = cols.getColArray(idx - 1);
|
CTCol prevColumnInfo = colArray[idx - 1];
|
||||||
if (!isAdjacentBefore(prevColumnInfo, columnInfo)) {
|
if (!isAdjacentBefore(prevColumnInfo, columnInfo)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1924,14 +1945,17 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private int findEndOfColumnOutlineGroup(int colInfoIndex) {
|
private int findEndOfColumnOutlineGroup(int colInfoIndex) {
|
||||||
CTCols cols = worksheet.getColsArray(0);
|
CTCols cols = worksheet.getColsArray(0);
|
||||||
// Find the end of the group.
|
// Find the end of the group.
|
||||||
CTCol columnInfo = cols.getColArray(colInfoIndex);
|
CTCol[] colArray = cols.getColArray();
|
||||||
|
CTCol columnInfo = colArray[colInfoIndex];
|
||||||
int level = columnInfo.getOutlineLevel();
|
int level = columnInfo.getOutlineLevel();
|
||||||
int idx = colInfoIndex;
|
int idx = colInfoIndex;
|
||||||
while (idx < cols.sizeOfColArray() - 1) {
|
int lastIdx = colArray.length - 1;
|
||||||
CTCol nextColumnInfo = cols.getColArray(idx + 1);
|
while (idx < lastIdx) {
|
||||||
|
CTCol nextColumnInfo = colArray[idx + 1];
|
||||||
if (!isAdjacentBefore(columnInfo, nextColumnInfo)) {
|
if (!isAdjacentBefore(columnInfo, nextColumnInfo)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1944,6 +1968,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private void expandColumn(int columnIndex) {
|
private void expandColumn(int columnIndex) {
|
||||||
CTCols cols = worksheet.getColsArray(0);
|
CTCols cols = worksheet.getColsArray(0);
|
||||||
CTCol col = columnHelper.getColumn(columnIndex, false);
|
CTCol col = columnHelper.getColumn(columnIndex, false);
|
||||||
@ -1974,12 +1999,13 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
// is the enclosing group
|
// is the enclosing group
|
||||||
// hidden bit only is altered for this outline level. ie. don't
|
// hidden bit only is altered for this outline level. ie. don't
|
||||||
// uncollapse contained groups
|
// uncollapse contained groups
|
||||||
CTCol columnInfo = cols.getColArray(endIdx);
|
CTCol[] colArray = cols.getColArray();
|
||||||
|
CTCol columnInfo = colArray[endIdx];
|
||||||
if (!isColumnGroupHiddenByParent(idx)) {
|
if (!isColumnGroupHiddenByParent(idx)) {
|
||||||
int outlineLevel = columnInfo.getOutlineLevel();
|
short outlineLevel = columnInfo.getOutlineLevel();
|
||||||
boolean nestedGroup = false;
|
boolean nestedGroup = false;
|
||||||
for (int i = startIdx; i <= endIdx; i++) {
|
for (int i = startIdx; i <= endIdx; i++) {
|
||||||
CTCol ci = cols.getColArray(i);
|
CTCol ci = colArray[i];
|
||||||
if (outlineLevel == ci.getOutlineLevel()) {
|
if (outlineLevel == ci.getOutlineLevel()) {
|
||||||
ci.unsetHidden();
|
ci.unsetHidden();
|
||||||
if (nestedGroup) {
|
if (nestedGroup) {
|
||||||
@ -1993,20 +2019,21 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
}
|
}
|
||||||
// Write collapse flag (stored in a single col info record after this
|
// Write collapse flag (stored in a single col info record after this
|
||||||
// outline group)
|
// outline group)
|
||||||
setColumn((int) columnInfo.getMax() + 1, null, null, null,
|
setColumn((int) columnInfo.getMax() + 1, null, null,
|
||||||
Boolean.FALSE, Boolean.FALSE);
|
Boolean.FALSE, Boolean.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private boolean isColumnGroupHiddenByParent(int idx) {
|
private boolean isColumnGroupHiddenByParent(int idx) {
|
||||||
CTCols cols = worksheet.getColsArray(0);
|
CTCols cols = worksheet.getColsArray(0);
|
||||||
// Look out outline details of end
|
// Look out outline details of end
|
||||||
int endLevel = 0;
|
int endLevel = 0;
|
||||||
boolean endHidden = false;
|
boolean endHidden = false;
|
||||||
int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
|
int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
|
||||||
if (endOfOutlineGroupIdx < cols.sizeOfColArray()) {
|
CTCol[] colArray = cols.getColArray();
|
||||||
CTCol nextInfo = cols.getColArray(endOfOutlineGroupIdx + 1);
|
if (endOfOutlineGroupIdx < colArray.length) {
|
||||||
if (isAdjacentBefore(cols.getColArray(endOfOutlineGroupIdx),
|
CTCol nextInfo = colArray[endOfOutlineGroupIdx + 1];
|
||||||
nextInfo)) {
|
if (isAdjacentBefore(colArray[endOfOutlineGroupIdx], nextInfo)) {
|
||||||
endLevel = nextInfo.getOutlineLevel();
|
endLevel = nextInfo.getOutlineLevel();
|
||||||
endHidden = nextInfo.getHidden();
|
endHidden = nextInfo.getHidden();
|
||||||
}
|
}
|
||||||
@ -2016,10 +2043,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
boolean startHidden = false;
|
boolean startHidden = false;
|
||||||
int startOfOutlineGroupIdx = findStartOfColumnOutlineGroup(idx);
|
int startOfOutlineGroupIdx = findStartOfColumnOutlineGroup(idx);
|
||||||
if (startOfOutlineGroupIdx > 0) {
|
if (startOfOutlineGroupIdx > 0) {
|
||||||
CTCol prevInfo = cols.getColArray(startOfOutlineGroupIdx - 1);
|
CTCol prevInfo = colArray[startOfOutlineGroupIdx - 1];
|
||||||
|
|
||||||
if (isAdjacentBefore(prevInfo, cols
|
if (isAdjacentBefore(prevInfo, colArray[startOfOutlineGroupIdx])) {
|
||||||
.getColArray(startOfOutlineGroupIdx))) {
|
|
||||||
startLevel = prevInfo.getOutlineLevel();
|
startLevel = prevInfo.getOutlineLevel();
|
||||||
startHidden = prevInfo.getHidden();
|
startHidden = prevInfo.getHidden();
|
||||||
}
|
}
|
||||||
@ -2031,6 +2057,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return startHidden;
|
return startHidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private int findColInfoIdx(int columnValue, int fromColInfoIdx) {
|
private int findColInfoIdx(int columnValue, int fromColInfoIdx) {
|
||||||
CTCols cols = worksheet.getColsArray(0);
|
CTCols cols = worksheet.getColsArray(0);
|
||||||
|
|
||||||
@ -2043,8 +2070,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
"fromIdx parameter out of range: " + fromColInfoIdx);
|
"fromIdx parameter out of range: " + fromColInfoIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int k = fromColInfoIdx; k < cols.sizeOfColArray(); k++) {
|
CTCol[] colArray = cols.getColArray();
|
||||||
CTCol ci = cols.getColArray(k);
|
for (int k = fromColInfoIdx; k < colArray.length; k++) {
|
||||||
|
CTCol ci = colArray[k];
|
||||||
|
|
||||||
if (containsColumn(ci, columnValue)) {
|
if (containsColumn(ci, columnValue)) {
|
||||||
return k;
|
return k;
|
||||||
@ -2069,16 +2097,18 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* @param idx
|
* @param idx
|
||||||
* @return a boolean represented if the column is collapsed
|
* @return a boolean represented if the column is collapsed
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private boolean isColumnGroupCollapsed(int idx) {
|
private boolean isColumnGroupCollapsed(int idx) {
|
||||||
CTCols cols = worksheet.getColsArray(0);
|
CTCols cols = worksheet.getColsArray(0);
|
||||||
|
CTCol[] colArray = cols.getColArray();
|
||||||
int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
|
int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
|
||||||
int nextColInfoIx = endOfOutlineGroupIdx + 1;
|
int nextColInfoIx = endOfOutlineGroupIdx + 1;
|
||||||
if (nextColInfoIx >= cols.sizeOfColArray()) {
|
if (nextColInfoIx >= colArray.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CTCol nextColInfo = cols.getColArray(nextColInfoIx);
|
CTCol nextColInfo = colArray[nextColInfoIx];
|
||||||
|
|
||||||
CTCol col = cols.getColArray(endOfOutlineGroupIdx);
|
CTCol col = colArray[endOfOutlineGroupIdx];
|
||||||
if (!isAdjacentBefore(col, nextColInfo)) {
|
if (!isAdjacentBefore(col, nextColInfo)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2285,7 +2315,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
*/
|
*/
|
||||||
private int findStartOfRowOutlineGroup(int rowIndex) {
|
private int findStartOfRowOutlineGroup(int rowIndex) {
|
||||||
// Find the start of the group.
|
// Find the start of the group.
|
||||||
int level = getRow(rowIndex).getCTRow().getOutlineLevel();
|
short level = getRow(rowIndex).getCTRow().getOutlineLevel();
|
||||||
int currentRow = rowIndex;
|
int currentRow = rowIndex;
|
||||||
while (getRow(currentRow) != null) {
|
while (getRow(currentRow) != null) {
|
||||||
if (getRow(currentRow).getCTRow().getOutlineLevel() < level)
|
if (getRow(currentRow).getCTRow().getOutlineLevel() < level)
|
||||||
@ -2296,7 +2326,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int writeHidden(XSSFRow xRow, int rowIndex, boolean hidden) {
|
private int writeHidden(XSSFRow xRow, int rowIndex, boolean hidden) {
|
||||||
int level = xRow.getCTRow().getOutlineLevel();
|
short level = xRow.getCTRow().getOutlineLevel();
|
||||||
for (Iterator<Row> it = rowIterator(); it.hasNext();) {
|
for (Iterator<Row> it = rowIterator(); it.hasNext();) {
|
||||||
xRow = (XSSFRow) it.next();
|
xRow = (XSSFRow) it.next();
|
||||||
|
|
||||||
@ -2343,10 +2373,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
// is the enclosing group
|
// is the enclosing group
|
||||||
// hidden bit only is altered for this outline level. ie. don't
|
// hidden bit only is altered for this outline level. ie. don't
|
||||||
// un-collapse contained groups
|
// un-collapse contained groups
|
||||||
|
short level = row.getCTRow().getOutlineLevel();
|
||||||
if (!isRowGroupHiddenByParent(rowNumber)) {
|
if (!isRowGroupHiddenByParent(rowNumber)) {
|
||||||
for (int i = startIdx; i < endIdx; i++) {
|
for (int i = startIdx; i < endIdx; i++) {
|
||||||
if (row.getCTRow().getOutlineLevel() == getRow(i).getCTRow()
|
if (level == getRow(i).getCTRow().getOutlineLevel()) {
|
||||||
.getOutlineLevel()) {
|
|
||||||
getRow(i).getCTRow().unsetHidden();
|
getRow(i).getCTRow().unsetHidden();
|
||||||
} else if (!isRowGroupCollapsed(i)) {
|
} else if (!isRowGroupCollapsed(i)) {
|
||||||
getRow(i).getCTRow().unsetHidden();
|
getRow(i).getCTRow().unsetHidden();
|
||||||
@ -2365,7 +2395,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* @param row the zero based row index to find from
|
* @param row the zero based row index to find from
|
||||||
*/
|
*/
|
||||||
public int findEndOfRowOutlineGroup(int row) {
|
public int findEndOfRowOutlineGroup(int row) {
|
||||||
int level = getRow(row).getCTRow().getOutlineLevel();
|
short level = getRow(row).getCTRow().getOutlineLevel();
|
||||||
int currentRow;
|
int currentRow;
|
||||||
for (currentRow = row; currentRow < getLastRowNum(); currentRow++) {
|
for (currentRow = row; currentRow < getLastRowNum(); currentRow++) {
|
||||||
if (getRow(currentRow) == null
|
if (getRow(currentRow) == null
|
||||||
@ -2621,11 +2651,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
for (int i = fromRow; i <= toRow; i++) {
|
for (int i = fromRow; i <= toRow; i++) {
|
||||||
XSSFRow xrow = getRow(i);
|
XSSFRow xrow = getRow(i);
|
||||||
if (xrow != null) {
|
if (xrow != null) {
|
||||||
CTRow ctrow = xrow.getCTRow();
|
CTRow ctRow = xrow.getCTRow();
|
||||||
short outlinelevel = ctrow.getOutlineLevel();
|
int outlineLevel = ctRow.getOutlineLevel();
|
||||||
ctrow.setOutlineLevel((short) (outlinelevel - 1));
|
ctRow.setOutlineLevel((short) (outlineLevel - 1));
|
||||||
//remove a row only if the row has no cell and if the outline level is 0
|
//remove a row only if the row has no cell and if the outline level is 0
|
||||||
if (ctrow.getOutlineLevel() == 0 && xrow.getFirstCellNum() == -1) {
|
if (outlineLevel == 1 && xrow.getFirstCellNum() == -1) {
|
||||||
removeRow(xrow);
|
removeRow(xrow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2737,13 +2767,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* so we can decide about writing it to disk or not
|
* so we can decide about writing it to disk or not
|
||||||
*/
|
*/
|
||||||
public boolean hasComments() {
|
public boolean hasComments() {
|
||||||
if(sheetComments == null) { return false; }
|
return sheetComments != null && sheetComments.getNumberOfComments() > 0;
|
||||||
return (sheetComments.getNumberOfComments() > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getNumberOfComments() {
|
protected int getNumberOfComments() {
|
||||||
if(sheetComments == null) { return 0; }
|
return sheetComments == null ? 0 : sheetComments.getNumberOfComments();
|
||||||
return sheetComments.getNumberOfComments();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CTSelection getSheetTypeSelection() {
|
private CTSelection getSheetTypeSelection() {
|
||||||
@ -2842,7 +2870,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
CTCellFormula sf = (CTCellFormula)f.copy();
|
CTCellFormula sf = (CTCellFormula)f.copy();
|
||||||
CellRangeAddress sfRef = CellRangeAddress.valueOf(sf.getRef());
|
CellRangeAddress sfRef = CellRangeAddress.valueOf(sf.getRef());
|
||||||
CellReference cellRef = new CellReference(cell);
|
CellReference cellRef = new CellReference(cell);
|
||||||
// If the shared formula range preceeds the master cell then the preceding part is discarded, e.g.
|
// If the shared formula range precedes the master cell then the preceding part is discarded, e.g.
|
||||||
// if the cell is E60 and the shared formula range is C60:M85 then the effective range is E60:M85
|
// if the cell is E60 and the shared formula range is C60:M85 then the effective range is E60:M85
|
||||||
// see more details in https://issues.apache.org/bugzilla/show_bug.cgi?id=51710
|
// see more details in https://issues.apache.org/bugzilla/show_bug.cgi?id=51710
|
||||||
if(cellRef.getCol() > sfRef.getFirstColumn() || cellRef.getRow() > sfRef.getFirstRow()){
|
if(cellRef.getCol() > sfRef.getFirstColumn() || cellRef.getRow() > sfRef.getFirstRow()){
|
||||||
@ -2920,160 +2948,112 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* @return true when Autofilters are locked and the sheet is protected.
|
* @return true when Autofilters are locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isAutoFilterLocked() {
|
public boolean isAutoFilterLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getAutoFilter();
|
||||||
return safeGetProtectionField().getAutoFilter();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Deleting columns is locked and the sheet is protected.
|
* @return true when Deleting columns is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isDeleteColumnsLocked() {
|
public boolean isDeleteColumnsLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getDeleteColumns();
|
||||||
return safeGetProtectionField().getDeleteColumns();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Deleting rows is locked and the sheet is protected.
|
* @return true when Deleting rows is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isDeleteRowsLocked() {
|
public boolean isDeleteRowsLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getDeleteRows();
|
||||||
return safeGetProtectionField().getDeleteRows();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Formatting cells is locked and the sheet is protected.
|
* @return true when Formatting cells is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isFormatCellsLocked() {
|
public boolean isFormatCellsLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getFormatCells();
|
||||||
return safeGetProtectionField().getFormatCells();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Formatting columns is locked and the sheet is protected.
|
* @return true when Formatting columns is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isFormatColumnsLocked() {
|
public boolean isFormatColumnsLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getFormatColumns();
|
||||||
return safeGetProtectionField().getFormatColumns();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Formatting rows is locked and the sheet is protected.
|
* @return true when Formatting rows is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isFormatRowsLocked() {
|
public boolean isFormatRowsLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getFormatRows();
|
||||||
return safeGetProtectionField().getFormatRows();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Inserting columns is locked and the sheet is protected.
|
* @return true when Inserting columns is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isInsertColumnsLocked() {
|
public boolean isInsertColumnsLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getInsertColumns();
|
||||||
return safeGetProtectionField().getInsertColumns();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Inserting hyperlinks is locked and the sheet is protected.
|
* @return true when Inserting hyperlinks is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isInsertHyperlinksLocked() {
|
public boolean isInsertHyperlinksLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getInsertHyperlinks();
|
||||||
return safeGetProtectionField().getInsertHyperlinks();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Inserting rows is locked and the sheet is protected.
|
* @return true when Inserting rows is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isInsertRowsLocked() {
|
public boolean isInsertRowsLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getInsertRows();
|
||||||
return safeGetProtectionField().getInsertRows();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Pivot tables are locked and the sheet is protected.
|
* @return true when Pivot tables are locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isPivotTablesLocked() {
|
public boolean isPivotTablesLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getPivotTables();
|
||||||
return safeGetProtectionField().getPivotTables();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Sorting is locked and the sheet is protected.
|
* @return true when Sorting is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isSortLocked() {
|
public boolean isSortLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getSort();
|
||||||
return safeGetProtectionField().getSort();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Objects are locked and the sheet is protected.
|
* @return true when Objects are locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isObjectsLocked() {
|
public boolean isObjectsLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getObjects();
|
||||||
return safeGetProtectionField().getObjects();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Scenarios are locked and the sheet is protected.
|
* @return true when Scenarios are locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isScenariosLocked() {
|
public boolean isScenariosLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getScenarios();
|
||||||
return safeGetProtectionField().getScenarios();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Selection of locked cells is locked and the sheet is protected.
|
* @return true when Selection of locked cells is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isSelectLockedCellsLocked() {
|
public boolean isSelectLockedCellsLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getSelectLockedCells();
|
||||||
return safeGetProtectionField().getSelectLockedCells();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Selection of unlocked cells is locked and the sheet is protected.
|
* @return true when Selection of unlocked cells is locked and the sheet is protected.
|
||||||
*/
|
*/
|
||||||
public boolean isSelectUnlockedCellsLocked() {
|
public boolean isSelectUnlockedCellsLocked() {
|
||||||
if (isSheetLocked()) {
|
return isSheetLocked() && safeGetProtectionField().getSelectUnlockedCells();
|
||||||
return safeGetProtectionField().getSelectUnlockedCells();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true when Sheet is Protected.
|
* @return true when Sheet is Protected.
|
||||||
*/
|
*/
|
||||||
public boolean isSheetLocked() {
|
public boolean isSheetLocked() {
|
||||||
if (worksheet.isSetSheetProtection()) {
|
return worksheet.isSetSheetProtection() && safeGetProtectionField().getSheet();
|
||||||
return safeGetProtectionField().getSheet();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3530,10 +3510,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* Returns any tables associated with this Sheet
|
* Returns any tables associated with this Sheet
|
||||||
*/
|
*/
|
||||||
public List<XSSFTable> getTables() {
|
public List<XSSFTable> getTables() {
|
||||||
List<XSSFTable> tableList = new ArrayList<XSSFTable>(
|
return new ArrayList<XSSFTable>(tables.values());
|
||||||
tables.values()
|
|
||||||
);
|
|
||||||
return tableList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -3656,19 +3633,18 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
String c = "";
|
String c = "";
|
||||||
String r = "";
|
String r = "";
|
||||||
|
|
||||||
if(startC == -1 && endC == -1) {
|
if (startC != -1 || endC != -1) {
|
||||||
} else {
|
|
||||||
c = escapedName + "!$" + colRef.getCellRefParts()[2]
|
c = escapedName + "!$" + colRef.getCellRefParts()[2]
|
||||||
+ ":$" + colRef2.getCellRefParts()[2];
|
+ ":$" + colRef2.getCellRefParts()[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startR == -1 && endR == -1) {
|
if (startR != -1 || endR != -1) {
|
||||||
|
if (!rowRef.getCellRefParts()[1].equals("0")
|
||||||
} else if (!rowRef.getCellRefParts()[1].equals("0")
|
|
||||||
&& !rowRef2.getCellRefParts()[1].equals("0")) {
|
&& !rowRef2.getCellRefParts()[1].equals("0")) {
|
||||||
r = escapedName + "!$" + rowRef.getCellRefParts()[1]
|
r = escapedName + "!$" + rowRef.getCellRefParts()[1]
|
||||||
+ ":$" + rowRef2.getCellRefParts()[1];
|
+ ":$" + rowRef2.getCellRefParts()[1];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder rng = new StringBuilder();
|
StringBuilder rng = new StringBuilder();
|
||||||
rng.append(c);
|
rng.append(c);
|
||||||
|
@ -1370,6 +1370,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
* @param pos the position that we want to insert the sheet into (0 based)
|
* @param pos the position that we want to insert the sheet into (0 based)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void setSheetOrder(String sheetname, int pos) {
|
public void setSheetOrder(String sheetname, int pos) {
|
||||||
int idx = getSheetIndex(sheetname);
|
int idx = getSheetIndex(sheetname);
|
||||||
sheets.add(pos, sheets.remove(idx));
|
sheets.add(pos, sheets.remove(idx));
|
||||||
@ -1381,8 +1382,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
newcts.set(cts);
|
newcts.set(cts);
|
||||||
|
|
||||||
//notify sheets
|
//notify sheets
|
||||||
for(int i=0; i < sheets.size(); i++) {
|
CTSheet[] sheetArray = ct.getSheetArray();
|
||||||
sheets.get(i).sheet = ct.getSheetArray(i);
|
for(int i=0; i < sheetArray.length; i++) {
|
||||||
|
sheets.get(i).sheet = sheetArray[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,10 @@ import static org.junit.Assert.assertNull;
|
|||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.poifs.crypt.CryptoFunctions;
|
import org.apache.poi.poifs.crypt.CryptoFunctions;
|
||||||
@ -295,6 +298,7 @@ public final class TestXSSFSheet extends BaseTestSheet {
|
|||||||
CellRangeAddress region_1 = CellRangeAddress.valueOf("A1:B2");
|
CellRangeAddress region_1 = CellRangeAddress.valueOf("A1:B2");
|
||||||
CellRangeAddress region_2 = CellRangeAddress.valueOf("C3:D4");
|
CellRangeAddress region_2 = CellRangeAddress.valueOf("C3:D4");
|
||||||
CellRangeAddress region_3 = CellRangeAddress.valueOf("E5:F6");
|
CellRangeAddress region_3 = CellRangeAddress.valueOf("E5:F6");
|
||||||
|
CellRangeAddress region_4 = CellRangeAddress.valueOf("G7:H8");
|
||||||
sheet.addMergedRegion(region_1);
|
sheet.addMergedRegion(region_1);
|
||||||
sheet.addMergedRegion(region_2);
|
sheet.addMergedRegion(region_2);
|
||||||
sheet.addMergedRegion(region_3);
|
sheet.addMergedRegion(region_3);
|
||||||
@ -308,6 +312,17 @@ public final class TestXSSFSheet extends BaseTestSheet {
|
|||||||
assertEquals(0, sheet.getNumMergedRegions());
|
assertEquals(0, sheet.getNumMergedRegions());
|
||||||
assertNull(" CTMergeCells should be deleted after removing the last merged " +
|
assertNull(" CTMergeCells should be deleted after removing the last merged " +
|
||||||
"region on the sheet.", sheet.getCTWorksheet().getMergeCells());
|
"region on the sheet.", sheet.getCTWorksheet().getMergeCells());
|
||||||
|
sheet.addMergedRegion(region_1);
|
||||||
|
sheet.addMergedRegion(region_2);
|
||||||
|
sheet.addMergedRegion(region_3);
|
||||||
|
sheet.addMergedRegion(region_4);
|
||||||
|
// test invalid indexes OOBE
|
||||||
|
Set<Integer> rmIdx = new HashSet<Integer>(Arrays.asList(5,6));
|
||||||
|
sheet.removeMergedRegions(rmIdx);
|
||||||
|
rmIdx = new HashSet<Integer>(Arrays.asList(1,3));
|
||||||
|
sheet.removeMergedRegions(rmIdx);
|
||||||
|
assertEquals("A1:B2", ctWorksheet.getMergeCells().getMergeCellArray(0).getRef());
|
||||||
|
assertEquals("E5:F6", ctWorksheet.getMergeCells().getMergeCellArray(1).getRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user