Commit patch from Paolo <p.mottadelli@sourcesense.com> attached to bug #44319.
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@616303 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2d33f4190a
commit
9ce000ac3a
@ -32,13 +32,18 @@ import org.apache.poi.ss.usermodel.PrintSetup;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
|
||||
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.CTRow;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||
@ -50,6 +55,13 @@ public class XSSFSheet implements Sheet {
|
||||
private CTWorksheet worksheet;
|
||||
private List<Row> rows;
|
||||
private ColumnHelper columnHelper;
|
||||
|
||||
public static final short LeftMargin = 0;
|
||||
public static final short RightMargin = 1;
|
||||
public static final short TopMargin = 2;
|
||||
public static final short BottomMargin = 3;
|
||||
public static final short HeaderMargin = 4;
|
||||
public static final short FooterMargin = 5;
|
||||
|
||||
public XSSFSheet(CTSheet sheet) {
|
||||
this.sheet = sheet;
|
||||
@ -86,6 +98,11 @@ public class XSSFSheet implements Sheet {
|
||||
CTHeaderFooter hf = this.worksheet.addNewHeaderFooter();
|
||||
hf.setOddHeader("&C&A");
|
||||
hf.setOddFooter("&C&\"Arial\"&10Page &P");
|
||||
CTPageBreak rowBreaks = worksheet.addNewRowBreaks();
|
||||
CTPageBreak columnBreak = worksheet.addNewColBreaks();
|
||||
CTSheetPr sheetPr = worksheet.addNewSheetPr();
|
||||
CTPageSetUpPr sheetPageSetUpPr = sheetPr.addNewPageSetUpPr();
|
||||
CTPageMargins pageMargins = worksheet.addNewPageMargins();
|
||||
columnHelper = new ColumnHelper(worksheet);
|
||||
}
|
||||
|
||||
@ -172,8 +189,7 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public boolean getAutobreaks() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return worksheet.getSheetPr().getPageSetUpPr().getAutoPageBreaks();
|
||||
}
|
||||
|
||||
public Comment getCellComment(int row, int column) {
|
||||
@ -182,24 +198,32 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public short[] getColumnBreaks() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
CTBreak[] brkArray = worksheet.getColBreaks().getBrkArray();
|
||||
if (brkArray.length == 0) {
|
||||
return null;
|
||||
}
|
||||
short[] breaks = new short[brkArray.length];
|
||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
||||
CTBreak brk = brkArray[i];
|
||||
breaks[i] = (short) brk.getId();
|
||||
}
|
||||
return breaks;
|
||||
}
|
||||
|
||||
public short getColumnWidth(short column) {
|
||||
return (short) columnHelper.getColumn(column).getWidth();
|
||||
return (short) columnHelper.getColumn(column).getWidth();
|
||||
}
|
||||
|
||||
public short getDefaultColumnWidth() {
|
||||
return (short) this.worksheet.getSheetFormatPr().getDefaultColWidth();
|
||||
return (short) this.worksheet.getSheetFormatPr().getDefaultColWidth();
|
||||
}
|
||||
|
||||
public short getDefaultRowHeight() {
|
||||
return (short) (this.worksheet.getSheetFormatPr().getDefaultRowHeight() * 20);
|
||||
return (short) (this.worksheet.getSheetFormatPr().getDefaultRowHeight() * 20);
|
||||
}
|
||||
|
||||
public float getDefaultRowHeightInPoints() {
|
||||
return (short) this.worksheet.getSheetFormatPr().getDefaultRowHeight();
|
||||
return (short) this.worksheet.getSheetFormatPr().getDefaultRowHeight();
|
||||
}
|
||||
|
||||
public boolean getDialog() {
|
||||
@ -213,13 +237,17 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public int getFirstRowNum() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
|
||||
Row row = it.next();
|
||||
if (row != null) {
|
||||
return row.getRowNum();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean getFitToPage() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return worksheet.getSheetPr().getPageSetUpPr().getFitToPage();
|
||||
}
|
||||
|
||||
public Footer getFooter() {
|
||||
@ -238,8 +266,14 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public int getLastRowNum() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
int lastRowNum = -1;
|
||||
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
|
||||
Row row = it.next();
|
||||
if (row != null) {
|
||||
lastRowNum = row.getRowNum();
|
||||
}
|
||||
}
|
||||
return lastRowNum;
|
||||
}
|
||||
|
||||
public short getLeftCol() {
|
||||
@ -248,8 +282,23 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public double getMargin(short margin) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
CTPageMargins pageMargins = worksheet.getPageMargins();
|
||||
switch (margin) {
|
||||
case LeftMargin:
|
||||
return pageMargins.getLeft();
|
||||
case RightMargin:
|
||||
return pageMargins.getRight();
|
||||
case TopMargin:
|
||||
return pageMargins.getTop();
|
||||
case BottomMargin:
|
||||
return pageMargins.getBottom();
|
||||
case HeaderMargin:
|
||||
return pageMargins.getHeader();
|
||||
case FooterMargin:
|
||||
return pageMargins.getFooter();
|
||||
default :
|
||||
throw new RuntimeException( "Unknown margin constant: " + margin );
|
||||
}
|
||||
}
|
||||
|
||||
public Region getMergedRegionAt(int index) {
|
||||
@ -278,8 +327,13 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public int getPhysicalNumberOfRows() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
int counter = 0;
|
||||
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
|
||||
if (it.next() != null) {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
public PrintSetup getPrintSetup() {
|
||||
@ -303,8 +357,17 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public int[] getRowBreaks() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
CTPageBreak rowBreaks = worksheet.getRowBreaks();
|
||||
int breaksCount = rowBreaks.getBrkArray().length;
|
||||
if (breaksCount == 0) {
|
||||
return null;
|
||||
}
|
||||
int[] breaks = new int[breaksCount];
|
||||
for (int i = 0 ; i < breaksCount ; i++) {
|
||||
CTBreak brk = rowBreaks.getBrkArray(i);
|
||||
breaks[i] = (int) brk.getId();
|
||||
}
|
||||
return breaks;
|
||||
}
|
||||
|
||||
public boolean getRowSumsBelow() {
|
||||
@ -343,13 +406,17 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public boolean isColumnBroken(short column) {
|
||||
// TODO Auto-generated method stub
|
||||
CTBreak[] brkArray = worksheet.getColBreaks().getBrkArray();
|
||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
||||
if (brkArray[i].getId() == column) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isColumnHidden(short column) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return columnHelper.getColumn(column).getHidden();
|
||||
}
|
||||
|
||||
public boolean isDisplayFormulas() {
|
||||
@ -378,7 +445,15 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public boolean isRowBroken(int row) {
|
||||
// TODO Auto-generated method stub
|
||||
int[] rowBreaks = getRowBreaks();
|
||||
if (rowBreaks == null) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0 ; i < rowBreaks.length ; i++) {
|
||||
if (rowBreaks[i] == row) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -388,8 +463,13 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public void removeColumnBreak(short column) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
CTBreak[] brkArray = worksheet.getColBreaks().getBrkArray();
|
||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
||||
if (brkArray[i].getId() == column) {
|
||||
worksheet.getColBreaks().removeBrk(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeMergedRegion(int index) {
|
||||
@ -398,13 +478,25 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public void removeRow(Row row) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
int counter = 0;
|
||||
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
|
||||
Row r = it.next();
|
||||
if (r.getRowNum() == row.getRowNum()) {
|
||||
it.remove();
|
||||
worksheet.getSheetData().removeRow(counter);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeRowBreak(int row) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
CTBreak[] brkArray = worksheet.getRowBreaks().getBrkArray();
|
||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
||||
if (brkArray[i].getId() == row) {
|
||||
worksheet.getRowBreaks().removeBrk(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<Row> rowIterator() {
|
||||
@ -422,13 +514,14 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public void setAutobreaks(boolean b) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
worksheet.getSheetPr().getPageSetUpPr().setAutoPageBreaks(b);
|
||||
}
|
||||
|
||||
public void setColumnBreak(short column) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
if (! isColumnBroken(column)) {
|
||||
CTBreak brk = worksheet.getColBreaks().addNewBrk();
|
||||
brk.setId(column);
|
||||
}
|
||||
}
|
||||
|
||||
public void setColumnGroupCollapsed(short columnNumber, boolean collapsed) {
|
||||
@ -437,16 +530,19 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public void setColumnHidden(short column, boolean hidden) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
CTCol col = columnHelper.getColumn(column);
|
||||
if (col == null) {
|
||||
col = columnHelper.createColumn(column);
|
||||
}
|
||||
col.setHidden(hidden);
|
||||
}
|
||||
|
||||
public void setColumnWidth(short column, short width) {
|
||||
CTCol col = columnHelper.getColumn(column);
|
||||
if (col == null) {
|
||||
col = columnHelper.createColumn(column);
|
||||
}
|
||||
col.setWidth(width);
|
||||
CTCol col = columnHelper.getColumn(column);
|
||||
if (col == null) {
|
||||
col = columnHelper.createColumn(column);
|
||||
}
|
||||
col.setWidth(width);
|
||||
}
|
||||
|
||||
public void setDefaultColumnStyle(short column, CellStyle style) {
|
||||
@ -455,16 +551,16 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public void setDefaultColumnWidth(short width) {
|
||||
this.worksheet.getSheetFormatPr().setDefaultColWidth((double) width);
|
||||
this.worksheet.getSheetFormatPr().setDefaultColWidth((double) width);
|
||||
}
|
||||
|
||||
public void setDefaultRowHeight(short height) {
|
||||
this.worksheet.getSheetFormatPr().setDefaultRowHeight(height / 20);
|
||||
this.worksheet.getSheetFormatPr().setDefaultRowHeight(height / 20);
|
||||
|
||||
}
|
||||
|
||||
public void setDefaultRowHeightInPoints(float height) {
|
||||
this.worksheet.getSheetFormatPr().setDefaultRowHeight(height);
|
||||
this.worksheet.getSheetFormatPr().setDefaultRowHeight(height);
|
||||
|
||||
}
|
||||
|
||||
@ -494,8 +590,7 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public void setFitToPage(boolean b) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
worksheet.getSheetPr().getPageSetUpPr().setFitToPage(b);
|
||||
}
|
||||
|
||||
public void setGridsPrinted(boolean value) {
|
||||
@ -509,8 +604,21 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public void setMargin(short margin, double size) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
CTPageMargins pageMargins = worksheet.getPageMargins();
|
||||
switch (margin) {
|
||||
case LeftMargin:
|
||||
pageMargins.setLeft(size);
|
||||
case RightMargin:
|
||||
pageMargins.setRight(size);
|
||||
case TopMargin:
|
||||
pageMargins.setTop(size);
|
||||
case BottomMargin:
|
||||
pageMargins.setBottom(size);
|
||||
case HeaderMargin:
|
||||
pageMargins.setHeader(size);
|
||||
case FooterMargin:
|
||||
pageMargins.setFooter(size);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPrintGridlines(boolean newPrintGridlines) {
|
||||
@ -524,8 +632,11 @@ public class XSSFSheet implements Sheet {
|
||||
}
|
||||
|
||||
public void setRowBreak(int row) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
CTPageBreak pageBreak = worksheet.getRowBreaks();
|
||||
if (! isRowBroken(row)) {
|
||||
CTBreak brk = pageBreak.addNewBrk();
|
||||
brk.setId(row);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRowGroupCollapsed(int row, boolean collapse) {
|
||||
|
@ -27,96 +27,244 @@ import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class TestXSSFSheet extends TestCase {
|
||||
|
||||
public void testRowIterator() throws Exception {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
Row row1 = sheet.createRow(0);
|
||||
Row row2 = sheet.createRow(1);
|
||||
Iterator<Row> it = sheet.rowIterator();
|
||||
assertNotNull(it);
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(row1, it.next());
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(row2, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
public void testGetRow() throws Exception {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
Row row1 = sheet.createRow(0);
|
||||
Cell cell = row1.createCell((short) 0);
|
||||
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
|
||||
cell.setCellValue((double) 1000);
|
||||
|
||||
// Test getting a row and check its cell's value
|
||||
Row row_got = sheet.getRow(0);
|
||||
Cell cell_got = row_got.getCell((short) 0);
|
||||
assertEquals((double) 1000, cell_got.getNumericCellValue());
|
||||
}
|
||||
|
||||
public void testCreateRow() throws Exception {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
|
||||
// Test row creation with consecutive indexes
|
||||
Row row1 = sheet.createRow(0);
|
||||
Row row2 = sheet.createRow(1);
|
||||
assertEquals(0, row1.getRowNum());
|
||||
Iterator<Row> it = sheet.rowIterator();
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(row1, it.next());
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(row2, it.next());
|
||||
|
||||
// Test row creation with non consecutive index
|
||||
Row row101 = sheet.createRow(100);
|
||||
assertNotNull(row101);
|
||||
|
||||
// Test overwriting an existing row
|
||||
Row row2_ovrewritten = sheet.createRow(1);
|
||||
Cell cell = row2_ovrewritten.createCell((short) 0);
|
||||
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
|
||||
cell.setCellValue((double) 100);
|
||||
Iterator<Row> it2 = sheet.rowIterator();
|
||||
assertTrue(it2.hasNext());
|
||||
assertEquals(row1, it2.next());
|
||||
assertTrue(it2.hasNext());
|
||||
Row row2_overwritten_copy = it2.next();
|
||||
assertEquals(row2_ovrewritten, row2_overwritten_copy);
|
||||
assertEquals(row2_overwritten_copy.getCell((short) 0).getNumericCellValue(), (double) 100);
|
||||
}
|
||||
|
||||
public void testGetSetDefaultRowHeight() throws Exception {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
// Test that default height set by the constructor
|
||||
assertEquals((short) 300, sheet.getDefaultRowHeight());
|
||||
assertEquals((float) 15, sheet.getDefaultRowHeightInPoints());
|
||||
// Set a new default row height in twips and test getting the value in points
|
||||
sheet.setDefaultRowHeight((short) 360);
|
||||
assertEquals((float) 18, sheet.getDefaultRowHeightInPoints());
|
||||
// Set a new default row height in points and test getting the value in twips
|
||||
sheet.setDefaultRowHeightInPoints((short) 17);
|
||||
assertEquals((short) 340, sheet.getDefaultRowHeight());
|
||||
}
|
||||
|
||||
public void testGetSetDefaultColumnWidth() throws Exception {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
// Test that default column width set by the constructor
|
||||
assertEquals((short) 13, sheet.getDefaultColumnWidth());
|
||||
// Set a new default column width and get its value
|
||||
sheet.setDefaultColumnWidth((short) 14);
|
||||
assertEquals((short) 14, sheet.getDefaultColumnWidth());
|
||||
}
|
||||
|
||||
public void testGetSetColumnWidth() throws Exception {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
// Test setting a column width and getting that value
|
||||
sheet.setColumnWidth((short) 0, (short) 16);
|
||||
assertEquals(16, sheet.getColumnWidth((short) 0));
|
||||
}
|
||||
|
||||
public void testRowIterator() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
Row row1 = sheet.createRow(0);
|
||||
Row row2 = sheet.createRow(1);
|
||||
Iterator<Row> it = sheet.rowIterator();
|
||||
assertNotNull(it);
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(row1, it.next());
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(row2, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
}
|
||||
|
||||
public void testGetRow() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
Row row1 = sheet.createRow(0);
|
||||
Cell cell = row1.createCell((short) 0);
|
||||
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
|
||||
cell.setCellValue((double) 1000);
|
||||
|
||||
// Test getting a row and check its cell's value
|
||||
Row row_got = sheet.getRow(0);
|
||||
Cell cell_got = row_got.getCell((short) 0);
|
||||
assertEquals((double) 1000, cell_got.getNumericCellValue());
|
||||
}
|
||||
|
||||
public void testCreateRow() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
|
||||
// Test row creation with consecutive indexes
|
||||
Row row1 = sheet.createRow(0);
|
||||
Row row2 = sheet.createRow(1);
|
||||
assertEquals(0, row1.getRowNum());
|
||||
assertEquals(1, row2.getRowNum());
|
||||
Iterator<Row> it = sheet.rowIterator();
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(row1, it.next());
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(row2, it.next());
|
||||
|
||||
// Test row creation with non consecutive index
|
||||
Row row101 = sheet.createRow(100);
|
||||
assertNotNull(row101);
|
||||
|
||||
// Test overwriting an existing row
|
||||
Row row2_ovrewritten = sheet.createRow(1);
|
||||
Cell cell = row2_ovrewritten.createCell((short) 0);
|
||||
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
|
||||
cell.setCellValue((double) 100);
|
||||
Iterator<Row> it2 = sheet.rowIterator();
|
||||
assertTrue(it2.hasNext());
|
||||
assertEquals(row1, it2.next());
|
||||
assertTrue(it2.hasNext());
|
||||
Row row2_overwritten_copy = it2.next();
|
||||
assertEquals(row2_ovrewritten, row2_overwritten_copy);
|
||||
assertEquals(row2_overwritten_copy.getCell((short) 0).getNumericCellValue(), (double) 100);
|
||||
}
|
||||
|
||||
public void testRemoveRow() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
Row row1 = sheet.createRow(1);
|
||||
Row row2 = sheet.createRow(2);
|
||||
assertNotNull(sheet.getRow(1));
|
||||
sheet.removeRow(row2);
|
||||
assertNull(sheet.getRow(0));
|
||||
assertNull(sheet.getRow(2));
|
||||
assertNotNull(sheet.getRow(1));
|
||||
}
|
||||
|
||||
public void testGetSetDefaultRowHeight() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
// Test that default height set by the constructor
|
||||
assertEquals((short) 300, sheet.getDefaultRowHeight());
|
||||
assertEquals((float) 15, sheet.getDefaultRowHeightInPoints());
|
||||
// Set a new default row height in twips and test getting the value in points
|
||||
sheet.setDefaultRowHeight((short) 360);
|
||||
assertEquals((float) 18, sheet.getDefaultRowHeightInPoints());
|
||||
// Set a new default row height in points and test getting the value in twips
|
||||
sheet.setDefaultRowHeightInPoints((short) 17);
|
||||
assertEquals((short) 340, sheet.getDefaultRowHeight());
|
||||
}
|
||||
|
||||
public void testGetSetDefaultColumnWidth() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
// Test that default column width set by the constructor
|
||||
assertEquals((short) 13, sheet.getDefaultColumnWidth());
|
||||
// Set a new default column width and get its value
|
||||
sheet.setDefaultColumnWidth((short) 14);
|
||||
assertEquals((short) 14, sheet.getDefaultColumnWidth());
|
||||
}
|
||||
|
||||
public void testGetSetColumnWidth() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
// Test setting a column width and getting that value
|
||||
sheet.setColumnWidth((short) 0, (short) 16);
|
||||
assertEquals(16, sheet.getColumnWidth((short) 0));
|
||||
}
|
||||
|
||||
public void testGetFirstLastRowNum() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
Row row10 = sheet.createRow(9);
|
||||
Row row1 = sheet.createRow(0);
|
||||
Row row2 = sheet.createRow(1);
|
||||
assertEquals(0, sheet.getFirstRowNum());
|
||||
assertEquals(9, sheet.getLastRowNum());
|
||||
}
|
||||
|
||||
public void testGetPhysicalNumberOfRows() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
Row row10 = sheet.createRow(9);
|
||||
Row row1 = sheet.createRow(0);
|
||||
Row row2 = sheet.createRow(1);
|
||||
assertEquals(3, sheet.getPhysicalNumberOfRows());
|
||||
}
|
||||
|
||||
public void testGetSetRowBreaks() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
assertNull(sheet.getRowBreaks());
|
||||
sheet.setRowBreak(1);
|
||||
sheet.setRowBreak(15);
|
||||
assertNotNull(sheet.getRowBreaks());
|
||||
assertEquals(1, sheet.getRowBreaks()[0]);
|
||||
assertEquals(15, sheet.getRowBreaks()[1]);
|
||||
sheet.setRowBreak(1);
|
||||
assertEquals(2, sheet.getRowBreaks().length);
|
||||
}
|
||||
|
||||
public void testRemoveRowBreak() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
sheet.setRowBreak(1);
|
||||
assertEquals(1, sheet.getRowBreaks().length);
|
||||
sheet.setRowBreak(2);
|
||||
assertEquals(2, sheet.getRowBreaks().length);
|
||||
sheet.removeRowBreak(1);
|
||||
assertEquals(1, sheet.getRowBreaks().length);
|
||||
}
|
||||
|
||||
public void testGetSetColumnBreaks() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
assertNull(sheet.getColumnBreaks());
|
||||
sheet.setColumnBreak((short) 11);
|
||||
assertNotNull(sheet.getColumnBreaks());
|
||||
assertEquals(11, sheet.getColumnBreaks()[0]);
|
||||
sheet.setColumnBreak((short) 11223);
|
||||
assertEquals(2, sheet.getColumnBreaks().length);
|
||||
}
|
||||
|
||||
public void testRemoveColumnBreak() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
assertNull(sheet.getColumnBreaks());
|
||||
sheet.setColumnBreak((short) 11);
|
||||
assertNotNull(sheet.getColumnBreaks());
|
||||
sheet.setColumnBreak((short) 12);
|
||||
assertEquals(2, sheet.getColumnBreaks().length);
|
||||
sheet.removeColumnBreak((short) 11);
|
||||
assertEquals(1, sheet.getColumnBreaks().length);
|
||||
sheet.removeColumnBreak((short) 15);
|
||||
assertEquals(1, sheet.getColumnBreaks().length);
|
||||
}
|
||||
|
||||
public void testIsRowColumnBroken() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
assertFalse(sheet.isRowBroken(0));
|
||||
sheet.setRowBreak(3);
|
||||
assertTrue(sheet.isRowBroken(3));
|
||||
assertFalse(sheet.isColumnBroken((short) 0));
|
||||
sheet.setColumnBreak((short) 3);
|
||||
assertTrue(sheet.isColumnBroken((short) 3));
|
||||
}
|
||||
|
||||
public void testGetSetAutoBreaks() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
assertTrue(sheet.getAutobreaks());
|
||||
sheet.setAutobreaks(false);
|
||||
assertFalse(sheet.getAutobreaks());
|
||||
}
|
||||
|
||||
public void testIsSetColumnHidden() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
sheet.setColumnWidth((short) 0, (short) 13);
|
||||
sheet.setColumnHidden((short) 1, false);
|
||||
sheet.setColumnHidden((short) 2, true);
|
||||
assertFalse(sheet.isColumnHidden((short) 0));
|
||||
assertFalse(sheet.isColumnHidden((short) 1));
|
||||
assertTrue(sheet.isColumnHidden((short) 2));
|
||||
}
|
||||
|
||||
public void testIsSetFitToPage() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
assertFalse(sheet.getFitToPage());
|
||||
sheet.setFitToPage(true);
|
||||
assertTrue(sheet.getFitToPage());
|
||||
sheet.setFitToPage(false);
|
||||
assertFalse(sheet.getFitToPage());
|
||||
}
|
||||
|
||||
public void testGetSetMargin() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
assertEquals((double) 0, sheet.getMargin((short) 0));
|
||||
sheet.setMargin((short) 0, 10);
|
||||
sheet.setMargin((short) 1, 11);
|
||||
sheet.setMargin((short) 2, 12);
|
||||
sheet.setMargin((short) 3, 13);
|
||||
sheet.setMargin((short) 4, 14);
|
||||
sheet.setMargin((short) 5, 15);
|
||||
assertEquals((double) 10, sheet.getMargin((short) 0));
|
||||
assertEquals((double) 11, sheet.getMargin((short) 1));
|
||||
assertEquals((double) 12, sheet.getMargin((short) 2));
|
||||
assertEquals((double) 13, sheet.getMargin((short) 3));
|
||||
assertEquals((double) 14, sheet.getMargin((short) 4));
|
||||
assertEquals((double) 15, sheet.getMargin((short) 5));
|
||||
|
||||
// Test that nothing happens if another margin constant is given (E.G. 65)
|
||||
sheet.setMargin((short) 65, 15);
|
||||
assertEquals((double) 10, sheet.getMargin((short) 0));
|
||||
assertEquals((double) 11, sheet.getMargin((short) 1));
|
||||
assertEquals((double) 12, sheet.getMargin((short) 2));
|
||||
assertEquals((double) 13, sheet.getMargin((short) 3));
|
||||
assertEquals((double) 14, sheet.getMargin((short) 4));
|
||||
assertEquals((double) 15, sheet.getMargin((short) 5));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user