- adapted relevant test-classes to Junit4 to support timeout handling - tab / space cleanup git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1561435 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_10_FINAL^2
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.CellRangeAddress; | import org.apache.poi.ss.util.CellRangeAddress; | ||||
import org.apache.poi.ss.util.CellRangeAddressList; | import org.apache.poi.ss.util.CellRangeAddressList; | ||||
import org.apache.poi.ss.util.CellReference; | import org.apache.poi.ss.util.CellReference; | ||||
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.STUnsignedShortHex; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument; | |||||
/** | /** | ||||
* High level representation of a SpreadsheetML worksheet. | * High level representation of a SpreadsheetML worksheet. | ||||
private void groupColumn1Based(int fromColumn, int toColumn) { | private void groupColumn1Based(int fromColumn, int toColumn) { | ||||
CTCols ctCols=worksheet.getColsArray(0); | CTCols ctCols=worksheet.getColsArray(0); | ||||
CTCol ctCol=CTCol.Factory.newInstance(); | CTCol ctCol=CTCol.Factory.newInstance(); | ||||
// copy attributes, as they might be removed by merging with the new column | |||||
// TODO: check if this fix is really necessary or if the sweeping algorithm | |||||
// in addCleanColIntoCols needs to be adapted ... | |||||
CTCol fixCol_before = this.columnHelper.getColumn1Based(toColumn, false); | |||||
if (fixCol_before != null) { | |||||
fixCol_before = (CTCol)fixCol_before.copy(); | |||||
} | |||||
ctCol.setMin(fromColumn); | ctCol.setMin(fromColumn); | ||||
ctCol.setMax(toColumn); | ctCol.setMax(toColumn); | ||||
this.columnHelper.addCleanColIntoCols(ctCols, ctCol); | this.columnHelper.addCleanColIntoCols(ctCols, ctCol); | ||||
CTCol fixCol_after = this.columnHelper.getColumn1Based(toColumn, false); | |||||
if (fixCol_before != null && fixCol_after != null) { | |||||
this.columnHelper.setColumnAttributes(fixCol_before, fixCol_after); | |||||
} | |||||
for(int index=fromColumn;index<=toColumn;index++){ | for(int index=fromColumn;index<=toColumn;index++){ | ||||
CTCol col=columnHelper.getColumn1Based(index, false); | CTCol col=columnHelper.getColumn1Based(index, false); | ||||
//col must exist | //col must exist |
package org.apache.poi.xssf.usermodel.helpers; | package org.apache.poi.xssf.usermodel.helpers; | ||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.LinkedHashMap; | |||||
import java.util.Map; | |||||
import java.util.Comparator; | |||||
import java.util.HashSet; | |||||
import java.util.Iterator; | |||||
import java.util.List; | |||||
import java.util.ListIterator; | |||||
import java.util.Set; | |||||
import java.util.TreeSet; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | import org.apache.poi.ss.usermodel.CellStyle; | ||||
import org.apache.poi.xssf.util.CTColComparator; | import org.apache.poi.xssf.util.CTColComparator; | ||||
import org.apache.poi.xssf.util.NumericRanges; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; | ||||
this.worksheet = worksheet; | this.worksheet = worksheet; | ||||
cleanColumns(); | cleanColumns(); | ||||
} | } | ||||
@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support | |||||
public void cleanColumns() { | public void cleanColumns() { | ||||
this.newCols = CTCols.Factory.newInstance(); | this.newCols = CTCols.Factory.newInstance(); | ||||
CTCols[] colsArray = worksheet.getColsArray(); | |||||
int i = 0; | |||||
for (i = 0; i < colsArray.length; i++) { | |||||
CTCols cols = colsArray[i]; | |||||
CTCol[] colArray = cols.getColArray(); | |||||
for (int y = 0; y < colArray.length; y++) { | |||||
CTCol col = colArray[y]; | |||||
newCols = addCleanColIntoCols(newCols, col); | |||||
CTCols aggregateCols = CTCols.Factory.newInstance(); | |||||
List<CTCols> colsList = worksheet.getColsList(); | |||||
if (colsList != null) { | |||||
for (CTCols cols : colsList) { | |||||
for (CTCol col : cols.getColList()) { | |||||
cloneCol(aggregateCols, col); | |||||
} | |||||
} | } | ||||
} | } | ||||
sortColumns(aggregateCols); | |||||
CTCol[] colArray = new CTCol[aggregateCols.getColList().size()]; | |||||
aggregateCols.getColList().toArray(colArray); | |||||
sweepCleanColumns(newCols, colArray, null); | |||||
int i = colsList.size(); | |||||
for (int y = i - 1; y >= 0; y--) { | for (int y = i - 1; y >= 0; y--) { | ||||
worksheet.removeCols(y); | worksheet.removeCols(y); | ||||
} | } | ||||
worksheet.addNewCols(); | worksheet.addNewCols(); | ||||
worksheet.setColsArray(0, newCols); | worksheet.setColsArray(0, newCols); | ||||
} | } | ||||
private static class CTColByMaxComparator implements Comparator<CTCol> { | |||||
public int compare(CTCol arg0, CTCol arg1) { | |||||
if (arg0.getMax() < arg1.getMax()) { | |||||
return -1; | |||||
} else { | |||||
if (arg0.getMax() > arg1.getMax()) return 1; | |||||
else return 0; | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* @see http://en.wikipedia.org/wiki/Sweep_line_algorithm | |||||
*/ | |||||
private void sweepCleanColumns(CTCols cols, CTCol[] flattenedColsArray, CTCol overrideColumn) { | |||||
List<CTCol> flattenedCols = new ArrayList<CTCol>(Arrays.asList(flattenedColsArray)); | |||||
TreeSet<CTCol> currentElements = new TreeSet<CTCol>(new CTColByMaxComparator()); | |||||
ListIterator<CTCol> flIter = flattenedCols.listIterator(); | |||||
CTCol haveOverrideColumn = null; | |||||
long lastMaxIndex = 0; | |||||
long currentMax = 0; | |||||
while (flIter.hasNext()) { | |||||
CTCol col = flIter.next(); | |||||
long currentIndex = col.getMin(); | |||||
long nextIndex = (col.getMax() > currentMax) ? col.getMax() : currentMax; | |||||
if (flIter.hasNext()) { | |||||
nextIndex = flIter.next().getMin(); | |||||
flIter.previous(); | |||||
} | |||||
Iterator<CTCol> iter = currentElements.iterator(); | |||||
while (iter.hasNext()) { | |||||
CTCol elem = iter.next(); | |||||
if (currentIndex <= elem.getMax()) break; // all passed elements have been purged | |||||
iter.remove(); | |||||
} | |||||
if (!currentElements.isEmpty() && lastMaxIndex < currentIndex) { | |||||
// we need to process previous elements first | |||||
insertCol(cols, lastMaxIndex, currentIndex - 1, currentElements.toArray(new CTCol[]{}), true, haveOverrideColumn); | |||||
} | |||||
currentElements.add(col); | |||||
if (col.getMax() > currentMax) currentMax = col.getMax(); | |||||
if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn; | |||||
while (currentIndex <= nextIndex && !currentElements.isEmpty()) { | |||||
Set<CTCol> currentIndexElements = new HashSet<CTCol>(); | |||||
CTCol currentElem = currentElements.first(); | |||||
long currentElemIndex = currentElem.getMax(); | |||||
currentIndexElements.add(currentElem); | |||||
while (currentElements.higher(currentElem) != null && currentElements.higher(currentElem).getMax() == currentElemIndex) { | |||||
currentElem = currentElements.higher(currentElem); | |||||
currentIndexElements.add(currentElem); | |||||
if (col.getMax() > currentMax) currentMax = col.getMax(); | |||||
if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn; | |||||
} | |||||
if (currentElemIndex < nextIndex || !flIter.hasNext()) { | |||||
insertCol(cols, currentIndex, currentElemIndex, currentElements.toArray(new CTCol[]{}), true, haveOverrideColumn); | |||||
if (flIter.hasNext()) { | |||||
if (nextIndex > currentElemIndex) { | |||||
currentElements.removeAll(currentIndexElements); | |||||
if (currentIndexElements.contains(overrideColumn)) haveOverrideColumn = null; | |||||
} | |||||
} else { | |||||
currentElements.removeAll(currentIndexElements); | |||||
if (currentIndexElements.contains(overrideColumn)) haveOverrideColumn = null; | |||||
} | |||||
lastMaxIndex = currentIndex = currentElemIndex + 1; | |||||
} else { | |||||
lastMaxIndex = currentIndex; | |||||
currentIndex = nextIndex + 1; | |||||
} | |||||
} | |||||
} | |||||
sortColumns(cols); | |||||
} | |||||
@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support | |||||
public static void sortColumns(CTCols newCols) { | public static void sortColumns(CTCols newCols) { | ||||
CTCol[] colArray = newCols.getColArray(); | |||||
CTCol[] colArray = new CTCol[newCols.getColList().size()]; | |||||
newCols.getColList().toArray(colArray); | |||||
Arrays.sort(colArray, new CTColComparator()); | Arrays.sort(colArray, new CTColComparator()); | ||||
newCols.setColArray(colArray); | newCols.setColArray(colArray); | ||||
} | } | ||||
* Returns the Column at the given 0 based index | * Returns the Column at the given 0 based index | ||||
*/ | */ | ||||
public CTCol getColumn(long index, boolean splitColumns) { | public CTCol getColumn(long index, boolean splitColumns) { | ||||
return getColumn1Based(index+1, splitColumns); | |||||
return getColumn1Based(index+1, splitColumns); | |||||
} | } | ||||
/** | /** | ||||
* Returns the Column at the given 1 based index. | * Returns the Column at the given 1 based index. | ||||
* POI default is 0 based, but the file stores | * POI default is 0 based, but the file stores | ||||
*/ | */ | ||||
public CTCol getColumn1Based(long index1, boolean splitColumns) { | public CTCol getColumn1Based(long index1, boolean splitColumns) { | ||||
CTCols colsArray = worksheet.getColsArray(0); | CTCols colsArray = worksheet.getColsArray(0); | ||||
for (int i = 0; i < colsArray.sizeOfColArray(); i++) { | |||||
for (int i = 0; i < colsArray.sizeOfColArray(); i++) { | |||||
CTCol colArray = colsArray.getColArray(i); | CTCol colArray = colsArray.getColArray(i); | ||||
if (colArray.getMin() <= index1 && colArray.getMax() >= index1) { | |||||
if (splitColumns) { | |||||
if (colArray.getMin() < index1) { | |||||
insertCol(colsArray, colArray.getMin(), (index1 - 1), new CTCol[]{colArray}); | |||||
} | |||||
if (colArray.getMax() > index1) { | |||||
insertCol(colsArray, (index1 + 1), colArray.getMax(), new CTCol[]{colArray}); | |||||
} | |||||
colArray.setMin(index1); | |||||
colArray.setMax(index1); | |||||
} | |||||
if (colArray.getMin() <= index1 && colArray.getMax() >= index1) { | |||||
if (splitColumns) { | |||||
if (colArray.getMin() < index1) { | |||||
insertCol(colsArray, colArray.getMin(), (index1 - 1), new CTCol[]{colArray}); | |||||
} | |||||
if (colArray.getMax() > index1) { | |||||
insertCol(colsArray, (index1 + 1), colArray.getMax(), new CTCol[]{colArray}); | |||||
} | |||||
colArray.setMin(index1); | |||||
colArray.setMax(index1); | |||||
} | |||||
return colArray; | return colArray; | ||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public CTCols addCleanColIntoCols(CTCols cols, CTCol col) { | public CTCols addCleanColIntoCols(CTCols cols, CTCol col) { | ||||
boolean colOverlaps = false; | |||||
// a Map to remember overlapping columns | |||||
Map<Long, Boolean> overlappingCols = new LinkedHashMap<Long, Boolean>(); | |||||
int sizeOfColArray = cols.sizeOfColArray(); | |||||
for (int i = 0; i < sizeOfColArray; i++) { | |||||
CTCol ithCol = cols.getColArray(i); | |||||
long[] range1 = { ithCol.getMin(), ithCol.getMax() }; | |||||
long[] range2 = { col.getMin(), col.getMax() }; | |||||
long[] overlappingRange = NumericRanges.getOverlappingRange(range1, | |||||
range2); | |||||
int overlappingType = NumericRanges.getOverlappingType(range1, | |||||
range2); | |||||
// different behavior required for each of the 4 different | |||||
// overlapping types | |||||
if (overlappingType == NumericRanges.OVERLAPS_1_MINOR) { | |||||
// move the max border of the ithCol | |||||
// and insert a new column within the overlappingRange with merged column attributes | |||||
ithCol.setMax(overlappingRange[0] - 1); | |||||
insertCol(cols, overlappingRange[0], | |||||
overlappingRange[1], new CTCol[] { ithCol, col }); | |||||
i++; | |||||
} else if (overlappingType == NumericRanges.OVERLAPS_2_MINOR) { | |||||
// move the min border of the ithCol | |||||
// and insert a new column within the overlappingRange with merged column attributes | |||||
ithCol.setMin(overlappingRange[1] + 1); | |||||
insertCol(cols, overlappingRange[0], | |||||
overlappingRange[1], new CTCol[] { ithCol, col }); | |||||
i++; | |||||
} else if (overlappingType == NumericRanges.OVERLAPS_2_WRAPS) { | |||||
// merge column attributes, no new column is needed | |||||
setColumnAttributes(col, ithCol); | |||||
} else if (overlappingType == NumericRanges.OVERLAPS_1_WRAPS) { | |||||
// split the ithCol in three columns: before the overlappingRange, overlappingRange, and after the overlappingRange | |||||
// before overlappingRange | |||||
if (col.getMin() != ithCol.getMin()) { | |||||
insertCol(cols, ithCol.getMin(), (col | |||||
.getMin() - 1), new CTCol[] { ithCol }); | |||||
i++; | |||||
} | |||||
// after the overlappingRange | |||||
if (col.getMax() != ithCol.getMax()) { | |||||
insertCol(cols, (col.getMax() + 1), | |||||
ithCol.getMax(), new CTCol[] { ithCol }); | |||||
i++; | |||||
} | |||||
// within the overlappingRange | |||||
ithCol.setMin(overlappingRange[0]); | |||||
ithCol.setMax(overlappingRange[1]); | |||||
setColumnAttributes(col, ithCol); | |||||
} | |||||
if (overlappingType != NumericRanges.NO_OVERLAPS) { | |||||
colOverlaps = true; | |||||
// remember overlapped columns | |||||
for (long j = overlappingRange[0]; j <= overlappingRange[1]; j++) { | |||||
overlappingCols.put(Long.valueOf(j), Boolean.TRUE); | |||||
} | |||||
} | |||||
CTCols newCols = CTCols.Factory.newInstance(); | |||||
for (CTCol c : cols.getColList()) { | |||||
cloneCol(newCols, c); | |||||
} | } | ||||
if (!colOverlaps) { | |||||
cloneCol(cols, col); | |||||
} else { | |||||
// insert new columns for ranges without overlaps | |||||
long colMin = -1; | |||||
for (long j = col.getMin(); j <= col.getMax(); j++) { | |||||
if (!Boolean.TRUE.equals(overlappingCols.get(Long.valueOf(j)))) { | |||||
if (colMin < 0) { | |||||
colMin = j; | |||||
} | |||||
if ((j + 1) > col.getMax() || Boolean.TRUE.equals(overlappingCols.get(Long.valueOf(j + 1)))) { | |||||
insertCol(cols, colMin, j, new CTCol[] { col }); | |||||
colMin = -1; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
sortColumns(cols); | |||||
return cols; | |||||
cloneCol(newCols, col); | |||||
sortColumns(newCols); | |||||
CTCol[] colArray = new CTCol[newCols.getColList().size()]; | |||||
newCols.getColList().toArray(colArray); | |||||
CTCols returnCols = CTCols.Factory.newInstance(); | |||||
sweepCleanColumns(returnCols, colArray, col); | |||||
colArray = new CTCol[returnCols.getColList().size()]; | |||||
returnCols.getColList().toArray(colArray); | |||||
cols.setColArray(colArray); | |||||
return returnCols; | |||||
} | } | ||||
/* | /* | ||||
* Insert a new CTCol at position 0 into cols, setting min=min, max=max and | * Insert a new CTCol at position 0 into cols, setting min=min, max=max and | ||||
* copying all the colsWithAttributes array cols attributes into newCol | * copying all the colsWithAttributes array cols attributes into newCol | ||||
*/ | */ | ||||
private CTCol insertCol(CTCols cols, long min, long max, CTCol[] colsWithAttributes) { | |||||
return insertCol(cols, min, max, colsWithAttributes, false, null); | |||||
} | |||||
private CTCol insertCol(CTCols cols, long min, long max, | private CTCol insertCol(CTCols cols, long min, long max, | ||||
CTCol[] colsWithAttributes) { | |||||
if(!columnExists(cols,min,max)){ | |||||
CTCol newCol = cols.insertNewCol(0); | |||||
newCol.setMin(min); | |||||
newCol.setMax(max); | |||||
for (CTCol col : colsWithAttributes) { | |||||
setColumnAttributes(col, newCol); | |||||
} | |||||
return newCol; | |||||
CTCol[] colsWithAttributes, boolean ignoreExistsCheck, CTCol overrideColumn) { | |||||
if(ignoreExistsCheck || !columnExists(cols,min,max)){ | |||||
CTCol newCol = cols.insertNewCol(0); | |||||
newCol.setMin(min); | |||||
newCol.setMax(max); | |||||
for (CTCol col : colsWithAttributes) { | |||||
setColumnAttributes(col, newCol); | |||||
} | |||||
if (overrideColumn != null) setColumnAttributes(overrideColumn, newCol); | |||||
return newCol; | |||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
* in the supplied list of column definitions? | * in the supplied list of column definitions? | ||||
*/ | */ | ||||
public boolean columnExists(CTCols cols, long index) { | public boolean columnExists(CTCols cols, long index) { | ||||
return columnExists1Based(cols, index+1); | |||||
return columnExists1Based(cols, index+1); | |||||
} | } | ||||
private boolean columnExists1Based(CTCols cols, long index1) { | private boolean columnExists1Based(CTCols cols, long index1) { | ||||
for (int i = 0; i < cols.sizeOfColArray(); i++) { | for (int i = 0; i < cols.sizeOfColArray(); i++) { | ||||
} | } | ||||
public void setColumnAttributes(CTCol fromCol, CTCol toCol) { | public void setColumnAttributes(CTCol fromCol, CTCol toCol) { | ||||
if(fromCol.isSetBestFit()) toCol.setBestFit(fromCol.getBestFit()); | |||||
if(fromCol.isSetBestFit()) toCol.setBestFit(fromCol.getBestFit()); | |||||
if(fromCol.isSetCustomWidth()) toCol.setCustomWidth(fromCol.getCustomWidth()); | if(fromCol.isSetCustomWidth()) toCol.setCustomWidth(fromCol.getCustomWidth()); | ||||
if(fromCol.isSetHidden()) toCol.setHidden(fromCol.getHidden()); | if(fromCol.isSetHidden()) toCol.setHidden(fromCol.getHidden()); | ||||
if(fromCol.isSetStyle()) toCol.setStyle(fromCol.getStyle()); | if(fromCol.isSetStyle()) toCol.setStyle(fromCol.getStyle()); | ||||
return col; | return col; | ||||
} | } | ||||
public void setColDefaultStyle(long index, CellStyle style) { | |||||
setColDefaultStyle(index, style.getIndex()); | |||||
} | |||||
public void setColDefaultStyle(long index, int styleId) { | |||||
CTCol col = getOrCreateColumn1Based(index+1, true); | |||||
col.setStyle(styleId); | |||||
} | |||||
// Returns -1 if no column is found for the given index | |||||
public int getColDefaultStyle(long index) { | |||||
if (getColumn(index, false) != null) { | |||||
return (int) getColumn(index, false).getStyle(); | |||||
} | |||||
return -1; | |||||
} | |||||
public void setColDefaultStyle(long index, CellStyle style) { | |||||
setColDefaultStyle(index, style.getIndex()); | |||||
} | |||||
public void setColDefaultStyle(long index, int styleId) { | |||||
CTCol col = getOrCreateColumn1Based(index+1, true); | |||||
col.setStyle(styleId); | |||||
} | |||||
// Returns -1 if no column is found for the given index | |||||
public int getColDefaultStyle(long index) { | |||||
if (getColumn(index, false) != null) { | |||||
return (int) getColumn(index, false).getStyle(); | |||||
} | |||||
return -1; | |||||
} | |||||
private boolean columnExists(CTCols cols, long min, long max) { | |||||
for (int i = 0; i < cols.sizeOfColArray(); i++) { | |||||
if (cols.getColArray(i).getMin() == min && cols.getColArray(i).getMax() == max) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
public int getIndexOfColumn(CTCols cols, CTCol col) { | |||||
for (int i = 0; i < cols.sizeOfColArray(); i++) { | |||||
if (cols.getColArray(i).getMin() == col.getMin() && cols.getColArray(i).getMax() == col.getMax()) { | |||||
return i; | |||||
} | |||||
} | |||||
return -1; | |||||
} | |||||
} | |||||
private boolean columnExists(CTCols cols, long min, long max) { | |||||
for (int i = 0; i < cols.sizeOfColArray(); i++) { | |||||
if (cols.getColArray(i).getMin() == min && cols.getColArray(i).getMax() == max) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
public int getIndexOfColumn(CTCols cols, CTCol col) { | |||||
for (int i = 0; i < cols.sizeOfColArray(); i++) { | |||||
if (cols.getColArray(i).getMin() == col.getMin() && cols.getColArray(i).getMax() == col.getMax()) { | |||||
return i; | |||||
} | |||||
} | |||||
return -1; | |||||
} | |||||
} |
package org.apache.poi.xssf.streaming; | package org.apache.poi.xssf.streaming; | ||||
import static org.junit.Assert.assertEquals; | |||||
import static org.junit.Assert.fail; | |||||
import org.apache.poi.ss.usermodel.BaseTestSheet; | import org.apache.poi.ss.usermodel.BaseTestSheet; | ||||
import org.apache.poi.ss.usermodel.Sheet; | import org.apache.poi.ss.usermodel.Sheet; | ||||
import org.apache.poi.ss.usermodel.Workbook; | import org.apache.poi.ss.usermodel.Workbook; | ||||
import org.apache.poi.xssf.SXSSFITestDataProvider; | import org.apache.poi.xssf.SXSSFITestDataProvider; | ||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||||
import org.junit.After; | |||||
import org.junit.Test; | |||||
public class TestSXSSFSheet extends BaseTestSheet { | public class TestSXSSFSheet extends BaseTestSheet { | ||||
} | } | ||||
@Override | |||||
@After | |||||
public void tearDown(){ | public void tearDown(){ | ||||
SXSSFITestDataProvider.instance.cleanup(); | SXSSFITestDataProvider.instance.cleanup(); | ||||
} | } | ||||
* cloning of sheets is not supported in SXSSF | * cloning of sheets is not supported in SXSSF | ||||
*/ | */ | ||||
@Override | @Override | ||||
public void testCloneSheet() { | |||||
try { | |||||
super.testCloneSheet(); | |||||
fail("expected exception"); | |||||
} catch (RuntimeException e){ | |||||
assertEquals("NotImplemented", e.getMessage()); | |||||
} | |||||
@Test | |||||
public void cloneSheet() { | |||||
thrown.expect(RuntimeException.class); | |||||
thrown.expectMessage("NotImplemented"); | |||||
super.cloneSheet(); | |||||
} | } | ||||
@Override | @Override | ||||
public void testCloneSheetMultipleTimes() { | |||||
try { | |||||
super.testCloneSheetMultipleTimes(); | |||||
fail("expected exception"); | |||||
} catch (RuntimeException e){ | |||||
assertEquals("NotImplemented", e.getMessage()); | |||||
} | |||||
@Test | |||||
public void cloneSheetMultipleTimes() { | |||||
thrown.expect(RuntimeException.class); | |||||
thrown.expectMessage("NotImplemented"); | |||||
super.cloneSheetMultipleTimes(); | |||||
} | } | ||||
/** | /** | ||||
* shifting rows is not supported in SXSSF | * shifting rows is not supported in SXSSF | ||||
*/ | */ | ||||
@Override | @Override | ||||
public void testShiftMerged(){ | |||||
try { | |||||
super.testShiftMerged(); | |||||
fail("expected exception"); | |||||
} catch (RuntimeException e){ | |||||
assertEquals("NotImplemented", e.getMessage()); | |||||
} | |||||
@Test | |||||
public void shiftMerged(){ | |||||
thrown.expect(RuntimeException.class); | |||||
thrown.expectMessage("NotImplemented"); | |||||
super.shiftMerged(); | |||||
} | } | ||||
/** | /** | ||||
* The test is disabled because cloning of sheets is not supported in SXSSF | * The test is disabled because cloning of sheets is not supported in SXSSF | ||||
*/ | */ | ||||
@Override | @Override | ||||
public void test35084(){ | |||||
try { | |||||
super.test35084(); | |||||
fail("expected exception"); | |||||
} catch (RuntimeException e){ | |||||
assertEquals("NotImplemented", e.getMessage()); | |||||
} | |||||
@Test | |||||
public void bug35084(){ | |||||
thrown.expect(RuntimeException.class); | |||||
thrown.expectMessage("NotImplemented"); | |||||
super.bug35084(); | |||||
} | } | ||||
@Override | @Override | ||||
public void testDefaultColumnStyle() { | |||||
@Test | |||||
public void defaultColumnStyle() { | |||||
//TODO column styles are not yet supported by XSSF | //TODO column styles are not yet supported by XSSF | ||||
} | } | ||||
public void testOverrideFlushedRows() { | |||||
@Test | |||||
public void overrideFlushedRows() { | |||||
Workbook wb = new SXSSFWorkbook(3); | Workbook wb = new SXSSFWorkbook(3); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
sheet.createRow(2); | sheet.createRow(2); | ||||
sheet.createRow(3); | sheet.createRow(3); | ||||
sheet.createRow(4); | sheet.createRow(4); | ||||
try { | |||||
sheet.createRow(1); | |||||
fail("expected exception"); | |||||
} catch (Throwable e){ | |||||
assertEquals("Attempting to write a row[1] in the range [0,1] that is already written to disk.", e.getMessage()); | |||||
} | |||||
thrown.expect(Throwable.class); | |||||
thrown.expectMessage("Attempting to write a row[1] in the range [0,1] that is already written to disk."); | |||||
sheet.createRow(1); | |||||
} | } | ||||
public void testOverrideRowsInTemplate() { | |||||
@Test | |||||
public void overrideRowsInTemplate() { | |||||
XSSFWorkbook template = new XSSFWorkbook(); | XSSFWorkbook template = new XSSFWorkbook(); | ||||
template.createSheet().createRow(1); | template.createSheet().createRow(1); | ||||
package org.apache.poi.xssf.usermodel; | package org.apache.poi.xssf.usermodel; | ||||
import static org.junit.Assert.assertEquals; | |||||
import static org.junit.Assert.assertFalse; | |||||
import static org.junit.Assert.assertNotNull; | |||||
import static org.junit.Assert.assertNotSame; | |||||
import static org.junit.Assert.assertNull; | |||||
import static org.junit.Assert.assertSame; | |||||
import static org.junit.Assert.assertTrue; | |||||
import static org.junit.Assert.fail; | |||||
import java.util.List; | import java.util.List; | ||||
import org.apache.poi.hssf.HSSFTestDataSamples; | import org.apache.poi.hssf.HSSFTestDataSamples; | ||||
import org.apache.poi.xssf.streaming.SXSSFSheet; | import org.apache.poi.xssf.streaming.SXSSFSheet; | ||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook; | import org.apache.poi.xssf.streaming.SXSSFWorkbook; | ||||
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper; | import org.apache.poi.xssf.usermodel.helpers.ColumnHelper; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; | |||||
import org.junit.Test; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetData; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCalcMode; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane; | |||||
@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support | |||||
public final class TestXSSFSheet extends BaseTestSheet { | public final class TestXSSFSheet extends BaseTestSheet { | ||||
private static final int ROW_COUNT = 40000; | private static final int ROW_COUNT = 40000; | ||||
} | } | ||||
//TODO column styles are not yet supported by XSSF | //TODO column styles are not yet supported by XSSF | ||||
@Override | |||||
public void testDefaultColumnStyle() { | |||||
//super.testDefaultColumnStyle(); | |||||
@Test | |||||
public void defaultColumnStyle() { | |||||
//super.defaultColumnStyle(); | |||||
} | } | ||||
public void testTestGetSetMargin() { | |||||
@Test | |||||
public void getSetMargin() { | |||||
baseTestGetSetMargin(new double[]{0.7, 0.7, 0.75, 0.75, 0.3, 0.3}); | baseTestGetSetMargin(new double[]{0.7, 0.7, 0.75, 0.75, 0.3, 0.3}); | ||||
} | } | ||||
public void testExistingHeaderFooter() { | |||||
@Test | |||||
public void existingHeaderFooter() { | |||||
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("45540_classic_Header.xlsx"); | XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("45540_classic_Header.xlsx"); | ||||
XSSFOddHeader hdr; | XSSFOddHeader hdr; | ||||
XSSFOddFooter ftr; | XSSFOddFooter ftr; | ||||
assertEquals("", ftr.getRight()); | assertEquals("", ftr.getRight()); | ||||
} | } | ||||
public void testGetAllHeadersFooters() { | |||||
@Test | |||||
public void getAllHeadersFooters() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet("Sheet 1"); | XSSFSheet sheet = workbook.createSheet("Sheet 1"); | ||||
assertNotNull(sheet.getOddFooter()); | assertNotNull(sheet.getOddFooter()); | ||||
assertEquals("odd header center", sheet.getHeader().getCenter()); | assertEquals("odd header center", sheet.getHeader().getCenter()); | ||||
} | } | ||||
public void testAutoSizeColumn() { | |||||
@Test | |||||
public void autoSizeColumn() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet("Sheet 1"); | XSSFSheet sheet = workbook.createSheet("Sheet 1"); | ||||
sheet.createRow(0).createCell(13).setCellValue("test"); | sheet.createRow(0).createCell(13).setCellValue("test"); | ||||
/** | /** | ||||
* XSSFSheet autoSizeColumn() on empty RichTextString fails | * XSSFSheet autoSizeColumn() on empty RichTextString fails | ||||
*/ | */ | ||||
public void test48325() { | |||||
@Test | |||||
public void bug48325() { | |||||
XSSFWorkbook wb = new XSSFWorkbook(); | XSSFWorkbook wb = new XSSFWorkbook(); | ||||
XSSFSheet sheet = wb.createSheet("Test"); | XSSFSheet sheet = wb.createSheet("Test"); | ||||
CreationHelper factory = wb.getCreationHelper(); | CreationHelper factory = wb.getCreationHelper(); | ||||
sheet.autoSizeColumn(0); | sheet.autoSizeColumn(0); | ||||
} | } | ||||
public void testGetCellComment() { | |||||
@Test | |||||
public void getCellComment() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet(); | XSSFSheet sheet = workbook.createSheet(); | ||||
XSSFDrawing dg = sheet.createDrawingPatriarch(); | XSSFDrawing dg = sheet.createDrawingPatriarch(); | ||||
assertEquals("test C10 author", sheet.getCellComment(9, 2).getAuthor()); | assertEquals("test C10 author", sheet.getCellComment(9, 2).getAuthor()); | ||||
} | } | ||||
public void testSetCellComment() { | |||||
@Test | |||||
public void setCellComment() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet(); | XSSFSheet sheet = workbook.createSheet(); | ||||
assertEquals("test A1 author", comments.getAuthor((int) ctComments.getCommentList().getCommentArray(0).getAuthorId())); | assertEquals("test A1 author", comments.getAuthor((int) ctComments.getCommentList().getCommentArray(0).getAuthorId())); | ||||
} | } | ||||
public void testGetActiveCell() { | |||||
@Test | |||||
public void getActiveCell() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet(); | XSSFSheet sheet = workbook.createSheet(); | ||||
sheet.setActiveCell("R5"); | sheet.setActiveCell("R5"); | ||||
} | } | ||||
public void testCreateFreezePane_XSSF() { | |||||
@Test | |||||
public void createFreezePane_XSSF() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet(); | XSSFSheet sheet = workbook.createSheet(); | ||||
CTWorksheet ctWorksheet = sheet.getCTWorksheet(); | CTWorksheet ctWorksheet = sheet.getCTWorksheet(); | ||||
assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane()); | assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane()); | ||||
} | } | ||||
public void testNewMergedRegionAt() { | |||||
@Test | |||||
public void newMergedRegionAt() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet(); | XSSFSheet sheet = workbook.createSheet(); | ||||
CellRangeAddress region = CellRangeAddress.valueOf("B2:D4"); | CellRangeAddress region = CellRangeAddress.valueOf("B2:D4"); | ||||
assertEquals(1, sheet.getNumMergedRegions()); | assertEquals(1, sheet.getNumMergedRegions()); | ||||
} | } | ||||
public void testRemoveMergedRegion_lowlevel() { | |||||
@Test | |||||
public void removeMergedRegion_lowlevel() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet(); | XSSFSheet sheet = workbook.createSheet(); | ||||
CTWorksheet ctWorksheet = sheet.getCTWorksheet(); | CTWorksheet ctWorksheet = sheet.getCTWorksheet(); | ||||
"region on the sheet.", sheet.getCTWorksheet().getMergeCells()); | "region on the sheet.", sheet.getCTWorksheet().getMergeCells()); | ||||
} | } | ||||
public void testSetDefaultColumnStyle() { | |||||
@Test | |||||
public void setDefaultColumnStyle() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet(); | XSSFSheet sheet = workbook.createSheet(); | ||||
CTWorksheet ctWorksheet = sheet.getCTWorksheet(); | CTWorksheet ctWorksheet = sheet.getCTWorksheet(); | ||||
} | } | ||||
public void testGroupUngroupColumn() { | |||||
@Test | |||||
public void groupUngroupColumn() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet(); | XSSFSheet sheet = workbook.createSheet(); | ||||
sheet.groupColumn(10, 11); | sheet.groupColumn(10, 11); | ||||
CTCols cols = sheet.getCTWorksheet().getColsArray(0); | CTCols cols = sheet.getCTWorksheet().getColsArray(0); | ||||
assertEquals(2, cols.sizeOfColArray()); | assertEquals(2, cols.sizeOfColArray()); | ||||
CTCol[] colArray = cols.getColArray(); | |||||
List<CTCol> colArray = cols.getColList(); | |||||
assertNotNull(colArray); | assertNotNull(colArray); | ||||
assertEquals(2 + 1, colArray[0].getMin()); // 1 based | |||||
assertEquals(7 + 1, colArray[0].getMax()); // 1 based | |||||
assertEquals(1, colArray[0].getOutlineLevel()); | |||||
assertEquals(2 + 1, colArray.get(0).getMin()); // 1 based | |||||
assertEquals(7 + 1, colArray.get(0).getMax()); // 1 based | |||||
assertEquals(1, colArray.get(0).getOutlineLevel()); | |||||
//two level | //two level | ||||
sheet.groupColumn(1, 2); | sheet.groupColumn(1, 2); | ||||
cols = sheet.getCTWorksheet().getColsArray(0); | cols = sheet.getCTWorksheet().getColsArray(0); | ||||
assertEquals(4, cols.sizeOfColArray()); | assertEquals(4, cols.sizeOfColArray()); | ||||
colArray = cols.getColArray(); | |||||
assertEquals(2, colArray[1].getOutlineLevel()); | |||||
colArray = cols.getColList(); | |||||
assertEquals(2, colArray.get(1).getOutlineLevel()); | |||||
//three level | //three level | ||||
sheet.groupColumn(6, 8); | sheet.groupColumn(6, 8); | ||||
sheet.groupColumn(2, 3); | sheet.groupColumn(2, 3); | ||||
cols = sheet.getCTWorksheet().getColsArray(0); | cols = sheet.getCTWorksheet().getColsArray(0); | ||||
assertEquals(7, cols.sizeOfColArray()); | assertEquals(7, cols.sizeOfColArray()); | ||||
colArray = cols.getColArray(); | |||||
assertEquals(3, colArray[1].getOutlineLevel()); | |||||
colArray = cols.getColList(); | |||||
assertEquals(3, colArray.get(1).getOutlineLevel()); | |||||
assertEquals(3, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol()); | assertEquals(3, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol()); | ||||
sheet.ungroupColumn(8, 10); | sheet.ungroupColumn(8, 10); | ||||
colArray = cols.getColArray(); | |||||
colArray = cols.getColList(); | |||||
//assertEquals(3, colArray[1].getOutlineLevel()); | //assertEquals(3, colArray[1].getOutlineLevel()); | ||||
sheet.ungroupColumn(4, 6); | sheet.ungroupColumn(4, 6); | ||||
sheet.ungroupColumn(2, 2); | sheet.ungroupColumn(2, 2); | ||||
colArray = cols.getColArray(); | |||||
assertEquals(4, colArray.length); | |||||
colArray = cols.getColList(); | |||||
assertEquals(4, colArray.size()); | |||||
assertEquals(2, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol()); | assertEquals(2, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol()); | ||||
} | } | ||||
public void testGroupUngroupRow() { | |||||
@Test | |||||
public void groupUngroupRow() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet(); | XSSFSheet sheet = workbook.createSheet(); | ||||
assertEquals(1, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelRow()); | assertEquals(1, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelRow()); | ||||
} | } | ||||
public void testSetZoom() { | |||||
@Test | |||||
public void setZoom() { | |||||
XSSFWorkbook workBook = new XSSFWorkbook(); | XSSFWorkbook workBook = new XSSFWorkbook(); | ||||
XSSFSheet sheet1 = workBook.createSheet("new sheet"); | XSSFSheet sheet1 = workBook.createSheet("new sheet"); | ||||
sheet1.setZoom(3, 4); // 75 percent magnification | sheet1.setZoom(3, 4); // 75 percent magnification | ||||
* be doing... Someone who understands the goals a little | * be doing... Someone who understands the goals a little | ||||
* better should really review this! | * better should really review this! | ||||
*/ | */ | ||||
public void testSetColumnGroupCollapsed(){ | |||||
@Test | |||||
public void setColumnGroupCollapsed(){ | |||||
Workbook wb = new XSSFWorkbook(); | Workbook wb = new XSSFWorkbook(); | ||||
XSSFSheet sheet1 =(XSSFSheet) wb.createSheet(); | XSSFSheet sheet1 =(XSSFSheet) wb.createSheet(); | ||||
assertEquals(5, cols.getColArray(0).getMin()); // 1 based | assertEquals(5, cols.getColArray(0).getMin()); // 1 based | ||||
assertEquals(8, cols.getColArray(0).getMax()); // 1 based | assertEquals(8, cols.getColArray(0).getMax()); // 1 based | ||||
assertEquals(false,cols.getColArray(1).isSetHidden()); | assertEquals(false,cols.getColArray(1).isSetHidden()); | ||||
assertEquals(false,cols.getColArray(1).isSetCollapsed()); | |||||
assertEquals(true,cols.getColArray(1).isSetCollapsed()); | |||||
assertEquals(9, cols.getColArray(1).getMin()); // 1 based | assertEquals(9, cols.getColArray(1).getMin()); // 1 based | ||||
assertEquals(9, cols.getColArray(1).getMax()); // 1 based | assertEquals(9, cols.getColArray(1).getMax()); // 1 based | ||||
assertEquals(true, cols.getColArray(2).isSetHidden()); | assertEquals(true, cols.getColArray(2).isSetHidden()); | ||||
assertEquals(5, cols.getColArray(0).getMin()); // 1 based | assertEquals(5, cols.getColArray(0).getMin()); // 1 based | ||||
assertEquals(8, cols.getColArray(0).getMax()); // 1 based | assertEquals(8, cols.getColArray(0).getMax()); // 1 based | ||||
assertEquals(false,cols.getColArray(1).isSetHidden()); | assertEquals(false,cols.getColArray(1).isSetHidden()); | ||||
assertEquals(false,cols.getColArray(1).isSetCollapsed()); | |||||
assertEquals(true,cols.getColArray(1).isSetCollapsed()); | |||||
assertEquals(9, cols.getColArray(1).getMin()); // 1 based | assertEquals(9, cols.getColArray(1).getMin()); // 1 based | ||||
assertEquals(9, cols.getColArray(1).getMax()); // 1 based | assertEquals(9, cols.getColArray(1).getMax()); // 1 based | ||||
assertEquals(false,cols.getColArray(2).isSetHidden()); | assertEquals(false,cols.getColArray(2).isSetHidden()); | ||||
assertEquals(5, cols.getColArray(0).getMin()); // 1 based | assertEquals(5, cols.getColArray(0).getMin()); // 1 based | ||||
assertEquals(8, cols.getColArray(0).getMax()); // 1 based | assertEquals(8, cols.getColArray(0).getMax()); // 1 based | ||||
assertEquals(false,cols.getColArray(1).isSetHidden()); | assertEquals(false,cols.getColArray(1).isSetHidden()); | ||||
assertEquals(false,cols.getColArray(1).isSetCollapsed()); | |||||
assertEquals(true,cols.getColArray(1).isSetCollapsed()); | |||||
assertEquals(9, cols.getColArray(1).getMin()); // 1 based | assertEquals(9, cols.getColArray(1).getMin()); // 1 based | ||||
assertEquals(9, cols.getColArray(1).getMax()); // 1 based | assertEquals(9, cols.getColArray(1).getMax()); // 1 based | ||||
assertEquals(false,cols.getColArray(2).isSetHidden()); | assertEquals(false,cols.getColArray(2).isSetHidden()); | ||||
assertEquals(5, cols.getColArray(0).getMin()); // 1 based | assertEquals(5, cols.getColArray(0).getMin()); // 1 based | ||||
assertEquals(8, cols.getColArray(0).getMax()); // 1 based | assertEquals(8, cols.getColArray(0).getMax()); // 1 based | ||||
assertEquals(false,cols.getColArray(1).isSetHidden()); | assertEquals(false,cols.getColArray(1).isSetHidden()); | ||||
assertEquals(false,cols.getColArray(1).isSetCollapsed()); | |||||
assertEquals(true,cols.getColArray(1).isSetCollapsed()); | |||||
assertEquals(9, cols.getColArray(1).getMin()); // 1 based | assertEquals(9, cols.getColArray(1).getMin()); // 1 based | ||||
assertEquals(9, cols.getColArray(1).getMax()); // 1 based | assertEquals(9, cols.getColArray(1).getMax()); // 1 based | ||||
assertEquals(false,cols.getColArray(2).isSetHidden()); | assertEquals(false,cols.getColArray(2).isSetHidden()); | ||||
* be doing... Someone who understands the goals a little | * be doing... Someone who understands the goals a little | ||||
* better should really review this! | * better should really review this! | ||||
*/ | */ | ||||
public void testSetRowGroupCollapsed(){ | |||||
@Test | |||||
public void setRowGroupCollapsed(){ | |||||
Workbook wb = new XSSFWorkbook(); | Workbook wb = new XSSFWorkbook(); | ||||
XSSFSheet sheet1 = (XSSFSheet)wb.createSheet(); | XSSFSheet sheet1 = (XSSFSheet)wb.createSheet(); | ||||
/** | /** | ||||
* Get / Set column width and check the actual values of the underlying XML beans | * Get / Set column width and check the actual values of the underlying XML beans | ||||
*/ | */ | ||||
public void testColumnWidth_lowlevel() { | |||||
@Test | |||||
public void columnWidth_lowlevel() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet("Sheet 1"); | XSSFSheet sheet = workbook.createSheet("Sheet 1"); | ||||
sheet.setColumnWidth(1, 22 * 256); | sheet.setColumnWidth(1, 22 * 256); | ||||
XSSFSheet xs = sheet; | XSSFSheet xs = sheet; | ||||
CTWorksheet cts = xs.getCTWorksheet(); | CTWorksheet cts = xs.getCTWorksheet(); | ||||
CTCols[] cols_s = cts.getColsArray(); | |||||
assertEquals(1, cols_s.length); | |||||
CTCols cols = cols_s[0]; | |||||
List<CTCols> cols_s = cts.getColsList(); | |||||
assertEquals(1, cols_s.size()); | |||||
CTCols cols = cols_s.get(0); | |||||
assertEquals(1, cols.sizeOfColArray()); | assertEquals(1, cols.sizeOfColArray()); | ||||
CTCol col = cols.getColArray(0); | CTCol col = cols.getColArray(0); | ||||
// Now set another | // Now set another | ||||
sheet.setColumnWidth(3, 33 * 256); | sheet.setColumnWidth(3, 33 * 256); | ||||
cols_s = cts.getColsArray(); | |||||
assertEquals(1, cols_s.length); | |||||
cols = cols_s[0]; | |||||
cols_s = cts.getColsList(); | |||||
assertEquals(1, cols_s.size()); | |||||
cols = cols_s.get(0); | |||||
assertEquals(2, cols.sizeOfColArray()); | assertEquals(2, cols.sizeOfColArray()); | ||||
col = cols.getColArray(0); | col = cols.getColArray(0); | ||||
/** | /** | ||||
* Setting width of a column included in a column span | * Setting width of a column included in a column span | ||||
*/ | */ | ||||
public void test47862() { | |||||
@Test | |||||
public void bug47862() { | |||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47862.xlsx"); | XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47862.xlsx"); | ||||
XSSFSheet sheet = wb.getSheetAt(0); | XSSFSheet sheet = wb.getSheetAt(0); | ||||
CTCols cols = sheet.getCTWorksheet().getColsArray(0); | CTCols cols = sheet.getCTWorksheet().getColsArray(0); | ||||
/** | /** | ||||
* Hiding a column included in a column span | * Hiding a column included in a column span | ||||
*/ | */ | ||||
public void test47804() { | |||||
@Test | |||||
public void bug47804() { | |||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47804.xlsx"); | XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47804.xlsx"); | ||||
XSSFSheet sheet = wb.getSheetAt(0); | XSSFSheet sheet = wb.getSheetAt(0); | ||||
CTCols cols = sheet.getCTWorksheet().getColsArray(0); | CTCols cols = sheet.getCTWorksheet().getColsArray(0); | ||||
assertFalse(sheet.isColumnHidden(5)); | assertFalse(sheet.isColumnHidden(5)); | ||||
} | } | ||||
public void testCommentsTable() { | |||||
@Test | |||||
public void commentsTable() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet1 = workbook.createSheet(); | XSSFSheet sheet1 = workbook.createSheet(); | ||||
CommentsTable comment1 = sheet1.getCommentsTable(false); | CommentsTable comment1 = sheet1.getCommentsTable(false); | ||||
* Rows and cells can be created in random order, | * Rows and cells can be created in random order, | ||||
* but CTRows are kept in ascending order | * but CTRows are kept in ascending order | ||||
*/ | */ | ||||
public void testCreateRowA() { | |||||
@Test | |||||
public void createRow() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet(); | XSSFSheet sheet = workbook.createSheet(); | ||||
CTWorksheet wsh = sheet.getCTWorksheet(); | CTWorksheet wsh = sheet.getCTWorksheet(); | ||||
row3.createCell(5); | row3.createCell(5); | ||||
CTRow[] xrow = sheetData.getRowArray(); | |||||
assertEquals(3, xrow.length); | |||||
List<CTRow> xrow = sheetData.getRowList(); | |||||
assertEquals(3, xrow.size()); | |||||
//rows are sorted: {0, 1, 2} | //rows are sorted: {0, 1, 2} | ||||
assertEquals(4, xrow[0].sizeOfCArray()); | |||||
assertEquals(1, xrow[0].getR()); | |||||
assertTrue(xrow[0].equals(row3.getCTRow())); | |||||
assertEquals(4, xrow.get(0).sizeOfCArray()); | |||||
assertEquals(1, xrow.get(0).getR()); | |||||
assertTrue(xrow.get(0).equals(row3.getCTRow())); | |||||
assertEquals(3, xrow[1].sizeOfCArray()); | |||||
assertEquals(2, xrow[1].getR()); | |||||
assertTrue(xrow[1].equals(row2.getCTRow())); | |||||
assertEquals(3, xrow.get(1).sizeOfCArray()); | |||||
assertEquals(2, xrow.get(1).getR()); | |||||
assertTrue(xrow.get(1).equals(row2.getCTRow())); | |||||
assertEquals(2, xrow[2].sizeOfCArray()); | |||||
assertEquals(3, xrow[2].getR()); | |||||
assertTrue(xrow[2].equals(row1.getCTRow())); | |||||
assertEquals(2, xrow.get(2).sizeOfCArray()); | |||||
assertEquals(3, xrow.get(2).getR()); | |||||
assertTrue(xrow.get(2).equals(row1.getCTRow())); | |||||
CTCell[] xcell = xrow[0].getCArray(); | |||||
assertEquals("D1", xcell[0].getR()); | |||||
assertEquals("A1", xcell[1].getR()); | |||||
assertEquals("C1", xcell[2].getR()); | |||||
assertEquals("F1", xcell[3].getR()); | |||||
List<CTCell> xcell = xrow.get(0).getCList(); | |||||
assertEquals("D1", xcell.get(0).getR()); | |||||
assertEquals("A1", xcell.get(1).getR()); | |||||
assertEquals("C1", xcell.get(2).getR()); | |||||
assertEquals("F1", xcell.get(3).getR()); | |||||
//re-creating a row does NOT add extra data to the parent | //re-creating a row does NOT add extra data to the parent | ||||
row2 = sheet.createRow(1); | row2 = sheet.createRow(1); | ||||
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); | workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); | ||||
sheet = workbook.getSheetAt(0); | sheet = workbook.getSheetAt(0); | ||||
wsh = sheet.getCTWorksheet(); | wsh = sheet.getCTWorksheet(); | ||||
xrow = sheetData.getRowArray(); | |||||
assertEquals(3, xrow.length); | |||||
xrow = sheetData.getRowList(); | |||||
assertEquals(3, xrow.size()); | |||||
//rows are sorted: {0, 1, 2} | //rows are sorted: {0, 1, 2} | ||||
assertEquals(4, xrow[0].sizeOfCArray()); | |||||
assertEquals(1, xrow[0].getR()); | |||||
assertEquals(4, xrow.get(0).sizeOfCArray()); | |||||
assertEquals(1, xrow.get(0).getR()); | |||||
//cells are now sorted | //cells are now sorted | ||||
xcell = xrow[0].getCArray(); | |||||
assertEquals("A1", xcell[0].getR()); | |||||
assertEquals("C1", xcell[1].getR()); | |||||
assertEquals("D1", xcell[2].getR()); | |||||
assertEquals("F1", xcell[3].getR()); | |||||
xcell = xrow.get(0).getCList(); | |||||
assertEquals("A1", xcell.get(0).getR()); | |||||
assertEquals("C1", xcell.get(1).getR()); | |||||
assertEquals("D1", xcell.get(2).getR()); | |||||
assertEquals("F1", xcell.get(3).getR()); | |||||
assertEquals(0, xrow[1].sizeOfCArray()); | |||||
assertEquals(2, xrow[1].getR()); | |||||
assertEquals(0, xrow.get(1).sizeOfCArray()); | |||||
assertEquals(2, xrow.get(1).getR()); | |||||
assertEquals(2, xrow[2].sizeOfCArray()); | |||||
assertEquals(3, xrow[2].getR()); | |||||
assertEquals(2, xrow.get(2).sizeOfCArray()); | |||||
assertEquals(3, xrow.get(2).getR()); | |||||
} | } | ||||
public void testSetAutoFilter() { | |||||
@Test | |||||
public void setAutoFilter() { | |||||
XSSFWorkbook wb = new XSSFWorkbook(); | XSSFWorkbook wb = new XSSFWorkbook(); | ||||
XSSFSheet sheet = wb.createSheet("new sheet"); | XSSFSheet sheet = wb.createSheet("new sheet"); | ||||
sheet.setAutoFilter(CellRangeAddress.valueOf("A1:D100")); | sheet.setAutoFilter(CellRangeAddress.valueOf("A1:D100")); | ||||
assertEquals("'new sheet'!$A$1:$D$100", nm.getCTName().getStringValue()); | assertEquals("'new sheet'!$A$1:$D$100", nm.getCTName().getStringValue()); | ||||
} | } | ||||
public void testProtectSheet_lowlevel() { | |||||
XSSFWorkbook wb = new XSSFWorkbook(); | |||||
XSSFSheet sheet = wb.createSheet(); | |||||
@Test | |||||
public void protectSheet_lowlevel() { | |||||
XSSFWorkbook wb = new XSSFWorkbook(); | |||||
XSSFSheet sheet = wb.createSheet(); | |||||
CTSheetProtection pr = sheet.getCTWorksheet().getSheetProtection(); | CTSheetProtection pr = sheet.getCTWorksheet().getSheetProtection(); | ||||
assertNull("CTSheetProtection should be null by default", pr); | assertNull("CTSheetProtection should be null by default", pr); | ||||
String password = "Test"; | String password = "Test"; | ||||
} | } | ||||
public void test49966() { | |||||
@Test | |||||
public void bug49966() { | |||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49966.xlsx"); | XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49966.xlsx"); | ||||
CalculationChain calcChain = wb.getCalculationChain(); | CalculationChain calcChain = wb.getCalculationChain(); | ||||
assertNotNull(wb.getCalculationChain()); | assertNotNull(wb.getCalculationChain()); | ||||
/** | /** | ||||
* See bug #50829 | * See bug #50829 | ||||
*/ | */ | ||||
public void testTables() { | |||||
@Test | |||||
public void tables() { | |||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithTable.xlsx"); | XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithTable.xlsx"); | ||||
assertEquals(3, wb.getNumberOfSheets()); | assertEquals(3, wb.getNumberOfSheets()); | ||||
// Check the table sheet | // Check the table sheet | ||||
XSSFSheet s1 = wb.getSheetAt(0); | XSSFSheet s1 = wb.getSheetAt(0); | ||||
assertEquals("a", s1.getRow(0).getCell(0).getRichStringCellValue().toString()); | assertEquals("a", s1.getRow(0).getCell(0).getRichStringCellValue().toString()); | ||||
assertEquals(1.0, s1.getRow(1).getCell(0).getNumericCellValue()); | |||||
assertEquals(1.0, s1.getRow(1).getCell(0).getNumericCellValue(), 0); | |||||
List<XSSFTable> tables = s1.getTables(); | List<XSSFTable> tables = s1.getTables(); | ||||
assertNotNull(tables); | assertNotNull(tables); | ||||
/** | /** | ||||
* Test to trigger OOXML-LITE generating to include org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetCalcPr | * Test to trigger OOXML-LITE generating to include org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetCalcPr | ||||
*/ | */ | ||||
public void testSetForceFormulaRecalculation() { | |||||
@Test | |||||
public void setForceFormulaRecalculation() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = workbook.createSheet("Sheet 1"); | XSSFSheet sheet = workbook.createSheet("Sheet 1"); | ||||
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); | workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); | ||||
sheet = workbook.getSheet("Sheet 1"); | sheet = workbook.getSheet("Sheet 1"); | ||||
assertEquals(false, sheet.getForceFormulaRecalculation()); | assertEquals(false, sheet.getForceFormulaRecalculation()); | ||||
} | |||||
public void test54607() { | |||||
// run with the file provided in the Bug-Report | |||||
runGetTopRow("54607.xlsx", true, 1, 0, 0); | |||||
runGetLeftCol("54607.xlsx", true, 0, 0, 0); | |||||
// run with some other flie to see | |||||
runGetTopRow("54436.xlsx", true, 0); | |||||
runGetLeftCol("54436.xlsx", true, 0); | |||||
runGetTopRow("TwoSheetsNoneHidden.xlsx", true, 0, 0); | |||||
runGetLeftCol("TwoSheetsNoneHidden.xlsx", true, 0, 0); | |||||
runGetTopRow("TwoSheetsNoneHidden.xls", false, 0, 0); | |||||
runGetLeftCol("TwoSheetsNoneHidden.xls", false, 0, 0); | |||||
} | } | ||||
private void runGetTopRow(String file, boolean isXSSF, int... topRows) { | |||||
final Workbook wb; | |||||
if(isXSSF) { | |||||
wb = XSSFTestDataSamples.openSampleWorkbook(file); | |||||
} else { | |||||
wb = HSSFTestDataSamples.openSampleWorkbook(file); | |||||
} | |||||
for (int si = 0; si < wb.getNumberOfSheets(); si++) { | |||||
Sheet sh = wb.getSheetAt(si); | |||||
assertNotNull(sh.getSheetName()); | |||||
assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow()); | |||||
} | |||||
// for XSSF also test with SXSSF | |||||
if(isXSSF) { | |||||
Workbook swb = new SXSSFWorkbook((XSSFWorkbook) wb); | |||||
for (int si = 0; si < swb.getNumberOfSheets(); si++) { | |||||
Sheet sh = swb.getSheetAt(si); | |||||
assertNotNull(sh.getSheetName()); | |||||
assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow()); | |||||
} | |||||
} | |||||
} | |||||
private void runGetLeftCol(String file, boolean isXSSF, int... topRows) { | |||||
final Workbook wb; | |||||
if(isXSSF) { | |||||
wb = XSSFTestDataSamples.openSampleWorkbook(file); | |||||
} else { | |||||
wb = HSSFTestDataSamples.openSampleWorkbook(file); | |||||
} | |||||
for (int si = 0; si < wb.getNumberOfSheets(); si++) { | |||||
Sheet sh = wb.getSheetAt(si); | |||||
assertNotNull(sh.getSheetName()); | |||||
assertEquals("Did not match for sheet " + si, topRows[si], sh.getLeftCol()); | |||||
} | |||||
// for XSSF also test with SXSSF | |||||
if(isXSSF) { | |||||
Workbook swb = new SXSSFWorkbook((XSSFWorkbook) wb); | |||||
for (int si = 0; si < swb.getNumberOfSheets(); si++) { | |||||
Sheet sh = swb.getSheetAt(si); | |||||
assertNotNull(sh.getSheetName()); | |||||
assertEquals("Did not match for sheet " + si, topRows[si], sh.getLeftCol()); | |||||
} | |||||
} | |||||
} | |||||
public void testShowInPaneManyRowsBug55248() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | |||||
XSSFSheet sheet = workbook.createSheet("Sheet 1"); | |||||
sheet.showInPane(0, 0); | |||||
@Test | |||||
public void bug54607() { | |||||
// run with the file provided in the Bug-Report | |||||
runGetTopRow("54607.xlsx", true, 1, 0, 0); | |||||
runGetLeftCol("54607.xlsx", true, 0, 0, 0); | |||||
// run with some other flie to see | |||||
runGetTopRow("54436.xlsx", true, 0); | |||||
runGetLeftCol("54436.xlsx", true, 0); | |||||
runGetTopRow("TwoSheetsNoneHidden.xlsx", true, 0, 0); | |||||
runGetLeftCol("TwoSheetsNoneHidden.xlsx", true, 0, 0); | |||||
runGetTopRow("TwoSheetsNoneHidden.xls", false, 0, 0); | |||||
runGetLeftCol("TwoSheetsNoneHidden.xls", false, 0, 0); | |||||
} | |||||
private void runGetTopRow(String file, boolean isXSSF, int... topRows) { | |||||
final Workbook wb; | |||||
if(isXSSF) { | |||||
wb = XSSFTestDataSamples.openSampleWorkbook(file); | |||||
} else { | |||||
wb = HSSFTestDataSamples.openSampleWorkbook(file); | |||||
} | |||||
for (int si = 0; si < wb.getNumberOfSheets(); si++) { | |||||
Sheet sh = wb.getSheetAt(si); | |||||
assertNotNull(sh.getSheetName()); | |||||
assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow()); | |||||
} | |||||
// for XSSF also test with SXSSF | |||||
if(isXSSF) { | |||||
Workbook swb = new SXSSFWorkbook((XSSFWorkbook) wb); | |||||
for (int si = 0; si < swb.getNumberOfSheets(); si++) { | |||||
Sheet sh = swb.getSheetAt(si); | |||||
assertNotNull(sh.getSheetName()); | |||||
assertEquals("Did not match for sheet " + si, topRows[si], sh.getTopRow()); | |||||
} | |||||
} | |||||
} | |||||
private void runGetLeftCol(String file, boolean isXSSF, int... topRows) { | |||||
final Workbook wb; | |||||
if(isXSSF) { | |||||
wb = XSSFTestDataSamples.openSampleWorkbook(file); | |||||
} else { | |||||
wb = HSSFTestDataSamples.openSampleWorkbook(file); | |||||
} | |||||
for (int si = 0; si < wb.getNumberOfSheets(); si++) { | |||||
Sheet sh = wb.getSheetAt(si); | |||||
assertNotNull(sh.getSheetName()); | |||||
assertEquals("Did not match for sheet " + si, topRows[si], sh.getLeftCol()); | |||||
} | |||||
// for XSSF also test with SXSSF | |||||
if(isXSSF) { | |||||
Workbook swb = new SXSSFWorkbook((XSSFWorkbook) wb); | |||||
for (int si = 0; si < swb.getNumberOfSheets(); si++) { | |||||
Sheet sh = swb.getSheetAt(si); | |||||
assertNotNull(sh.getSheetName()); | |||||
assertEquals("Did not match for sheet " + si, topRows[si], sh.getLeftCol()); | |||||
} | |||||
} | |||||
} | |||||
@Test | |||||
public void showInPaneManyRowsBug55248() { | |||||
XSSFWorkbook workbook = new XSSFWorkbook(); | |||||
XSSFSheet sheet = workbook.createSheet("Sheet 1"); | |||||
sheet.showInPane(0, 0); | |||||
for(int i = ROW_COUNT/2;i < ROW_COUNT;i++) { | for(int i = ROW_COUNT/2;i < ROW_COUNT;i++) { | ||||
sheet.createRow(i); | sheet.createRow(i); | ||||
sheet.showInPane(i, 0); | sheet.showInPane(i, 0); | ||||
// this one fails: sheet.showInPane((short)i, 0); | // this one fails: sheet.showInPane((short)i, 0); | ||||
} | } | ||||
short i = 0; | |||||
int i = 0; | |||||
sheet.showInPane(i, i); | sheet.showInPane(i, i); | ||||
XSSFWorkbook wb = XSSFTestDataSamples.writeOutAndReadBack(workbook); | XSSFWorkbook wb = XSSFTestDataSamples.writeOutAndReadBack(workbook); | ||||
checkRowCount(wb); | checkRowCount(wb); | ||||
} | |||||
} | |||||
public void testShowInPaneManyRowsBug55248SXSSF() { | |||||
@Test | |||||
public void showInPaneManyRowsBug55248SXSSF() { | |||||
SXSSFWorkbook workbook = new SXSSFWorkbook(new XSSFWorkbook()); | SXSSFWorkbook workbook = new SXSSFWorkbook(new XSSFWorkbook()); | ||||
SXSSFSheet sheet = (SXSSFSheet) workbook.createSheet("Sheet 1"); | SXSSFSheet sheet = (SXSSFSheet) workbook.createSheet("Sheet 1"); | ||||
sheet.showInPane(0, 0); | sheet.showInPane(0, 0); | ||||
for(int i = ROW_COUNT/2;i < ROW_COUNT;i++) { | for(int i = ROW_COUNT/2;i < ROW_COUNT;i++) { | ||||
sheet.createRow(i); | sheet.createRow(i); | ||||
sheet.showInPane(i, 0); | sheet.showInPane(i, 0); | ||||
// this one fails: sheet.showInPane((short)i, 0); | // this one fails: sheet.showInPane((short)i, 0); | ||||
} | } | ||||
short i = 0; | |||||
int i = 0; | |||||
sheet.showInPane(i, i); | sheet.showInPane(i, i); | ||||
Workbook wb = SXSSFITestDataProvider.instance.writeOutAndReadBack(workbook); | Workbook wb = SXSSFITestDataProvider.instance.writeOutAndReadBack(workbook); | ||||
checkRowCount(wb); | checkRowCount(wb); | ||||
} | } | ||||
assertEquals(ROW_COUNT-1, sh.getLastRowNum()); | assertEquals(ROW_COUNT-1, sh.getLastRowNum()); | ||||
} | } | ||||
public static void test55745() throws Exception { | |||||
@Test | |||||
public void bug55745() throws Exception { | |||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55745.xlsx"); | XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55745.xlsx"); | ||||
XSSFSheet sheet = wb.getSheetAt(0); | XSSFSheet sheet = wb.getSheetAt(0); | ||||
List<XSSFTable> tables = sheet.getTables(); | List<XSSFTable> tables = sheet.getTables(); | ||||
/*System.out.println(tables.size()); | /*System.out.println(tables.size()); | ||||
for(XSSFTable table : tables) { | for(XSSFTable table : tables) { | ||||
System.out.println("XPath: " + table.getCommonXpath()); | System.out.println("XPath: " + table.getCommonXpath()); | ||||
System.out.println("Name: " + table.getName()); | System.out.println("Name: " + table.getName()); | ||||
assertNotNull("Sheet should contain a comments table", sheet.getCommentsTable(false)); | assertNotNull("Sheet should contain a comments table", sheet.getCommentsTable(false)); | ||||
} | } | ||||
public void testBug55723b(){ | |||||
@Test | |||||
public void bug55723b(){ | |||||
XSSFWorkbook wb = new XSSFWorkbook(); | XSSFWorkbook wb = new XSSFWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
CellRangeAddress range = CellRangeAddress.valueOf("A:B"); | CellRangeAddress range = CellRangeAddress.valueOf("A:B"); | ||||
AutoFilter filter = sheet.setAutoFilter(range); | AutoFilter filter = sheet.setAutoFilter(range); | ||||
assertNotNull(filter); | assertNotNull(filter); | ||||
// stored with a special name | // stored with a special name | ||||
XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0); | XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0); | ||||
assertNotNull(name); | assertNotNull(name); | ||||
assertEquals("Sheet0!$A:$B", name.getRefersToFormula()); | assertEquals("Sheet0!$A:$B", name.getRefersToFormula()); | ||||
range = CellRangeAddress.valueOf("B:C"); | range = CellRangeAddress.valueOf("B:C"); | ||||
filter = sheet.setAutoFilter(range); | filter = sheet.setAutoFilter(range); | ||||
assertNotNull(filter); | assertNotNull(filter); | ||||
// stored with a special name | // stored with a special name | ||||
name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0); | name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, 0); | ||||
assertNotNull(name); | assertNotNull(name); | ||||
assertEquals("Sheet0!$B:$C", name.getRefersToFormula()); | assertEquals("Sheet0!$B:$C", name.getRefersToFormula()); | ||||
} | } | ||||
} | |||||
@Test(timeout=180000) | |||||
public void bug51585(){ | |||||
XSSFTestDataSamples.openSampleWorkbook("51585.xlsx"); | |||||
} | |||||
} |
package org.apache.poi.hssf.usermodel; | package org.apache.poi.hssf.usermodel; | ||||
import static org.junit.Assert.assertEquals; | |||||
import static org.junit.Assert.assertFalse; | |||||
import static org.junit.Assert.assertNotNull; | |||||
import static org.junit.Assert.assertNull; | |||||
import static org.junit.Assert.assertSame; | |||||
import static org.junit.Assert.assertTrue; | |||||
import static org.junit.Assert.fail; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
import java.util.List; | import java.util.List; | ||||
import junit.framework.AssertionFailedError; | |||||
import org.apache.poi.ddf.EscherDgRecord; | import org.apache.poi.ddf.EscherDgRecord; | ||||
import org.apache.poi.hssf.HSSFITestDataProvider; | import org.apache.poi.hssf.HSSFITestDataProvider; | ||||
import org.apache.poi.hssf.HSSFTestDataSamples; | import org.apache.poi.hssf.HSSFTestDataSamples; | ||||
import org.apache.poi.hssf.model.DrawingManager2; | import org.apache.poi.hssf.model.DrawingManager2; | ||||
import org.apache.poi.hssf.model.InternalSheet; | import org.apache.poi.hssf.model.InternalSheet; | ||||
import org.apache.poi.hssf.model.InternalWorkbook; | import org.apache.poi.hssf.model.InternalWorkbook; | ||||
import org.apache.poi.hssf.record.*; | |||||
import org.apache.poi.hssf.record.AutoFilterInfoRecord; | |||||
import org.apache.poi.hssf.record.CommonObjectDataSubRecord; | |||||
import org.apache.poi.hssf.record.DimensionsRecord; | |||||
import org.apache.poi.hssf.record.FtCblsSubRecord; | |||||
import org.apache.poi.hssf.record.GridsetRecord; | |||||
import org.apache.poi.hssf.record.HCenterRecord; | |||||
import org.apache.poi.hssf.record.LbsDataSubRecord; | |||||
import org.apache.poi.hssf.record.NameRecord; | |||||
import org.apache.poi.hssf.record.ObjRecord; | |||||
import org.apache.poi.hssf.record.ObjectProtectRecord; | |||||
import org.apache.poi.hssf.record.PasswordRecord; | |||||
import org.apache.poi.hssf.record.ProtectRecord; | |||||
import org.apache.poi.hssf.record.Record; | |||||
import org.apache.poi.hssf.record.SCLRecord; | |||||
import org.apache.poi.hssf.record.ScenarioProtectRecord; | |||||
import org.apache.poi.hssf.record.SubRecord; | |||||
import org.apache.poi.hssf.record.VCenterRecord; | |||||
import org.apache.poi.hssf.record.WSBoolRecord; | |||||
import org.apache.poi.hssf.record.WindowTwoRecord; | |||||
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock; | import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock; | ||||
import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector; | import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector; | ||||
import org.apache.poi.ss.formula.ptg.Area3DPtg; | import org.apache.poi.ss.formula.ptg.Area3DPtg; | ||||
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; | ||||
import org.apache.poi.util.TempFile; | import org.apache.poi.util.TempFile; | ||||
import org.junit.Test; | |||||
/** | /** | ||||
* Tests HSSFSheet. This test case is very incomplete at the moment. | * Tests HSSFSheet. This test case is very incomplete at the moment. | ||||
* Test for Bugzilla #29747. | * Test for Bugzilla #29747. | ||||
* Moved from TestHSSFWorkbook#testSetRepeatingRowsAndColumns(). | * Moved from TestHSSFWorkbook#testSetRepeatingRowsAndColumns(). | ||||
*/ | */ | ||||
public void testSetRepeatingRowsAndColumnsBug29747() { | |||||
@Test | |||||
public void setRepeatingRowsAndColumnsBug29747() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
wb.createSheet(); | wb.createSheet(); | ||||
wb.createSheet(); | wb.createSheet(); | ||||
} | } | ||||
public void testTestGetSetMargin() { | |||||
@Test | |||||
public void getSetMargin() { | |||||
baseTestGetSetMargin(new double[]{0.75, 0.75, 1.0, 1.0, 0.3, 0.3}); | baseTestGetSetMargin(new double[]{0.75, 0.75, 1.0, 1.0, 0.3, 0.3}); | ||||
} | } | ||||
/** | /** | ||||
* Test the gridset field gets set as expected. | * Test the gridset field gets set as expected. | ||||
*/ | */ | ||||
public void testBackupRecord() { | |||||
@Test | |||||
public void backupRecord() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet s = wb.createSheet(); | HSSFSheet s = wb.createSheet(); | ||||
GridsetRecord gridsetRec = s.getSheet().getGridsetRecord(); | GridsetRecord gridsetRec = s.getSheet().getGridsetRecord(); | ||||
* Test vertically centered output. | * Test vertically centered output. | ||||
*/ | */ | ||||
@SuppressWarnings("deprecation") | @SuppressWarnings("deprecation") | ||||
public void testVerticallyCenter() { | |||||
@Test | |||||
public void verticallyCenter() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet s = wb.createSheet(); | HSSFSheet s = wb.createSheet(); | ||||
VCenterRecord record = s.getSheet().getPageSettings().getVCenter(); | VCenterRecord record = s.getSheet().getPageSettings().getVCenter(); | ||||
/** | /** | ||||
* Test horizontally centered output. | * Test horizontally centered output. | ||||
*/ | */ | ||||
public void testHorizontallyCenter() { | |||||
@Test | |||||
public void horizontallyCenter() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet s = wb.createSheet(); | HSSFSheet s = wb.createSheet(); | ||||
HCenterRecord record = s.getSheet().getPageSettings().getHCenter(); | HCenterRecord record = s.getSheet().getPageSettings().getHCenter(); | ||||
/** | /** | ||||
* Test WSBboolRecord fields get set in the user model. | * Test WSBboolRecord fields get set in the user model. | ||||
*/ | */ | ||||
public void testWSBool() { | |||||
@Test | |||||
public void wsBool() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet s = wb.createSheet(); | HSSFSheet s = wb.createSheet(); | ||||
WSBoolRecord record = | WSBoolRecord record = | ||||
/** | /** | ||||
* Setting landscape and portrait stuff on existing sheets | * Setting landscape and portrait stuff on existing sheets | ||||
*/ | */ | ||||
public void testPrintSetupLandscapeExisting() { | |||||
@Test | |||||
public void printSetupLandscapeExisting() { | |||||
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls"); | HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls"); | ||||
assertEquals(3, workbook.getNumberOfSheets()); | assertEquals(3, workbook.getNumberOfSheets()); | ||||
assertEquals(1, sheetLS.getPrintSetup().getCopies()); | assertEquals(1, sheetLS.getPrintSetup().getCopies()); | ||||
} | } | ||||
public void testGroupRows() { | |||||
@Test | |||||
public void groupRows() { | |||||
HSSFWorkbook workbook = new HSSFWorkbook(); | HSSFWorkbook workbook = new HSSFWorkbook(); | ||||
HSSFSheet s = workbook.createSheet(); | HSSFSheet s = workbook.createSheet(); | ||||
HSSFRow r1 = s.createRow(0); | HSSFRow r1 = s.createRow(0); | ||||
assertEquals(0, r5.getOutlineLevel()); | assertEquals(0, r5.getOutlineLevel()); | ||||
} | } | ||||
public void testGroupRowsExisting() { | |||||
@Test | |||||
public void groupRowsExisting() { | |||||
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("NoGutsRecords.xls"); | HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("NoGutsRecords.xls"); | ||||
HSSFSheet s = workbook.getSheetAt(0); | HSSFSheet s = workbook.getSheetAt(0); | ||||
try { | try { | ||||
workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook); | workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook); | ||||
} catch (OutOfMemoryError e) { | } catch (OutOfMemoryError e) { | ||||
throw new AssertionFailedError("Identified bug 39903"); | |||||
fail("Identified bug 39903"); | |||||
} | } | ||||
s = workbook.getSheetAt(0); | s = workbook.getSheetAt(0); | ||||
assertEquals(0, r6.getOutlineLevel()); | assertEquals(0, r6.getOutlineLevel()); | ||||
} | } | ||||
public void testCreateDrawings() { | |||||
@Test | |||||
public void createDrawings() { | |||||
HSSFWorkbook workbook = new HSSFWorkbook(); | HSSFWorkbook workbook = new HSSFWorkbook(); | ||||
HSSFSheet sheet = workbook.createSheet(); | HSSFSheet sheet = workbook.createSheet(); | ||||
HSSFPatriarch p1 = sheet.createDrawingPatriarch(); | HSSFPatriarch p1 = sheet.createDrawingPatriarch(); | ||||
assertSame(p1, p2); | assertSame(p1, p2); | ||||
} | } | ||||
public void testGetDrawings() { | |||||
@Test | |||||
public void getDrawings() { | |||||
HSSFWorkbook wb1c = HSSFTestDataSamples.openSampleWorkbook("WithChart.xls"); | HSSFWorkbook wb1c = HSSFTestDataSamples.openSampleWorkbook("WithChart.xls"); | ||||
HSSFWorkbook wb2c = HSSFTestDataSamples.openSampleWorkbook("WithTwoCharts.xls"); | HSSFWorkbook wb2c = HSSFTestDataSamples.openSampleWorkbook("WithTwoCharts.xls"); | ||||
/** | /** | ||||
* Test that the ProtectRecord is included when creating or cloning a sheet | * Test that the ProtectRecord is included when creating or cloning a sheet | ||||
*/ | */ | ||||
public void testCloneWithProtect() { | |||||
@Test | |||||
public void cloneWithProtect() { | |||||
String passwordA = "secrect"; | String passwordA = "secrect"; | ||||
int expectedHashA = -6810; | int expectedHashA = -6810; | ||||
String passwordB = "admin"; | String passwordB = "admin"; | ||||
assertEquals(expectedHashA, sheet2.getSheet().getProtectionBlock().getPasswordHash()); | assertEquals(expectedHashA, sheet2.getSheet().getProtectionBlock().getPasswordHash()); | ||||
} | } | ||||
public void testProtectSheetA() { | |||||
@Test | |||||
public void protectSheetA() { | |||||
int expectedHash = (short)0xfef1; | int expectedHash = (short)0xfef1; | ||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet s = wb.createSheet(); | HSSFSheet s = wb.createSheet(); | ||||
* {@link PasswordRecord} belongs with the rest of the Worksheet Protection Block | * {@link PasswordRecord} belongs with the rest of the Worksheet Protection Block | ||||
* (which should be before {@link DimensionsRecord}). | * (which should be before {@link DimensionsRecord}). | ||||
*/ | */ | ||||
public void testProtectSheetRecordOrder_bug47363a() { | |||||
@Test | |||||
public void protectSheetRecordOrder_bug47363a() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet s = wb.createSheet(); | HSSFSheet s = wb.createSheet(); | ||||
s.protectSheet("secret"); | s.protectSheet("secret"); | ||||
Record[] recs = rc.getRecords(); | Record[] recs = rc.getRecords(); | ||||
int nRecs = recs.length; | int nRecs = recs.length; | ||||
if (recs[nRecs-2] instanceof PasswordRecord && recs[nRecs-5] instanceof DimensionsRecord) { | if (recs[nRecs-2] instanceof PasswordRecord && recs[nRecs-5] instanceof DimensionsRecord) { | ||||
throw new AssertionFailedError("Identified bug 47363a - PASSWORD after DIMENSION"); | |||||
fail("Identified bug 47363a - PASSWORD after DIMENSION"); | |||||
} | } | ||||
// Check that protection block is together, and before DIMENSION | // Check that protection block is together, and before DIMENSION | ||||
confirmRecordClass(recs, nRecs-4, DimensionsRecord.class); | confirmRecordClass(recs, nRecs-4, DimensionsRecord.class); | ||||
private static void confirmRecordClass(Record[] recs, int index, Class<? extends Record> cls) { | private static void confirmRecordClass(Record[] recs, int index, Class<? extends Record> cls) { | ||||
if (recs.length <= index) { | if (recs.length <= index) { | ||||
throw new AssertionFailedError("Expected (" + cls.getName() + ") at index " | |||||
+ index + " but array length is " + recs.length + "."); | |||||
fail("Expected (" + cls.getName() + ") at index " | |||||
+ index + " but array length is " + recs.length + "."); | |||||
} | } | ||||
assertEquals(cls, recs[index].getClass()); | assertEquals(cls, recs[index].getClass()); | ||||
} | } | ||||
/** | /** | ||||
* There should be no problem with adding data validations after sheet protection | * There should be no problem with adding data validations after sheet protection | ||||
*/ | */ | ||||
public void testDvProtectionOrder_bug47363b() { | |||||
@Test | |||||
public void dvProtectionOrder_bug47363b() { | |||||
HSSFWorkbook workbook = new HSSFWorkbook(); | HSSFWorkbook workbook = new HSSFWorkbook(); | ||||
HSSFSheet sheet = workbook.createSheet("Sheet1"); | HSSFSheet sheet = workbook.createSheet("Sheet1"); | ||||
sheet.protectSheet("secret"); | sheet.protectSheet("secret"); | ||||
} catch (IllegalStateException e) { | } catch (IllegalStateException e) { | ||||
String expMsg = "Unexpected (org.apache.poi.hssf.record.PasswordRecord) while looking for DV Table insert pos"; | String expMsg = "Unexpected (org.apache.poi.hssf.record.PasswordRecord) while looking for DV Table insert pos"; | ||||
if (expMsg.equals(e.getMessage())) { | if (expMsg.equals(e.getMessage())) { | ||||
throw new AssertionFailedError("Identified bug 47363b"); | |||||
fail("Identified bug 47363b"); | |||||
} | } | ||||
throw e; | throw e; | ||||
} | } | ||||
assertEquals(4, nRecsWithProtection - nRecsWithoutProtection); | assertEquals(4, nRecsWithProtection - nRecsWithoutProtection); | ||||
} | } | ||||
public void testZoom() { | |||||
@Test | |||||
public void zoom() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet sheet = wb.createSheet(); | HSSFSheet sheet = wb.createSheet(); | ||||
assertEquals(-1, sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid)); | assertEquals(-1, sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid)); | ||||
/** | /** | ||||
* When removing one merged region, it would break | * When removing one merged region, it would break | ||||
* | |||||
*/ | |||||
/** | |||||
* Make sure the excel file loads work | * Make sure the excel file loads work | ||||
* | |||||
*/ | */ | ||||
public void testPageBreakFiles() { | |||||
@Test | |||||
public void pageBreakFiles() { | |||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls"); | HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls"); | ||||
HSSFSheet sheet = wb.getSheetAt(0); | HSSFSheet sheet = wb.getSheetAt(0); | ||||
assertEquals("column breaks number", 2, sheet.getColumnBreaks().length); | assertEquals("column breaks number", 2, sheet.getColumnBreaks().length); | ||||
} | } | ||||
public void testDBCSName () { | |||||
@Test | |||||
public void dbcsName () { | |||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DBCSSheetName.xls"); | HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DBCSSheetName.xls"); | ||||
wb.getSheetAt(1); | wb.getSheetAt(1); | ||||
assertEquals ("DBCS Sheet Name 2", wb.getSheetName(1),"\u090f\u0915" ); | assertEquals ("DBCS Sheet Name 2", wb.getSheetName(1),"\u090f\u0915" ); | ||||
* parameter to allow setting the toprow in the visible view | * parameter to allow setting the toprow in the visible view | ||||
* of the sheet when it is first opened. | * of the sheet when it is first opened. | ||||
*/ | */ | ||||
public void testTopRow() { | |||||
@Test | |||||
public void topRow() { | |||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls"); | HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithPageBreaks.xls"); | ||||
HSSFSheet sheet = wb.getSheetAt(0); | HSSFSheet sheet = wb.getSheetAt(0); | ||||
assertEquals("HSSFSheet.getLeftCol()", leftcol, sheet.getLeftCol()); | assertEquals("HSSFSheet.getLeftCol()", leftcol, sheet.getLeftCol()); | ||||
} | } | ||||
/** | |||||
* | |||||
*/ | |||||
public void testAddEmptyRow() { | |||||
@Test | |||||
public void addEmptyRow() { | |||||
//try to add 5 empty rows to a new sheet | //try to add 5 empty rows to a new sheet | ||||
HSSFWorkbook workbook = new HSSFWorkbook(); | HSSFWorkbook workbook = new HSSFWorkbook(); | ||||
HSSFSheet sheet = workbook.createSheet(); | HSSFSheet sheet = workbook.createSheet(); | ||||
} | } | ||||
@SuppressWarnings("deprecation") | @SuppressWarnings("deprecation") | ||||
public void testAutoSizeColumn() { | |||||
@Test | |||||
public void autoSizeColumn() { | |||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("43902.xls"); | HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("43902.xls"); | ||||
String sheetName = "my sheet"; | String sheetName = "my sheet"; | ||||
HSSFSheet sheet = wb.getSheet(sheetName); | HSSFSheet sheet = wb.getSheet(sheetName); | ||||
assertTrue(sheet3.getColumnWidth(0) <= maxWithRow1And2); | assertTrue(sheet3.getColumnWidth(0) <= maxWithRow1And2); | ||||
} | } | ||||
public void testAutoSizeDate() throws Exception { | |||||
@Test | |||||
public void autoSizeDate() throws Exception { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet s = wb.createSheet("Sheet1"); | HSSFSheet s = wb.createSheet("Sheet1"); | ||||
HSSFRow r = s.createRow(0); | HSSFRow r = s.createRow(0); | ||||
/** | /** | ||||
* Setting ForceFormulaRecalculation on sheets | * Setting ForceFormulaRecalculation on sheets | ||||
*/ | */ | ||||
public void testForceRecalculation() throws Exception { | |||||
@Test | |||||
public void forceRecalculation() throws Exception { | |||||
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("UncalcedRecord.xls"); | HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("UncalcedRecord.xls"); | ||||
HSSFSheet sheet = workbook.getSheetAt(0); | HSSFSheet sheet = workbook.getSheetAt(0); | ||||
assertTrue(wb3.getSheetAt(3).getForceFormulaRecalculation()); | assertTrue(wb3.getSheetAt(3).getForceFormulaRecalculation()); | ||||
} | } | ||||
public void testColumnWidthA() { | |||||
@Test | |||||
public void columnWidthA() { | |||||
//check we can correctly read column widths from a reference workbook | //check we can correctly read column widths from a reference workbook | ||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("colwidth.xls"); | HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("colwidth.xls"); | ||||
} | } | ||||
public void testDefaultColumnWidth() { | |||||
@Test | |||||
public void defaultColumnWidth() { | |||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook( "12843-1.xls" ); | HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook( "12843-1.xls" ); | ||||
HSSFSheet sheet = wb.getSheetAt( 7 ); | HSSFSheet sheet = wb.getSheetAt( 7 ); | ||||
// shall not be NPE | // shall not be NPE | ||||
* Excel, ooo, and google docs are OK with this. | * Excel, ooo, and google docs are OK with this. | ||||
* Now POI is too. | * Now POI is too. | ||||
*/ | */ | ||||
public void testMissingRowRecords_bug41187() { | |||||
@Test | |||||
public void missingRowRecords_bug41187() { | |||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex41187-19267.xls"); | HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex41187-19267.xls"); | ||||
HSSFSheet sheet = wb.getSheetAt(0); | HSSFSheet sheet = wb.getSheetAt(0); | ||||
HSSFRow row = sheet.getRow(0); | HSSFRow row = sheet.getRow(0); | ||||
if(row == null) { | if(row == null) { | ||||
throw new AssertionFailedError("Identified bug 41187 a"); | |||||
fail("Identified bug 41187 a"); | |||||
} | } | ||||
if (row.getHeight() == 0) { | if (row.getHeight() == 0) { | ||||
throw new AssertionFailedError("Identified bug 41187 b"); | |||||
fail("Identified bug 41187 b"); | |||||
} | } | ||||
assertEquals("Hi Excel!", row.getCell(0).getRichStringCellValue().getString()); | assertEquals("Hi Excel!", row.getCell(0).getRichStringCellValue().getString()); | ||||
// check row height for 'default' flag | // check row height for 'default' flag | ||||
* | * | ||||
* See bug #45720. | * See bug #45720. | ||||
*/ | */ | ||||
public void testCloneSheetWithDrawings() { | |||||
@Test | |||||
public void cloneSheetWithDrawings() { | |||||
HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("45720.xls"); | HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("45720.xls"); | ||||
HSSFSheet sheet1 = wb1.getSheetAt(0); | HSSFSheet sheet1 = wb1.getSheetAt(0); | ||||
* Since Excel silently truncates to 31, make sure that POI enforces uniqueness on the first | * Since Excel silently truncates to 31, make sure that POI enforces uniqueness on the first | ||||
* 31 chars. | * 31 chars. | ||||
*/ | */ | ||||
public void testLongSheetNames() { | |||||
@Test | |||||
public void longSheetNames() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
final String SAME_PREFIX = "A123456789B123456789C123456789"; // 30 chars | final String SAME_PREFIX = "A123456789B123456789C123456789"; // 30 chars | ||||
wb.createSheet(SAME_PREFIX + "Dxxxx"); | wb.createSheet(SAME_PREFIX + "Dxxxx"); | ||||
try { | try { | ||||
wb.createSheet(SAME_PREFIX + "Dyyyy"); // identical up to the 32nd char | wb.createSheet(SAME_PREFIX + "Dyyyy"); // identical up to the 32nd char | ||||
throw new AssertionFailedError("Expected exception not thrown"); | |||||
fail("Expected exception not thrown"); | |||||
} catch (IllegalArgumentException e) { | } catch (IllegalArgumentException e) { | ||||
assertEquals("The workbook already contains a sheet of this name", e.getMessage()); | assertEquals("The workbook already contains a sheet of this name", e.getMessage()); | ||||
} | } | ||||
/** | /** | ||||
* Tests that we can read existing column styles | * Tests that we can read existing column styles | ||||
*/ | */ | ||||
public void testReadColumnStyles() { | |||||
@Test | |||||
public void readColumnStyles() { | |||||
HSSFWorkbook wbNone = HSSFTestDataSamples.openSampleWorkbook("ColumnStyleNone.xls"); | HSSFWorkbook wbNone = HSSFTestDataSamples.openSampleWorkbook("ColumnStyleNone.xls"); | ||||
HSSFWorkbook wbSimple = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dp.xls"); | HSSFWorkbook wbSimple = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dp.xls"); | ||||
HSSFWorkbook wbComplex = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dpColoured.xls"); | HSSFWorkbook wbComplex = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dpColoured.xls"); | ||||
/** | /** | ||||
* Tests the arabic setting | * Tests the arabic setting | ||||
*/ | */ | ||||
public void testArabic() { | |||||
@Test | |||||
public void arabic() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet s = wb.createSheet(); | HSSFSheet s = wb.createSheet(); | ||||
assertTrue(s.isRightToLeft()); | assertTrue(s.isRightToLeft()); | ||||
} | } | ||||
public void testAutoFilter(){ | |||||
@Test | |||||
public void autoFilter(){ | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet sh = wb.createSheet(); | HSSFSheet sh = wb.createSheet(); | ||||
InternalWorkbook iwb = wb.getWorkbook(); | InternalWorkbook iwb = wb.getWorkbook(); | ||||
assertTrue(subRecords.get(2) instanceof LbsDataSubRecord ); | assertTrue(subRecords.get(2) instanceof LbsDataSubRecord ); | ||||
} | } | ||||
public void testGetSetColumnHiddenShort() { | |||||
@Test | |||||
public void getSetColumnHiddenShort() { | |||||
Workbook workbook = new HSSFWorkbook(); | Workbook workbook = new HSSFWorkbook(); | ||||
Sheet sheet = workbook.createSheet("Sheet 1"); | Sheet sheet = workbook.createSheet("Sheet 1"); | ||||
sheet.setColumnHidden((short)2, true); | sheet.setColumnHidden((short)2, true); | ||||
assertTrue(sheet.isColumnHidden((short)2)); | assertTrue(sheet.isColumnHidden((short)2)); | ||||
} | } | ||||
public void testColumnWidthShort() { | |||||
@Test | |||||
public void columnWidthShort() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
assertEquals(40000, sheet.getColumnWidth((short)10)); | assertEquals(40000, sheet.getColumnWidth((short)10)); | ||||
} | } | ||||
public void testShowInPane() { | |||||
@Test | |||||
public void showInPane() { | |||||
Workbook wb = new HSSFWorkbook(); | Workbook wb = new HSSFWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
sheet.showInPane(2, 3); | sheet.showInPane(2, 3); | ||||
try { | |||||
sheet.showInPane(Integer.MAX_VALUE, 3); | |||||
fail("Should catch exception here"); | |||||
} catch (IllegalArgumentException e) { | |||||
assertEquals("Maximum row number is 65535", e.getMessage()); | |||||
} | |||||
thrown.expect(IllegalArgumentException.class); | |||||
thrown.expectMessage("Maximum row number is 65535"); | |||||
sheet.showInPane(Integer.MAX_VALUE, 3); | |||||
} | } | ||||
public void testDrawingRecords() { | |||||
@Test | |||||
public void drawingRecords() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
HSSFSheet sheet = wb.createSheet(); | HSSFSheet sheet = wb.createSheet(); | ||||
assertNull(sheet.getDrawingEscherAggregate()); | assertNull(sheet.getDrawingEscherAggregate()); | ||||
} | } | ||||
public void testBug55723b() { | |||||
@Test | |||||
public void bug55723b() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
package org.apache.poi.ss.usermodel; | package org.apache.poi.ss.usermodel; | ||||
import java.util.Iterator; | |||||
import static org.junit.Assert.assertEquals; | |||||
import static org.junit.Assert.assertFalse; | |||||
import static org.junit.Assert.assertNotNull; | |||||
import static org.junit.Assert.assertNull; | |||||
import static org.junit.Assert.assertSame; | |||||
import static org.junit.Assert.assertTrue; | |||||
import static org.junit.Assert.fail; | |||||
import junit.framework.TestCase; | |||||
import java.util.Iterator; | |||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook; | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||||
import org.apache.poi.hssf.util.PaneInformation; | import org.apache.poi.hssf.util.PaneInformation; | ||||
import org.apache.poi.ss.ITestDataProvider; | import org.apache.poi.ss.ITestDataProvider; | ||||
import org.apache.poi.ss.SpreadsheetVersion; | import org.apache.poi.ss.SpreadsheetVersion; | ||||
import org.apache.poi.ss.util.CellRangeAddress; | import org.apache.poi.ss.util.CellRangeAddress; | ||||
import org.junit.Rule; | |||||
import org.junit.Test; | |||||
import org.junit.rules.ExpectedException; | |||||
/** | /** | ||||
* Common superclass for testing {@link org.apache.poi.xssf.usermodel.XSSFCell} and | * Common superclass for testing {@link org.apache.poi.xssf.usermodel.XSSFCell} and | ||||
* {@link org.apache.poi.hssf.usermodel.HSSFCell} | * {@link org.apache.poi.hssf.usermodel.HSSFCell} | ||||
*/ | */ | ||||
public abstract class BaseTestSheet extends TestCase { | |||||
public abstract class BaseTestSheet { | |||||
@Rule | |||||
public ExpectedException thrown = ExpectedException.none(); | |||||
private final ITestDataProvider _testDataProvider; | private final ITestDataProvider _testDataProvider; | ||||
protected BaseTestSheet(ITestDataProvider testDataProvider) { | protected BaseTestSheet(ITestDataProvider testDataProvider) { | ||||
_testDataProvider = testDataProvider; | _testDataProvider = testDataProvider; | ||||
} | } | ||||
public void testCreateRow() { | |||||
@Test | |||||
public void createRow() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = workbook.createSheet(); | Sheet sheet = workbook.createSheet(); | ||||
assertEquals(0, sheet.getPhysicalNumberOfRows()); | assertEquals(0, sheet.getPhysicalNumberOfRows()); | ||||
} | } | ||||
public void testRemoveRow() { | |||||
@Test | |||||
public void removeRow() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
Sheet sheet1 = workbook.createSheet(); | Sheet sheet1 = workbook.createSheet(); | ||||
assertEquals(0, sheet1.getPhysicalNumberOfRows()); | assertEquals(0, sheet1.getPhysicalNumberOfRows()); | ||||
Row row3 = sheet1.createRow(3); | Row row3 = sheet1.createRow(3); | ||||
Sheet sheet2 = workbook.createSheet(); | Sheet sheet2 = workbook.createSheet(); | ||||
try { | |||||
sheet2.removeRow(row3); | |||||
fail("Expected exception"); | |||||
} catch (IllegalArgumentException e){ | |||||
assertEquals("Specified row does not belong to this sheet", e.getMessage()); | |||||
} | |||||
thrown.expect(IllegalArgumentException.class); | |||||
thrown.expectMessage("Specified row does not belong to this sheet"); | |||||
sheet2.removeRow(row3); | |||||
} | } | ||||
public void testCloneSheet() { | |||||
@Test | |||||
public void cloneSheet() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
CreationHelper factory = workbook.getCreationHelper(); | CreationHelper factory = workbook.getCreationHelper(); | ||||
Sheet sheet = workbook.createSheet("Test Clone"); | Sheet sheet = workbook.createSheet("Test Clone"); | ||||
/** tests that the sheet name for multiple clones of the same sheet is unique | /** tests that the sheet name for multiple clones of the same sheet is unique | ||||
* BUG 37416 | * BUG 37416 | ||||
*/ | */ | ||||
public void testCloneSheetMultipleTimes() { | |||||
@Test | |||||
public void cloneSheetMultipleTimes() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
CreationHelper factory = workbook.getCreationHelper(); | CreationHelper factory = workbook.getCreationHelper(); | ||||
Sheet sheet = workbook.createSheet("Test Clone"); | Sheet sheet = workbook.createSheet("Test Clone"); | ||||
/** | /** | ||||
* Setting landscape and portrait stuff on new sheets | * Setting landscape and portrait stuff on new sheets | ||||
*/ | */ | ||||
public void testPrintSetupLandscapeNew() { | |||||
@Test | |||||
public void printSetupLandscapeNew() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
Sheet sheetL = workbook.createSheet("LandscapeS"); | Sheet sheetL = workbook.createSheet("LandscapeS"); | ||||
Sheet sheetP = workbook.createSheet("LandscapeP"); | Sheet sheetP = workbook.createSheet("LandscapeP"); | ||||
* then an IllegalArgumentException should be thrown | * then an IllegalArgumentException should be thrown | ||||
* | * | ||||
*/ | */ | ||||
public void testAddMerged() { | |||||
@Test | |||||
public void addMerged() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
assertEquals(0, sheet.getNumMergedRegions()); | assertEquals(0, sheet.getNumMergedRegions()); | ||||
sheet.addMergedRegion(region); | sheet.addMergedRegion(region); | ||||
fail("Expected exception"); | fail("Expected exception"); | ||||
} catch (IllegalArgumentException e){ | } catch (IllegalArgumentException e){ | ||||
// TODO assertEquals("Minimum row number is 0.", e.getMessage()); | |||||
// TODO: assertEquals("Minimum row number is 0.", e.getMessage()); | |||||
} | } | ||||
try { | try { | ||||
region = new CellRangeAddress(0, 0, 0, ssVersion.getLastColumnIndex() + 1); | region = new CellRangeAddress(0, 0, 0, ssVersion.getLastColumnIndex() + 1); | ||||
* When removing one merged region, it would break | * When removing one merged region, it would break | ||||
* | * | ||||
*/ | */ | ||||
public void testRemoveMerged() { | |||||
@Test | |||||
public void removeMerged() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1); | CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1); | ||||
assertEquals("the merged row to doesnt match the one we put in ", 4, region.getLastRow()); | assertEquals("the merged row to doesnt match the one we put in ", 4, region.getLastRow()); | ||||
} | } | ||||
public void testShiftMerged() { | |||||
@Test | |||||
public void shiftMerged() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
CreationHelper factory = wb.getCreationHelper(); | CreationHelper factory = wb.getCreationHelper(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
* Tests the display of gridlines, formulas, and rowcolheadings. | * Tests the display of gridlines, formulas, and rowcolheadings. | ||||
* @author Shawn Laubach (slaubach at apache dot org) | * @author Shawn Laubach (slaubach at apache dot org) | ||||
*/ | */ | ||||
public void testDisplayOptions() { | |||||
@Test | |||||
public void displayOptions() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
assertEquals(sheet.isDisplayZeros(), false); | assertEquals(sheet.isDisplayZeros(), false); | ||||
} | } | ||||
public void testColumnWidth() { | |||||
@Test | |||||
public void columnWidth() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
} | } | ||||
public void testDefaultRowHeight() { | |||||
@Test | |||||
public void defaultRowHeight() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = workbook.createSheet(); | Sheet sheet = workbook.createSheet(); | ||||
sheet.setDefaultRowHeightInPoints(15); | sheet.setDefaultRowHeightInPoints(15); | ||||
} | } | ||||
/** cell with formula becomes null on cloning a sheet*/ | /** cell with formula becomes null on cloning a sheet*/ | ||||
public void test35084() { | |||||
@Test | |||||
public void bug35084() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet s = wb.createSheet("Sheet1"); | Sheet s = wb.createSheet("Sheet1"); | ||||
Row r = s.createRow(0); | Row r = s.createRow(0); | ||||
} | } | ||||
/** test that new default column styles get applied */ | /** test that new default column styles get applied */ | ||||
public void testDefaultColumnStyle() { | |||||
@Test | |||||
public void defaultColumnStyle() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
CellStyle style = wb.createCellStyle(); | CellStyle style = wb.createCellStyle(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
assertEquals("style should match", style.getIndex(), style2.getIndex()); | assertEquals("style should match", style.getIndex(), style2.getIndex()); | ||||
} | } | ||||
public void testOutlineProperties() { | |||||
@Test | |||||
public void outlineProperties() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
/** | /** | ||||
* Test basic display properties | * Test basic display properties | ||||
*/ | */ | ||||
public void testSheetProperties() { | |||||
@Test | |||||
public void sheetProperties() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
assertEquals(11.5, sheet.getMargin(Sheet.HeaderMargin), 0.0); | assertEquals(11.5, sheet.getMargin(Sheet.HeaderMargin), 0.0); | ||||
// incorrect margin constant | // incorrect margin constant | ||||
try { | |||||
sheet.setMargin((short) 65, 15); | |||||
fail("Expected exception"); | |||||
} catch (IllegalArgumentException e){ | |||||
assertEquals("Unknown margin constant: 65", e.getMessage()); | |||||
} | |||||
thrown.expect(IllegalArgumentException.class); | |||||
thrown.expectMessage("Unknown margin constant: 65"); | |||||
sheet.setMargin((short) 65, 15); | |||||
} | } | ||||
public void testRowBreaks() { | |||||
@Test | |||||
public void rowBreaks() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = workbook.createSheet(); | Sheet sheet = workbook.createSheet(); | ||||
//Sheet#getRowBreaks() returns an empty array if no row breaks are defined | //Sheet#getRowBreaks() returns an empty array if no row breaks are defined | ||||
assertFalse(sheet.isRowBroken(15)); | assertFalse(sheet.isRowBroken(15)); | ||||
} | } | ||||
public void testColumnBreaks() { | |||||
@Test | |||||
public void columnBreaks() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = workbook.createSheet(); | Sheet sheet = workbook.createSheet(); | ||||
assertNotNull(sheet.getColumnBreaks()); | assertNotNull(sheet.getColumnBreaks()); | ||||
assertFalse(sheet.isColumnBroken(12)); | assertFalse(sheet.isColumnBroken(12)); | ||||
} | } | ||||
public void testGetFirstLastRowNum() { | |||||
@Test | |||||
public void getFirstLastRowNum() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = workbook.createSheet("Sheet 1"); | Sheet sheet = workbook.createSheet("Sheet 1"); | ||||
sheet.createRow(9); | sheet.createRow(9); | ||||
assertEquals(9, sheet.getLastRowNum()); | assertEquals(9, sheet.getLastRowNum()); | ||||
} | } | ||||
public void testGetFooter() { | |||||
@Test | |||||
public void getFooter() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = workbook.createSheet("Sheet 1"); | Sheet sheet = workbook.createSheet("Sheet 1"); | ||||
assertNotNull(sheet.getFooter()); | assertNotNull(sheet.getFooter()); | ||||
assertEquals("test center footer", sheet.getFooter().getCenter()); | assertEquals("test center footer", sheet.getFooter().getCenter()); | ||||
} | } | ||||
public void testGetSetColumnHidden() { | |||||
@Test | |||||
public void getSetColumnHidden() { | |||||
Workbook workbook = _testDataProvider.createWorkbook(); | Workbook workbook = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = workbook.createSheet("Sheet 1"); | Sheet sheet = workbook.createSheet("Sheet 1"); | ||||
sheet.setColumnHidden(2, true); | sheet.setColumnHidden(2, true); | ||||
assertTrue(sheet.isColumnHidden(2)); | assertTrue(sheet.isColumnHidden(2)); | ||||
} | } | ||||
public void testProtectSheet() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | |||||
Sheet sheet = wb.createSheet(); | |||||
@Test | |||||
public void protectSheet() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | |||||
Sheet sheet = wb.createSheet(); | |||||
assertFalse(sheet.getProtect()); | |||||
sheet.protectSheet("Test"); | |||||
assertTrue(sheet.getProtect()); | |||||
sheet.protectSheet(null); | |||||
assertFalse(sheet.getProtect()); | assertFalse(sheet.getProtect()); | ||||
sheet.protectSheet("Test"); | |||||
assertTrue(sheet.getProtect()); | |||||
sheet.protectSheet(null); | |||||
assertFalse(sheet.getProtect()); | |||||
} | } | ||||
public void testCreateFreezePane() { | |||||
@Test | |||||
public void createFreezePane() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
// create a workbook | // create a workbook | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
} | } | ||||
public void testGetRepeatingRowsAndColumns() { | |||||
@Test | |||||
public void getRepeatingRowsAndColumns() { | |||||
Workbook wb = _testDataProvider.openSampleWorkbook( | Workbook wb = _testDataProvider.openSampleWorkbook( | ||||
"RepeatingRowsCols." | "RepeatingRowsCols." | ||||
+ _testDataProvider.getStandardFileNameExtension()); | + _testDataProvider.getStandardFileNameExtension()); | ||||
} | } | ||||
public void testSetRepeatingRowsAndColumnsBug47294(){ | |||||
@Test | |||||
public void setRepeatingRowsAndColumnsBug47294(){ | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet1 = wb.createSheet(); | Sheet sheet1 = wb.createSheet(); | ||||
sheet1.setRepeatingRows(CellRangeAddress.valueOf("1:4")); | sheet1.setRepeatingRows(CellRangeAddress.valueOf("1:4")); | ||||
assertEquals("1:4", sheet2.getRepeatingRows().formatAsString()); | assertEquals("1:4", sheet2.getRepeatingRows().formatAsString()); | ||||
} | } | ||||
public void testSetRepeatingRowsAndColumns() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | |||||
Sheet sheet1 = wb.createSheet("Sheet1"); | |||||
Sheet sheet2 = wb.createSheet("Sheet2"); | |||||
Sheet sheet3 = wb.createSheet("Sheet3"); | |||||
checkRepeatingRowsAndColumns(sheet1, null, null); | |||||
sheet1.setRepeatingRows(CellRangeAddress.valueOf("4:5")); | |||||
sheet2.setRepeatingColumns(CellRangeAddress.valueOf("A:C")); | |||||
sheet3.setRepeatingRows(CellRangeAddress.valueOf("1:4")); | |||||
sheet3.setRepeatingColumns(CellRangeAddress.valueOf("A:A")); | |||||
checkRepeatingRowsAndColumns(sheet1, "4:5", null); | |||||
checkRepeatingRowsAndColumns(sheet2, null, "A:C"); | |||||
checkRepeatingRowsAndColumns(sheet3, "1:4", "A:A"); | |||||
// write out, read back, and test refrain... | |||||
wb = _testDataProvider.writeOutAndReadBack(wb); | |||||
sheet1 = wb.getSheetAt(0); | |||||
sheet2 = wb.getSheetAt(1); | |||||
sheet3 = wb.getSheetAt(2); | |||||
checkRepeatingRowsAndColumns(sheet1, "4:5", null); | |||||
checkRepeatingRowsAndColumns(sheet2, null, "A:C"); | |||||
checkRepeatingRowsAndColumns(sheet3, "1:4", "A:A"); | |||||
// check removing repeating rows and columns | |||||
sheet3.setRepeatingRows(null); | |||||
checkRepeatingRowsAndColumns(sheet3, null, "A:A"); | |||||
sheet3.setRepeatingColumns(null); | |||||
checkRepeatingRowsAndColumns(sheet3, null, null); | |||||
@Test | |||||
public void setRepeatingRowsAndColumns() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | |||||
Sheet sheet1 = wb.createSheet("Sheet1"); | |||||
Sheet sheet2 = wb.createSheet("Sheet2"); | |||||
Sheet sheet3 = wb.createSheet("Sheet3"); | |||||
checkRepeatingRowsAndColumns(sheet1, null, null); | |||||
sheet1.setRepeatingRows(CellRangeAddress.valueOf("4:5")); | |||||
sheet2.setRepeatingColumns(CellRangeAddress.valueOf("A:C")); | |||||
sheet3.setRepeatingRows(CellRangeAddress.valueOf("1:4")); | |||||
sheet3.setRepeatingColumns(CellRangeAddress.valueOf("A:A")); | |||||
checkRepeatingRowsAndColumns(sheet1, "4:5", null); | |||||
checkRepeatingRowsAndColumns(sheet2, null, "A:C"); | |||||
checkRepeatingRowsAndColumns(sheet3, "1:4", "A:A"); | |||||
// write out, read back, and test refrain... | |||||
wb = _testDataProvider.writeOutAndReadBack(wb); | |||||
sheet1 = wb.getSheetAt(0); | |||||
sheet2 = wb.getSheetAt(1); | |||||
sheet3 = wb.getSheetAt(2); | |||||
checkRepeatingRowsAndColumns(sheet1, "4:5", null); | |||||
checkRepeatingRowsAndColumns(sheet2, null, "A:C"); | |||||
checkRepeatingRowsAndColumns(sheet3, "1:4", "A:A"); | |||||
// check removing repeating rows and columns | |||||
sheet3.setRepeatingRows(null); | |||||
checkRepeatingRowsAndColumns(sheet3, null, "A:A"); | |||||
sheet3.setRepeatingColumns(null); | |||||
checkRepeatingRowsAndColumns(sheet3, null, null); | |||||
} | } | ||||
private void checkRepeatingRowsAndColumns( | private void checkRepeatingRowsAndColumns( | ||||
Sheet s, String expectedRows, String expectedCols) { | Sheet s, String expectedRows, String expectedCols) { | ||||
if (expectedRows == null) { | |||||
assertNull(s.getRepeatingRows()); | |||||
} else { | |||||
assertEquals(expectedRows, s.getRepeatingRows().formatAsString()); | |||||
} | |||||
if (expectedCols == null) { | |||||
assertNull(s.getRepeatingColumns()); | |||||
} else { | |||||
assertEquals(expectedCols, s.getRepeatingColumns().formatAsString()); | |||||
} | |||||
} | |||||
public void testBaseZoom() { | |||||
if (expectedRows == null) { | |||||
assertNull(s.getRepeatingRows()); | |||||
} else { | |||||
assertEquals(expectedRows, s.getRepeatingRows().formatAsString()); | |||||
} | |||||
if (expectedCols == null) { | |||||
assertNull(s.getRepeatingColumns()); | |||||
} else { | |||||
assertEquals(expectedCols, s.getRepeatingColumns().formatAsString()); | |||||
} | |||||
} | |||||
@Test | |||||
public void baseZoom() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
sheet.setZoom(3,4); | sheet.setZoom(3,4); | ||||
} | } | ||||
public void testBaseShowInPane() { | |||||
@Test | |||||
public void baseShowInPane() { | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
sheet.showInPane(2, 3); | sheet.showInPane(2, 3); | ||||
} | } | ||||
public void testBug55723(){ | |||||
@Test | |||||
public void bug55723(){ | |||||
Workbook wb = _testDataProvider.createWorkbook(); | Workbook wb = _testDataProvider.createWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
// there seems to be currently no generic way to check the setting... | // there seems to be currently no generic way to check the setting... | ||||
} | } | ||||
public void testBug55723_Rows() { | |||||
@Test | |||||
public void bug55723_Rows() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||
assertNotNull(filter); | assertNotNull(filter); | ||||
} | } | ||||
public void testBug55723d_RowsOver65k() { | |||||
@Test | |||||
public void bug55723d_RowsOver65k() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | HSSFWorkbook wb = new HSSFWorkbook(); | ||||
Sheet sheet = wb.createSheet(); | Sheet sheet = wb.createSheet(); | ||||