mirror of https://github.com/apache/poi.git
Applied patches for #44480, thanks to Paolo Mottadelli <p.mottadelli@sourcesense.com>, <paolo.moz@gmail.com>
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@632325 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3e92b80e9d
commit
cedd473b59
|
@ -0,0 +1,108 @@
|
|||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.xssf.usermodel;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
|
||||
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.CTPrintOptions;
|
||||
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.CTSheetProtection;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
|
||||
|
||||
public class XSSFDialogsheet extends XSSFSheet implements Sheet{
|
||||
|
||||
public XSSFDialogsheet(CTSheet sheet, CTDialogsheet dialogsheet,
|
||||
XSSFWorkbook workbook) {
|
||||
super(sheet, null, workbook);
|
||||
this.worksheet = null;
|
||||
this.dialogsheet = dialogsheet;
|
||||
if (this.dialogsheet == null) {
|
||||
this.dialogsheet = CTDialogsheet.Factory.newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
public Row createRow(int rowNum) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected CTHeaderFooter getSheetTypeHeaderFooter() {
|
||||
if (dialogsheet.getHeaderFooter() == null) {
|
||||
dialogsheet.setHeaderFooter(CTHeaderFooter.Factory.newInstance());
|
||||
}
|
||||
return dialogsheet.getHeaderFooter();
|
||||
}
|
||||
|
||||
protected CTSheetPr getSheetTypeSheetPr() {
|
||||
if (dialogsheet.getSheetPr() == null) {
|
||||
dialogsheet.setSheetPr(CTSheetPr.Factory.newInstance());
|
||||
}
|
||||
return dialogsheet.getSheetPr();
|
||||
}
|
||||
|
||||
protected CTPageBreak getSheetTypeColumnBreaks() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected CTSheetFormatPr getSheetTypeSheetFormatPr() {
|
||||
if (dialogsheet.getSheetFormatPr() == null) {
|
||||
dialogsheet.setSheetFormatPr(CTSheetFormatPr.Factory.newInstance());
|
||||
}
|
||||
return dialogsheet.getSheetFormatPr();
|
||||
}
|
||||
|
||||
protected CTPageMargins getSheetTypePageMargins() {
|
||||
if (dialogsheet.getPageMargins() == null) {
|
||||
dialogsheet.setPageMargins(CTPageMargins.Factory.newInstance());
|
||||
}
|
||||
return dialogsheet.getPageMargins();
|
||||
}
|
||||
|
||||
protected CTPageBreak getSheetTypeRowBreaks() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected CTSheetViews getSheetTypeSheetViews() {
|
||||
if (dialogsheet.getSheetViews() == null) {
|
||||
dialogsheet.setSheetViews(CTSheetViews.Factory.newInstance());
|
||||
dialogsheet.getSheetViews().addNewSheetView();
|
||||
}
|
||||
return dialogsheet.getSheetViews();
|
||||
}
|
||||
|
||||
protected CTPrintOptions getSheetTypePrintOptions() {
|
||||
if (dialogsheet.getPrintOptions() == null) {
|
||||
dialogsheet.setPrintOptions(CTPrintOptions.Factory.newInstance());
|
||||
}
|
||||
return dialogsheet.getPrintOptions();
|
||||
}
|
||||
|
||||
protected CTSheetProtection getSheetTypeProtection() {
|
||||
if (dialogsheet.getSheetProtection() == null) {
|
||||
dialogsheet.setSheetProtection(CTSheetProtection.Factory.newInstance());
|
||||
}
|
||||
return dialogsheet.getSheetProtection();
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package org.apache.poi.xssf.usermodel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -29,21 +28,23 @@ import org.apache.poi.ss.usermodel.Comment;
|
|||
import org.apache.poi.ss.usermodel.Footer;
|
||||
import org.apache.poi.ss.usermodel.Header;
|
||||
import org.apache.poi.ss.usermodel.Patriarch;
|
||||
import org.apache.poi.ss.usermodel.PictureData;
|
||||
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.apache.poi.xssf.util.CellReference;
|
||||
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.CTDialogsheet;
|
||||
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.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.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.CTWorksheet;
|
||||
|
@ -51,11 +52,12 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
|||
|
||||
public class XSSFSheet implements Sheet {
|
||||
|
||||
private CTSheet sheet;
|
||||
private CTWorksheet worksheet;
|
||||
private List<Row> rows;
|
||||
private ColumnHelper columnHelper;
|
||||
private XSSFWorkbook workbook;
|
||||
protected CTSheet sheet;
|
||||
protected CTWorksheet worksheet;
|
||||
protected CTDialogsheet dialogsheet;
|
||||
protected List<Row> rows;
|
||||
protected ColumnHelper columnHelper;
|
||||
protected XSSFWorkbook workbook;
|
||||
|
||||
public static final short LeftMargin = 0;
|
||||
public static final short RightMargin = 1;
|
||||
|
@ -63,56 +65,20 @@ public class XSSFSheet implements Sheet {
|
|||
public static final short BottomMargin = 3;
|
||||
public static final short HeaderMargin = 4;
|
||||
public static final short FooterMargin = 5;
|
||||
|
||||
public XSSFSheet(CTSheet sheet, XSSFWorkbook workbook) {
|
||||
this.sheet = sheet;
|
||||
this.worksheet = CTWorksheet.Factory.newInstance();
|
||||
this.workbook = workbook;
|
||||
this.worksheet.addNewSheetData();
|
||||
initRows(worksheet);
|
||||
|
||||
this.worksheet.addNewHeaderFooter();
|
||||
worksheet.addNewRowBreaks();
|
||||
worksheet.addNewColBreaks();
|
||||
CTSheetPr sheetPr = worksheet.addNewSheetPr();
|
||||
sheetPr.addNewPageSetUpPr();
|
||||
worksheet.addNewPageMargins();
|
||||
|
||||
// XXX Initial default data, probably useful only for testing. Review and eliminate if necessary.
|
||||
CTSheetViews views = this.worksheet.addNewSheetViews();
|
||||
CTSheetView view = views.addNewSheetView();
|
||||
view.setWorkbookViewId(0);
|
||||
view.setZoomScale(100);
|
||||
CTSelection selection = view.addNewSelection();
|
||||
selection.setActiveCell("A1");
|
||||
CTSheetFormatPr format = this.worksheet.addNewSheetFormatPr();
|
||||
format.setDefaultColWidth(13);
|
||||
format.setDefaultRowHeight(15);
|
||||
format.setCustomHeight(true);
|
||||
CTCols cols = this.worksheet.addNewCols();
|
||||
CTCol col = cols.addNewCol();
|
||||
col.setMin(1);
|
||||
col.setMax(2);
|
||||
col.setWidth(13);
|
||||
col.setCustomWidth(true);
|
||||
for (int i = 3 ; i < 5 ; ++i) {
|
||||
col = cols.addNewCol();
|
||||
col.setMin(i);
|
||||
col.setMax(i);
|
||||
col.setWidth(13);
|
||||
col.setCustomWidth(true);
|
||||
}
|
||||
|
||||
initColumns(worksheet);
|
||||
}
|
||||
|
||||
public XSSFSheet(CTSheet sheet, CTWorksheet worksheet, XSSFWorkbook workbook) {
|
||||
public XSSFSheet(CTSheet sheet, CTWorksheet worksheet, XSSFWorkbook workbook) {
|
||||
this.workbook = workbook;
|
||||
this.sheet = sheet;
|
||||
this.worksheet = worksheet;
|
||||
this.workbook = workbook;
|
||||
initRows(worksheet);
|
||||
initColumns(worksheet);
|
||||
}
|
||||
if (this.worksheet == null) {
|
||||
this.worksheet = CTWorksheet.Factory.newInstance();
|
||||
}
|
||||
if (this.worksheet.getSheetData() == null) {
|
||||
this.worksheet.addNewSheetData();
|
||||
}
|
||||
initRows(this.worksheet);
|
||||
initColumns(this.worksheet);
|
||||
}
|
||||
|
||||
public XSSFSheet(XSSFWorkbook workbook) {
|
||||
this.workbook = workbook;
|
||||
|
@ -121,15 +87,23 @@ public class XSSFSheet implements Sheet {
|
|||
public XSSFWorkbook getWorkbook() {
|
||||
return this.workbook;
|
||||
}
|
||||
|
||||
protected CTWorksheet getWorksheet() {
|
||||
return this.worksheet;
|
||||
}
|
||||
|
||||
public ColumnHelper getColumnHelper() {
|
||||
return columnHelper;
|
||||
}
|
||||
|
||||
private void initRows(CTWorksheet worksheet) {
|
||||
protected void initRows(CTWorksheet worksheet) {
|
||||
this.rows = new LinkedList<Row>();
|
||||
for (CTRow row : worksheet.getSheetData().getRowArray()) {
|
||||
this.rows.add(new XSSFRow(row, this));
|
||||
}
|
||||
}
|
||||
|
||||
private void initColumns(CTWorksheet worksheet) {
|
||||
protected void initColumns(CTWorksheet worksheet) {
|
||||
columnHelper = new ColumnHelper(worksheet);
|
||||
}
|
||||
|
||||
|
@ -137,18 +111,13 @@ public class XSSFSheet implements Sheet {
|
|||
return this.sheet;
|
||||
}
|
||||
|
||||
protected CTWorksheet getWorksheet() {
|
||||
return this.worksheet;
|
||||
}
|
||||
|
||||
public int addMergedRegion(Region region) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void autoSizeColumn(short column) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
columnHelper.setColBestFit(column, true);
|
||||
}
|
||||
|
||||
public Patriarch createDrawingPatriarch() {
|
||||
|
@ -215,16 +184,30 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public boolean getAutobreaks() {
|
||||
return worksheet.getSheetPr().getPageSetUpPr().getAutoPageBreaks();
|
||||
return getSheetTypePageSetUpPr().getAutoPageBreaks();
|
||||
}
|
||||
|
||||
private CTPageSetUpPr getSheetTypePageSetUpPr() {
|
||||
if (getSheetTypeSheetPr().getPageSetUpPr() == null) {
|
||||
getSheetTypeSheetPr().setPageSetUpPr(CTPageSetUpPr.Factory.newInstance());
|
||||
}
|
||||
return getSheetTypeSheetPr().getPageSetUpPr();
|
||||
}
|
||||
|
||||
protected CTSheetPr getSheetTypeSheetPr() {
|
||||
if (worksheet.getSheetPr() == null) {
|
||||
worksheet.setSheetPr(CTSheetPr.Factory.newInstance());
|
||||
}
|
||||
return worksheet.getSheetPr();
|
||||
}
|
||||
|
||||
public Comment getCellComment(int row, int column) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public short[] getColumnBreaks() {
|
||||
CTBreak[] brkArray = worksheet.getColBreaks().getBrkArray();
|
||||
CTBreak[] brkArray = getSheetTypeColumnBreaks().getBrkArray();
|
||||
if (brkArray.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
@ -236,25 +219,41 @@ public class XSSFSheet implements Sheet {
|
|||
return breaks;
|
||||
}
|
||||
|
||||
protected CTPageBreak getSheetTypeColumnBreaks() {
|
||||
if (worksheet.getColBreaks() == null) {
|
||||
worksheet.setColBreaks(CTPageBreak.Factory.newInstance());
|
||||
}
|
||||
return worksheet.getColBreaks();
|
||||
}
|
||||
|
||||
public short getColumnWidth(short column) {
|
||||
return (short) columnHelper.getColumn(column).getWidth();
|
||||
}
|
||||
|
||||
public short getDefaultColumnWidth() {
|
||||
return (short) this.worksheet.getSheetFormatPr().getDefaultColWidth();
|
||||
return (short) getSheetTypeSheetFormatPr().getDefaultColWidth();
|
||||
}
|
||||
|
||||
public short getDefaultRowHeight() {
|
||||
return (short) (this.worksheet.getSheetFormatPr().getDefaultRowHeight() * 20);
|
||||
return (short) (getSheetTypeSheetFormatPr().getDefaultRowHeight() * 20);
|
||||
}
|
||||
|
||||
protected CTSheetFormatPr getSheetTypeSheetFormatPr() {
|
||||
if (worksheet.getSheetFormatPr() == null) {
|
||||
worksheet.setSheetFormatPr(CTSheetFormatPr.Factory.newInstance());
|
||||
}
|
||||
return worksheet.getSheetFormatPr();
|
||||
}
|
||||
|
||||
public float getDefaultRowHeightInPoints() {
|
||||
return (short) this.worksheet.getSheetFormatPr().getDefaultRowHeight();
|
||||
return (short) getSheetTypeSheetFormatPr().getDefaultRowHeight();
|
||||
}
|
||||
|
||||
public boolean getDialog() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
if (dialogsheet != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean getDisplayGuts() {
|
||||
|
@ -273,7 +272,7 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public boolean getFitToPage() {
|
||||
return worksheet.getSheetPr().getPageSetUpPr().getFitToPage();
|
||||
return getSheetTypePageSetUpPr().getFitToPage();
|
||||
}
|
||||
|
||||
public Footer getFooter() {
|
||||
|
@ -281,15 +280,22 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public Footer getOddFooter() {
|
||||
return new XSSFOddFooter(worksheet.getHeaderFooter());
|
||||
return new XSSFOddFooter(getSheetTypeHeaderFooter());
|
||||
}
|
||||
|
||||
protected CTHeaderFooter getSheetTypeHeaderFooter() {
|
||||
if (worksheet.getHeaderFooter() == null) {
|
||||
worksheet.setHeaderFooter(CTHeaderFooter.Factory.newInstance());
|
||||
}
|
||||
return worksheet.getHeaderFooter();
|
||||
}
|
||||
|
||||
public Footer getEvenFooter() {
|
||||
return new XSSFEvenFooter(worksheet.getHeaderFooter());
|
||||
return new XSSFEvenFooter(getSheetTypeHeaderFooter());
|
||||
}
|
||||
|
||||
public Footer getFirstFooter() {
|
||||
return new XSSFFirstFooter(worksheet.getHeaderFooter());
|
||||
return new XSSFFirstFooter(getSheetTypeHeaderFooter());
|
||||
}
|
||||
|
||||
public Header getHeader() {
|
||||
|
@ -297,23 +303,29 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public Header getOddHeader() {
|
||||
return new XSSFOddHeader(worksheet.getHeaderFooter());
|
||||
return new XSSFOddHeader(getSheetTypeHeaderFooter());
|
||||
}
|
||||
|
||||
public Header getEvenHeader() {
|
||||
return new XSSFEvenHeader(worksheet.getHeaderFooter()
|
||||
return new XSSFEvenHeader(getSheetTypeHeaderFooter()
|
||||
);
|
||||
}
|
||||
|
||||
public Header getFirstHeader() {
|
||||
return new XSSFFirstHeader(worksheet.getHeaderFooter());
|
||||
return new XSSFFirstHeader(getSheetTypeHeaderFooter());
|
||||
}
|
||||
|
||||
public boolean getHorizontallyCenter() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return getSheetTypePrintOptions().getHorizontalCentered();
|
||||
}
|
||||
|
||||
protected CTPrintOptions getSheetTypePrintOptions() {
|
||||
if (worksheet.getPrintOptions() == null) {
|
||||
worksheet.setPrintOptions(CTPrintOptions.Factory.newInstance());
|
||||
}
|
||||
return worksheet.getPrintOptions();
|
||||
}
|
||||
|
||||
public int getLastRowNum() {
|
||||
int lastRowNum = -1;
|
||||
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
|
||||
|
@ -326,12 +338,13 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public short getLeftCol() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
String cellRef = worksheet.getSheetViews().getSheetViewArray(0).getTopLeftCell();
|
||||
CellReference cellReference = new CellReference(cellRef);
|
||||
return cellReference.getCol();
|
||||
}
|
||||
|
||||
public double getMargin(short margin) {
|
||||
CTPageMargins pageMargins = worksheet.getPageMargins();
|
||||
CTPageMargins pageMargins = getSheetTypePageMargins();
|
||||
switch (margin) {
|
||||
case LeftMargin:
|
||||
return pageMargins.getLeft();
|
||||
|
@ -350,6 +363,13 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
}
|
||||
|
||||
protected CTPageMargins getSheetTypePageMargins() {
|
||||
if (worksheet.getPageMargins() == null) {
|
||||
worksheet.setPageMargins(CTPageMargins.Factory.newInstance());
|
||||
}
|
||||
return worksheet.getPageMargins();
|
||||
}
|
||||
|
||||
public Region getMergedRegionAt(int index) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
@ -406,7 +426,7 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public int[] getRowBreaks() {
|
||||
CTPageBreak rowBreaks = worksheet.getRowBreaks();
|
||||
CTPageBreak rowBreaks = getSheetTypeRowBreaks();
|
||||
int breaksCount = rowBreaks.getBrkArray().length;
|
||||
if (breaksCount == 0) {
|
||||
return null;
|
||||
|
@ -419,6 +439,13 @@ public class XSSFSheet implements Sheet {
|
|||
return breaks;
|
||||
}
|
||||
|
||||
protected CTPageBreak getSheetTypeRowBreaks() {
|
||||
if (worksheet.getRowBreaks() == null) {
|
||||
worksheet.setRowBreaks(CTPageBreak.Factory.newInstance());
|
||||
}
|
||||
return worksheet.getRowBreaks();
|
||||
}
|
||||
|
||||
public boolean getRowSumsBelow() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
|
@ -430,18 +457,29 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public boolean getScenarioProtect() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return getSheetTypeProtection().getScenarios();
|
||||
}
|
||||
|
||||
protected CTSheetProtection getSheetTypeProtection() {
|
||||
if (worksheet.getSheetProtection() == null) {
|
||||
worksheet.setSheetProtection(CTSheetProtection.Factory.newInstance());
|
||||
}
|
||||
return worksheet.getSheetProtection();
|
||||
}
|
||||
|
||||
public short getTopRow() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
String cellRef = getSheetTypeSheetView().getTopLeftCell();
|
||||
CellReference cellReference = new CellReference(cellRef);
|
||||
return (short) cellReference.getRow();
|
||||
}
|
||||
|
||||
// Right signature method. Remove the wrong one when it will be removed in HSSFSheet (and interface)
|
||||
public boolean getVerticallyCenter() {
|
||||
return getVerticallyCenter(true);
|
||||
}
|
||||
|
||||
public boolean getVerticallyCenter(boolean value) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return getSheetTypePrintOptions().getVerticalCentered();
|
||||
}
|
||||
|
||||
public void groupColumn(short fromColumn, short toColumn) {
|
||||
|
@ -455,7 +493,7 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public boolean isColumnBroken(short column) {
|
||||
CTBreak[] brkArray = worksheet.getColBreaks().getBrkArray();
|
||||
CTBreak[] brkArray = getSheetTypeColumnBreaks().getBrkArray();
|
||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
||||
if (brkArray[i].getId() == column) {
|
||||
return true;
|
||||
|
@ -469,28 +507,23 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public boolean isDisplayFormulas() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return getSheetTypeSheetView().getShowFormulas();
|
||||
}
|
||||
|
||||
public boolean isDisplayGridlines() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return getSheetTypeSheetView().getShowGridLines();
|
||||
}
|
||||
|
||||
public boolean isDisplayRowColHeadings() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return getSheetTypeSheetView().getShowRowColHeaders();
|
||||
}
|
||||
|
||||
public boolean isGridsPrinted() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return isPrintGridlines();
|
||||
}
|
||||
|
||||
public boolean isPrintGridlines() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return getSheetTypePrintOptions().getGridLines();
|
||||
}
|
||||
|
||||
public boolean isRowBroken(int row) {
|
||||
|
@ -512,10 +545,10 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public void removeColumnBreak(short column) {
|
||||
CTBreak[] brkArray = worksheet.getColBreaks().getBrkArray();
|
||||
CTBreak[] brkArray = getSheetTypeColumnBreaks().getBrkArray();
|
||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
||||
if (brkArray[i].getId() == column) {
|
||||
worksheet.getColBreaks().removeBrk(i);
|
||||
getSheetTypeColumnBreaks().removeBrk(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -539,10 +572,10 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public void removeRowBreak(int row) {
|
||||
CTBreak[] brkArray = worksheet.getRowBreaks().getBrkArray();
|
||||
CTBreak[] brkArray = getSheetTypeRowBreaks().getBrkArray();
|
||||
for (int i = 0 ; i < brkArray.length ; i++) {
|
||||
if (brkArray[i].getId() == row) {
|
||||
worksheet.getRowBreaks().removeBrk(i);
|
||||
getSheetTypeRowBreaks().removeBrk(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -570,12 +603,12 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public void setAutobreaks(boolean b) {
|
||||
worksheet.getSheetPr().getPageSetUpPr().setAutoPageBreaks(b);
|
||||
getSheetTypePageSetUpPr().setAutoPageBreaks(b);
|
||||
}
|
||||
|
||||
public void setColumnBreak(short column) {
|
||||
if (! isColumnBroken(column)) {
|
||||
CTBreak brk = worksheet.getColBreaks().addNewBrk();
|
||||
CTBreak brk = getSheetTypeColumnBreaks().addNewBrk();
|
||||
brk.setId(column);
|
||||
}
|
||||
}
|
||||
|
@ -586,11 +619,11 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public void setColumnHidden(short column, boolean hidden) {
|
||||
columnHelper.getColumn(column).setHidden(hidden);
|
||||
columnHelper.setColHidden(column, hidden);
|
||||
}
|
||||
|
||||
public void setColumnWidth(short column, short width) {
|
||||
columnHelper.getColumn(column).setWidth(width);
|
||||
columnHelper.setColWidth(column, width);
|
||||
}
|
||||
|
||||
public void setDefaultColumnStyle(short column, CellStyle style) {
|
||||
|
@ -599,32 +632,36 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public void setDefaultColumnWidth(short width) {
|
||||
this.worksheet.getSheetFormatPr().setDefaultColWidth((double) width);
|
||||
getSheetTypeSheetFormatPr().setDefaultColWidth((double) width);
|
||||
}
|
||||
|
||||
public void setDefaultRowHeight(short height) {
|
||||
this.worksheet.getSheetFormatPr().setDefaultRowHeight(height / 20);
|
||||
getSheetTypeSheetFormatPr().setDefaultRowHeight(height / 20);
|
||||
|
||||
}
|
||||
|
||||
public void setDefaultRowHeightInPoints(float height) {
|
||||
this.worksheet.getSheetFormatPr().setDefaultRowHeight(height);
|
||||
getSheetTypeSheetFormatPr().setDefaultRowHeight(height);
|
||||
|
||||
}
|
||||
|
||||
public void setDialog(boolean b) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setDisplayFormulas(boolean show) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
getSheetTypeSheetView().setShowFormulas(show);
|
||||
}
|
||||
|
||||
public void setDisplayGridlines(boolean show) {
|
||||
// TODO Auto-generated method stub
|
||||
protected CTSheetView getSheetTypeSheetView() {
|
||||
if (getDefaultSheetView() == null) {
|
||||
getSheetTypeSheetViews().setSheetViewArray(0, CTSheetView.Factory.newInstance());
|
||||
}
|
||||
return getDefaultSheetView();
|
||||
}
|
||||
|
||||
public void setDisplayGridlines(boolean show) {
|
||||
getSheetTypeSheetView().setShowGridLines(show);
|
||||
}
|
||||
|
||||
public void setDisplayGuts(boolean b) {
|
||||
|
@ -633,26 +670,23 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public void setDisplayRowColHeadings(boolean show) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
getSheetTypeSheetView().setShowRowColHeaders(show);
|
||||
}
|
||||
|
||||
public void setFitToPage(boolean b) {
|
||||
worksheet.getSheetPr().getPageSetUpPr().setFitToPage(b);
|
||||
getSheetTypePageSetUpPr().setFitToPage(b);
|
||||
}
|
||||
|
||||
public void setGridsPrinted(boolean value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
setPrintGridlines(value);
|
||||
}
|
||||
|
||||
public void setHorizontallyCenter(boolean value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
getSheetTypePrintOptions().setHorizontalCentered(value);
|
||||
}
|
||||
|
||||
public void setMargin(short margin, double size) {
|
||||
CTPageMargins pageMargins = worksheet.getPageMargins();
|
||||
CTPageMargins pageMargins = getSheetTypePageMargins();
|
||||
switch (margin) {
|
||||
case LeftMargin:
|
||||
pageMargins.setLeft(size);
|
||||
|
@ -670,8 +704,7 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public void setPrintGridlines(boolean newPrintGridlines) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
getSheetTypePrintOptions().setGridLines(newPrintGridlines);
|
||||
}
|
||||
|
||||
public void setProtect(boolean protect) {
|
||||
|
@ -680,7 +713,7 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public void setRowBreak(int row) {
|
||||
CTPageBreak pageBreak = worksheet.getRowBreaks();
|
||||
CTPageBreak pageBreak = getSheetTypeRowBreaks();
|
||||
if (! isRowBroken(row)) {
|
||||
CTBreak brk = pageBreak.addNewBrk();
|
||||
brk.setId(row);
|
||||
|
@ -702,19 +735,29 @@ public class XSSFSheet implements Sheet {
|
|||
|
||||
}
|
||||
|
||||
public void setSelected(boolean sel) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setVerticallyCenter(boolean value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
getSheetTypePrintOptions().setVerticalCentered(value);
|
||||
}
|
||||
|
||||
// HSSFSheet compatibility methods. See also the following zoom related methods
|
||||
public void setZoom(int numerator, int denominator) {
|
||||
// TODO Auto-generated method stub
|
||||
setZoom((numerator/denominator) * 100);
|
||||
}
|
||||
|
||||
public void setZoom(long scale) {
|
||||
getSheetTypeSheetView().setZoomScale(scale);
|
||||
}
|
||||
|
||||
public void setZoomNormal(long scale) {
|
||||
getSheetTypeSheetView().setZoomScaleNormal(scale);
|
||||
}
|
||||
|
||||
public void setZoomPageLayoutView(long scale) {
|
||||
getSheetTypeSheetView().setZoomScalePageLayoutView(scale);
|
||||
}
|
||||
|
||||
public void setZoomSheetLayoutView(long scale) {
|
||||
getSheetTypeSheetView().setZoomScaleSheetLayoutView(scale);
|
||||
}
|
||||
|
||||
public void shiftRows(int startRow, int endRow, int n) {
|
||||
|
@ -728,8 +771,9 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
public void showInPane(short toprow, short leftcol) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
CellReference cellReference = new CellReference();
|
||||
String cellRef = cellReference.convertRowColToString(toprow, leftcol);
|
||||
getSheetTypeSheetView().setTopLeftCell(cellRef);
|
||||
}
|
||||
|
||||
public void ungroupColumn(short fromColumn, short toColumn) {
|
||||
|
@ -742,14 +786,22 @@ public class XSSFSheet implements Sheet {
|
|||
|
||||
}
|
||||
|
||||
public void setTabSelected(boolean flag) {
|
||||
CTSheetViews views = this.worksheet.getSheetViews();
|
||||
public void setSelected(boolean flag) {
|
||||
CTSheetViews views = getSheetTypeSheetViews();
|
||||
for (CTSheetView view : views.getSheetViewArray()) {
|
||||
view.setTabSelected(flag);
|
||||
}
|
||||
}
|
||||
|
||||
protected CTSheetViews getSheetTypeSheetViews() {
|
||||
if (worksheet.getSheetViews() == null) {
|
||||
worksheet.setSheetViews(CTSheetViews.Factory.newInstance());
|
||||
worksheet.getSheetViews().addNewSheetView();
|
||||
}
|
||||
return worksheet.getSheetViews();
|
||||
}
|
||||
|
||||
public boolean isTabSelected() {
|
||||
public boolean isSelected() {
|
||||
CTSheetView view = getDefaultSheetView();
|
||||
return view != null && view.getTabSelected();
|
||||
}
|
||||
|
@ -764,7 +816,7 @@ public class XSSFSheet implements Sheet {
|
|||
* workbookView entries) are saved."
|
||||
*/
|
||||
private CTSheetView getDefaultSheetView() {
|
||||
CTSheetViews views = this.worksheet.getSheetViews();
|
||||
CTSheetViews views = getSheetTypeSheetViews();
|
||||
if (views == null || views.getSheetViewArray() == null || views.getSheetViewArray().length <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
@ -772,7 +824,13 @@ public class XSSFSheet implements Sheet {
|
|||
}
|
||||
|
||||
protected XSSFSheet cloneSheet() {
|
||||
return new XSSFSheet((CTSheet) sheet.copy(), this.workbook);
|
||||
XSSFSheet newSheet = new XSSFSheet(this.workbook);
|
||||
newSheet.setSheet((CTSheet)sheet.copy());
|
||||
return newSheet;
|
||||
}
|
||||
|
||||
private void setSheet(CTSheet sheet) {
|
||||
this.sheet = sheet;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.openxml4j.opc.PackagingURIHelper;
|
|||
import org.openxml4j.opc.TargetMode;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||
|
@ -204,14 +205,30 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
|||
}
|
||||
|
||||
public Sheet createSheet(String sheetname) {
|
||||
CTSheet sheet = workbook.getSheets().addNewSheet();
|
||||
if (sheetname != null) {
|
||||
sheet.setName(sheetname);
|
||||
}
|
||||
XSSFSheet wrapper = new XSSFSheet(sheet, this);
|
||||
return createSheet(sheetname, null);
|
||||
}
|
||||
|
||||
public Sheet createSheet(String sheetname, CTWorksheet worksheet) {
|
||||
CTSheet sheet = addSheet(sheetname);
|
||||
XSSFWorksheet wrapper = new XSSFWorksheet(sheet, worksheet, this);
|
||||
this.sheets.add(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public Sheet createDialogsheet(String sheetname, CTDialogsheet dialogsheet) {
|
||||
CTSheet sheet = addSheet(sheetname);
|
||||
XSSFDialogsheet wrapper = new XSSFDialogsheet(sheet, dialogsheet, this);
|
||||
this.sheets.add(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private CTSheet addSheet(String sheetname) {
|
||||
CTSheet sheet = workbook.getSheets().addNewSheet();
|
||||
if (sheetname != null) {
|
||||
sheet.setName(sheetname);
|
||||
}
|
||||
return sheet;
|
||||
}
|
||||
|
||||
public void dumpDrawingGroupRecords(boolean fat) {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -331,7 +348,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
|||
public short getSelectedTab() {
|
||||
short i = 0;
|
||||
for (XSSFSheet sheet : this.sheets) {
|
||||
if (sheet.isTabSelected()) {
|
||||
if (sheet.isSelected()) {
|
||||
return i;
|
||||
}
|
||||
++i;
|
||||
|
@ -392,7 +409,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
|||
}
|
||||
|
||||
public void removeSheetAt(int index) {
|
||||
XSSFSheet sheet = this.sheets.remove(index);
|
||||
this.sheets.remove(index);
|
||||
this.workbook.getSheets().removeSheet(index);
|
||||
}
|
||||
|
||||
|
@ -427,7 +444,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
|||
public void setSelectedTab(short index) {
|
||||
for (int i = 0 ; i < this.sheets.size() ; ++i) {
|
||||
XSSFSheet sheet = this.sheets.get(i);
|
||||
sheet.setTabSelected(i == index);
|
||||
sheet.setSelected(i == index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -479,7 +496,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
|||
out.close();
|
||||
|
||||
for (int i = 0 ; i < this.getNumberOfSheets() ; ++i) {
|
||||
XSSFSheet sheet = (XSSFSheet) this.getSheetAt(i);
|
||||
XSSFSheet sheet = (XSSFSheet) this.getSheetAt(i);
|
||||
PackagePartName partName = PackagingURIHelper.createPartName("/xl/worksheets/sheet" + i + ".xml");
|
||||
corePart.addRelationship(partName, TargetMode.INTERNAL, WORKSHEET_RELATIONSHIP, "rSheet" + 1);
|
||||
PackagePart part = pkg.createPart(partName, WORKSHEET_TYPE);
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.xssf.usermodel;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||
|
||||
public class XSSFWorksheet extends XSSFSheet implements Sheet{
|
||||
|
||||
public XSSFWorksheet(CTSheet sheet, CTWorksheet worksheet,
|
||||
XSSFWorkbook workbook) {
|
||||
super(sheet, worksheet, workbook);
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
|||
public class ColumnHelper {
|
||||
|
||||
private CTWorksheet worksheet;
|
||||
|
||||
private CTCols newCols;
|
||||
|
||||
public ColumnHelper(CTWorksheet worksheet) {
|
||||
super();
|
||||
|
@ -35,7 +35,7 @@ public class ColumnHelper {
|
|||
}
|
||||
|
||||
public void cleanColumns() {
|
||||
CTCols newCols = CTCols.Factory.newInstance();
|
||||
this.newCols = CTCols.Factory.newInstance();
|
||||
CTCols[] colsArray = worksheet.getColsArray();
|
||||
int i = 0;
|
||||
for (i = 0 ; i < colsArray.length ; i++) {
|
||||
|
@ -85,6 +85,34 @@ public class ColumnHelper {
|
|||
if (col.getHidden()) {
|
||||
newCol.setHidden(true);
|
||||
}
|
||||
if (col.getBestFit()) {
|
||||
newCol.setBestFit(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setColBestFit(long index, boolean bestFit) {
|
||||
CTCol col = getOrCreateColumn(index);
|
||||
col.setBestFit(bestFit);
|
||||
}
|
||||
|
||||
public void setColWidth(long index, double width) {
|
||||
CTCol col = getOrCreateColumn(index);
|
||||
col.setWidth(width);
|
||||
}
|
||||
|
||||
public void setColHidden(long index, boolean hidden) {
|
||||
CTCol col = getOrCreateColumn(index);
|
||||
col.setHidden(hidden);
|
||||
}
|
||||
|
||||
protected CTCol getOrCreateColumn(long index) {
|
||||
CTCol col = getColumn(index);
|
||||
if (col == null) {
|
||||
col = worksheet.getColsArray(0).addNewCol();
|
||||
col.setMin(index);
|
||||
col.setMax(index);
|
||||
}
|
||||
return col;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.xssf.util;
|
||||
|
||||
public class CellReference {
|
||||
|
||||
private int row;
|
||||
private short col;
|
||||
|
||||
public CellReference() {
|
||||
}
|
||||
|
||||
public CellReference(String cellRef) {
|
||||
if (cellRef == null || "".equals(cellRef)) {
|
||||
throw new IllegalArgumentException("Invalid Formula cell reference: '"+cellRef+"'");
|
||||
}
|
||||
String[] parts = getCellRefParts(cellRef);
|
||||
col = getColNumFromRef(parts[0]);
|
||||
row = getRowNumFromRef(parts[1]);
|
||||
}
|
||||
|
||||
public CellReference(short col, int row) {
|
||||
this.col = col;
|
||||
this.row = row;
|
||||
}
|
||||
|
||||
public int getRow() {
|
||||
return this.row;
|
||||
}
|
||||
|
||||
public short getCol() {
|
||||
return this.col;
|
||||
}
|
||||
|
||||
public String[] getCellRefParts(String cellRef) {
|
||||
StringBuffer sb0 = new StringBuffer("");
|
||||
StringBuffer sb1 = new StringBuffer("");
|
||||
String[] parts = new String[2];
|
||||
for (int i = 0 ; i < cellRef.length() ; i++) {
|
||||
char item = cellRef.charAt(i);
|
||||
if ((int)item >= 65 && (int)item <= 90) {
|
||||
sb0.append(item);
|
||||
}
|
||||
else {
|
||||
sb1.append(item);
|
||||
}
|
||||
}
|
||||
parts[0] = sb0.toString();
|
||||
parts[1] = sb1.toString();
|
||||
return parts;
|
||||
}
|
||||
|
||||
public int getRowNumFromRef(String rowRef) {
|
||||
return (new Integer(rowRef).intValue()) - 1;
|
||||
}
|
||||
|
||||
public short getColNumFromRef(String colRef) {
|
||||
double columnIndex = -1;
|
||||
for (int i = (colRef.length() - 1) ; i >= 0 ; i--) {
|
||||
char numericCharValue = colRef.charAt(colRef.length() - (i + 1));
|
||||
int convertedNumericCharValue = (numericCharValue - 64);
|
||||
double indexIncrement = (convertedNumericCharValue * Math.pow(26, i));
|
||||
columnIndex = columnIndex + indexIncrement;
|
||||
}
|
||||
return (short)columnIndex;
|
||||
}
|
||||
|
||||
public String convertNumToColString(short col) {
|
||||
String colRef = "";
|
||||
double div = 1;
|
||||
double mod = 0;
|
||||
for (int i = 0 ; div >= 1 ; i ++) {
|
||||
mod = col % 26;
|
||||
div = col / 26;
|
||||
int AsciiIncrement = (i != 0 ? 64 : 65);
|
||||
char modToChar = (char)(mod + AsciiIncrement);
|
||||
colRef = modToChar + colRef;
|
||||
col = (short) ((col - mod) / 26);
|
||||
}
|
||||
return colRef;
|
||||
}
|
||||
|
||||
public String convertRowColToString(short row, short col) {
|
||||
return convertNumToColString(col) + ((short) (row + 1));
|
||||
}
|
||||
|
||||
}
|
|
@ -56,17 +56,19 @@ public class TestLoadSaveXSSF extends TestCase {
|
|||
assertEquals("Lorem", cell.getRichStringCellValue().getString());
|
||||
}
|
||||
|
||||
// TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successfull.
|
||||
public void testLoadStyles() throws Exception {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "styles.xlsx").getAbsolutePath());
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(new File("src/ooxml/testcases/org/apache/poi/xssf/data", "styles.xlsx").getAbsolutePath());
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
Row row = sheet.getRow(0);
|
||||
Cell cell = row.getCell((short) 0);
|
||||
CellStyle style = cell.getCellStyle();
|
||||
// assertNotNull(style);
|
||||
}
|
||||
|
||||
|
||||
// TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successfull.
|
||||
public void testLoadPictures() throws Exception {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "picture.xlsx").getAbsolutePath());
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(new File("src/ooxml/testcases/org/apache/poi/xssf/data", "picture.xlsx").getAbsolutePath());
|
||||
List<PictureData> pictures = workbook.getAllPictures();
|
||||
assertEquals(1, pictures.size());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,225 @@
|
|||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.xssf.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
||||
|
||||
|
||||
public class TestXSSFDialogSheet extends TestCase {
|
||||
|
||||
public void testDialogsheetConstructor() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
XSSFDialogsheet dialogsheet = new XSSFDialogsheet(CTSheet.Factory.newInstance(), CTDialogsheet.Factory.newInstance(), workbook);
|
||||
assertNotNull(dialogsheet);
|
||||
XSSFDialogsheet dialogsheet2 = new XSSFDialogsheet(CTSheet.Factory.newInstance(), null, workbook);
|
||||
assertNotNull(dialogsheet2);
|
||||
}
|
||||
|
||||
public void testCreateDialogSheet() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", CTDialogsheet.Factory.newInstance());
|
||||
assertNotNull(dialogsheet);
|
||||
}
|
||||
|
||||
public void testGetDialog() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
assertFalse(sheet.getDialog());
|
||||
XSSFSheet dialogsheet = (XSSFSheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertTrue(dialogsheet.getDialog());
|
||||
|
||||
}
|
||||
|
||||
public void testAddRow() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", CTDialogsheet.Factory.newInstance());
|
||||
assertNotNull(dialogsheet);
|
||||
Row row = dialogsheet.createRow(0);
|
||||
assertNull(row);
|
||||
}
|
||||
|
||||
public void testGetSetAutoBreaks() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertTrue(sheet.getAutobreaks());
|
||||
sheet.setAutobreaks(false);
|
||||
assertFalse(sheet.getAutobreaks());
|
||||
}
|
||||
|
||||
public void testIsSetFitToPage() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertFalse(sheet.getFitToPage());
|
||||
sheet.setFitToPage(true);
|
||||
assertTrue(sheet.getFitToPage());
|
||||
sheet.setFitToPage(false);
|
||||
assertFalse(sheet.getFitToPage());
|
||||
}
|
||||
|
||||
public void testGetSetMargin() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertEquals((double) 0, sheet.getMargin((short) 0));
|
||||
sheet.setMargin((short) 0, 10);
|
||||
assertEquals((double) 10, sheet.getMargin((short) 0));
|
||||
assertEquals((double) 10, sheet.getMargin((short) 1));
|
||||
assertEquals((double) 10, sheet.getMargin((short) 2));
|
||||
assertEquals((double) 10, sheet.getMargin((short) 3));
|
||||
assertEquals((double) 10, sheet.getMargin((short) 4));
|
||||
assertEquals((double) 10, sheet.getMargin((short) 5));
|
||||
sheet.setMargin((short) 1, 11);
|
||||
assertEquals((double) 11, sheet.getMargin((short) 1));
|
||||
assertEquals((double) 11, sheet.getMargin((short) 2));
|
||||
assertEquals((double) 11, sheet.getMargin((short) 3));
|
||||
assertEquals((double) 11, sheet.getMargin((short) 4));
|
||||
assertEquals((double) 11, sheet.getMargin((short) 5));
|
||||
sheet.setMargin((short) 2, 12);
|
||||
assertEquals((double) 12, sheet.getMargin((short) 2));
|
||||
assertEquals((double) 12, sheet.getMargin((short) 3));
|
||||
assertEquals((double) 12, sheet.getMargin((short) 4));
|
||||
assertEquals((double) 12, sheet.getMargin((short) 5));
|
||||
sheet.setMargin((short) 3, 13);
|
||||
assertEquals((double) 13, sheet.getMargin((short) 3));
|
||||
assertEquals((double) 13, sheet.getMargin((short) 4));
|
||||
assertEquals((double) 13, sheet.getMargin((short) 5));
|
||||
sheet.setMargin((short) 4, 14);
|
||||
assertEquals((double) 14, sheet.getMargin((short) 4));
|
||||
assertEquals((double) 14, sheet.getMargin((short) 5));
|
||||
sheet.setMargin((short) 5, 15);
|
||||
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));
|
||||
}
|
||||
|
||||
public void testGetFooter() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertNotNull(sheet.getFooter());
|
||||
sheet.getFooter().setCenter("test center footer");
|
||||
assertEquals("test center footer", sheet.getFooter().getCenter());
|
||||
}
|
||||
|
||||
public void testGetAllHeadersFooters() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertNotNull(sheet);
|
||||
assertNotNull(sheet.getOddFooter());
|
||||
assertNotNull(sheet.getEvenFooter());
|
||||
assertNotNull(sheet.getFirstFooter());
|
||||
assertNotNull(sheet.getOddHeader());
|
||||
assertNotNull(sheet.getEvenHeader());
|
||||
assertNotNull(sheet.getFirstHeader());
|
||||
|
||||
assertEquals("", sheet.getOddFooter().getLeft());
|
||||
sheet.getOddFooter().setLeft("odd footer left");
|
||||
assertEquals("odd footer left", sheet.getOddFooter().getLeft());
|
||||
|
||||
assertEquals("", sheet.getEvenFooter().getLeft());
|
||||
sheet.getEvenFooter().setLeft("even footer left");
|
||||
assertEquals("even footer left", sheet.getEvenFooter().getLeft());
|
||||
|
||||
assertEquals("", sheet.getFirstFooter().getLeft());
|
||||
sheet.getFirstFooter().setLeft("first footer left");
|
||||
assertEquals("first footer left", sheet.getFirstFooter().getLeft());
|
||||
|
||||
assertEquals("", sheet.getOddHeader().getLeft());
|
||||
sheet.getOddHeader().setLeft("odd header left");
|
||||
assertEquals("odd header left", sheet.getOddHeader().getLeft());
|
||||
|
||||
assertEquals("", sheet.getOddHeader().getRight());
|
||||
sheet.getOddHeader().setRight("odd header right");
|
||||
assertEquals("odd header right", sheet.getOddHeader().getRight());
|
||||
|
||||
assertEquals("", sheet.getOddHeader().getCenter());
|
||||
sheet.getOddHeader().setCenter("odd header center");
|
||||
assertEquals("odd header center", sheet.getOddHeader().getCenter());
|
||||
|
||||
}
|
||||
|
||||
public void testGetSetHorizontallyCentered() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertFalse(sheet.getHorizontallyCenter());
|
||||
sheet.setHorizontallyCenter(true);
|
||||
assertTrue(sheet.getHorizontallyCenter());
|
||||
sheet.setHorizontallyCenter(false);
|
||||
assertFalse(sheet.getHorizontallyCenter());
|
||||
}
|
||||
|
||||
public void testGetSetVerticallyCentered() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertFalse(sheet.getVerticallyCenter());
|
||||
sheet.setVerticallyCenter(true);
|
||||
assertTrue(sheet.getVerticallyCenter());
|
||||
sheet.setVerticallyCenter(false);
|
||||
assertFalse(sheet.getVerticallyCenter());
|
||||
}
|
||||
|
||||
public void testIsSetPrintGridlines() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertFalse(sheet.isPrintGridlines());
|
||||
sheet.setPrintGridlines(true);
|
||||
assertTrue(sheet.isPrintGridlines());
|
||||
}
|
||||
|
||||
public void testIsSetDisplayFormulas() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertFalse(sheet.isDisplayFormulas());
|
||||
sheet.setDisplayFormulas(true);
|
||||
assertTrue(sheet.isDisplayFormulas());
|
||||
}
|
||||
|
||||
public void testIsSetDisplayGridLines() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertTrue(sheet.isDisplayGridlines());
|
||||
sheet.setDisplayGridlines(false);
|
||||
assertFalse(sheet.isDisplayGridlines());
|
||||
}
|
||||
|
||||
public void testIsSetDisplayRowColHeadings() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertTrue(sheet.isDisplayRowColHeadings());
|
||||
sheet.setDisplayRowColHeadings(false);
|
||||
assertFalse(sheet.isDisplayRowColHeadings());
|
||||
}
|
||||
|
||||
public void testGetScenarioProtect() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertFalse(sheet.getScenarioProtect());
|
||||
}
|
||||
|
||||
}
|
|
@ -19,12 +19,16 @@ package org.apache.poi.xssf.usermodel;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Footer;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||
|
||||
|
||||
public class TestXSSFSheet extends TestCase {
|
||||
|
@ -106,8 +110,8 @@ public class TestXSSFSheet extends TestCase {
|
|||
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());
|
||||
assertEquals((short) 0, sheet.getDefaultRowHeight());
|
||||
assertEquals((float) 0, 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());
|
||||
|
@ -120,7 +124,7 @@ public class TestXSSFSheet extends TestCase {
|
|||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
// Test that default column width set by the constructor
|
||||
assertEquals((short) 13, sheet.getDefaultColumnWidth());
|
||||
assertEquals((short) 0, sheet.getDefaultColumnWidth());
|
||||
// Set a new default column width and get its value
|
||||
sheet.setDefaultColumnWidth((short) 14);
|
||||
assertEquals((short) 14, sheet.getDefaultColumnWidth());
|
||||
|
@ -322,4 +326,94 @@ public class TestXSSFSheet extends TestCase {
|
|||
sheet.setColumnHidden((short) 2, true);
|
||||
assertTrue(sheet.isColumnHidden((short) 2));
|
||||
}
|
||||
|
||||
public void testAutoSizeColumn() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
ColumnHelper columnHelper = sheet.getColumnHelper();
|
||||
CTCol col = columnHelper.getColumn(13);
|
||||
assertNull(col);
|
||||
sheet.autoSizeColumn((short)13);
|
||||
col = columnHelper.getColumn(13);
|
||||
assertNotNull(col);
|
||||
assertTrue(col.getBestFit());
|
||||
}
|
||||
|
||||
public void testGetDialog() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
assertFalse(sheet.getDialog());
|
||||
XSSFSheet dialogsheet = (XSSFSheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
||||
assertTrue(dialogsheet.getDialog());
|
||||
|
||||
}
|
||||
|
||||
public void testGetSetHorizontallyCentered() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
assertFalse(sheet.getHorizontallyCenter());
|
||||
sheet.setHorizontallyCenter(true);
|
||||
assertTrue(sheet.getHorizontallyCenter());
|
||||
sheet.setHorizontallyCenter(false);
|
||||
assertFalse(sheet.getHorizontallyCenter());
|
||||
}
|
||||
|
||||
public void testGetSetVerticallyCentered() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
assertFalse(sheet.getVerticallyCenter());
|
||||
sheet.setVerticallyCenter(true);
|
||||
assertTrue(sheet.getVerticallyCenter());
|
||||
sheet.setVerticallyCenter(false);
|
||||
assertFalse(sheet.getVerticallyCenter());
|
||||
}
|
||||
|
||||
public void testIsSetPrintGridlines() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
assertFalse(sheet.isPrintGridlines());
|
||||
sheet.setPrintGridlines(true);
|
||||
assertTrue(sheet.isPrintGridlines());
|
||||
}
|
||||
|
||||
public void testIsSetDisplayFormulas() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
assertFalse(sheet.isDisplayFormulas());
|
||||
sheet.setDisplayFormulas(true);
|
||||
assertTrue(sheet.isDisplayFormulas());
|
||||
}
|
||||
|
||||
public void testIsSetDisplayGridLines() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
assertTrue(sheet.isDisplayGridlines());
|
||||
sheet.setDisplayGridlines(false);
|
||||
assertFalse(sheet.isDisplayGridlines());
|
||||
}
|
||||
|
||||
public void testIsSetDisplayRowColHeadings() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
assertTrue(sheet.isDisplayRowColHeadings());
|
||||
sheet.setDisplayRowColHeadings(false);
|
||||
assertFalse(sheet.isDisplayRowColHeadings());
|
||||
}
|
||||
|
||||
public void testGetScenarioProtect() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
assertFalse(sheet.getScenarioProtect());
|
||||
}
|
||||
|
||||
public void testTopRowLeftCol() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
sheet.showInPane((short)1, (short)1);
|
||||
assertEquals((short) 1, sheet.getTopRow());
|
||||
assertEquals((short) 1, sheet.getLeftCol());
|
||||
sheet.showInPane((short)2, (short)26);
|
||||
assertEquals((short) 2, sheet.getTopRow());
|
||||
assertEquals((short) 26, sheet.getLeftCol());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.apache.poi.xssf.usermodel.helpers;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||
|
@ -94,6 +96,19 @@ public class TestColumnHelper extends TestCase {
|
|||
assertEquals((double) 12, newCol.getWidth());
|
||||
assertTrue(newCol.getHidden());
|
||||
}
|
||||
|
||||
public void testGetOrCreateColumn() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
|
||||
ColumnHelper columnHelper = sheet.getColumnHelper();
|
||||
CTCol col = columnHelper.getOrCreateColumn(3);
|
||||
assertNotNull(col);
|
||||
assertNotNull(columnHelper.getColumn(3));
|
||||
|
||||
CTCol col2 = columnHelper.getOrCreateColumn(30);
|
||||
assertNotNull(col2);
|
||||
assertNotNull(columnHelper.getColumn(30));
|
||||
}
|
||||
|
||||
private int countColumns(CTWorksheet worksheet) {
|
||||
int count;
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.xssf.util;
|
||||
|
||||
import org.apache.poi.xssf.util.CellReference;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class TestCellReference extends TestCase {
|
||||
|
||||
public void testGetCellRefParts() {
|
||||
String cellRef = "A1";
|
||||
CellReference cellReference = new CellReference(cellRef);
|
||||
String[] parts = cellReference.getCellRefParts(cellRef);
|
||||
assertNotNull(parts);
|
||||
assertEquals("A", parts[0]);
|
||||
assertEquals("1", parts[1]);
|
||||
|
||||
cellRef = "AA1";
|
||||
cellReference = new CellReference(cellRef);
|
||||
parts = cellReference.getCellRefParts(cellRef);
|
||||
assertNotNull(parts);
|
||||
assertEquals("AA", parts[0]);
|
||||
assertEquals("1", parts[1]);
|
||||
|
||||
cellRef = "AA100";
|
||||
cellReference = new CellReference(cellRef);
|
||||
parts = cellReference.getCellRefParts(cellRef);
|
||||
assertNotNull(parts);
|
||||
assertEquals("AA", parts[0]);
|
||||
assertEquals("100", parts[1]);
|
||||
|
||||
|
||||
cellRef = "AABC10065";
|
||||
cellReference = new CellReference(cellRef);
|
||||
parts = cellReference.getCellRefParts(cellRef);
|
||||
assertNotNull(parts);
|
||||
assertEquals("AABC", parts[0]);
|
||||
assertEquals("10065", parts[1]);
|
||||
}
|
||||
|
||||
public void testGetColNumFromRef() {
|
||||
String cellRef = "A1";
|
||||
CellReference cellReference = new CellReference(cellRef);
|
||||
String[] parts = cellReference.getCellRefParts(cellRef);
|
||||
short col = cellReference.getColNumFromRef(parts[0]);
|
||||
assertEquals(0, col);
|
||||
|
||||
cellRef = "AB1";
|
||||
cellReference = new CellReference(cellRef);
|
||||
parts = cellReference.getCellRefParts(cellRef);
|
||||
col = cellReference.getColNumFromRef(parts[0]);
|
||||
assertEquals(27, col);
|
||||
|
||||
cellRef = "A1100";
|
||||
cellReference = new CellReference(cellRef);
|
||||
parts = cellReference.getCellRefParts(cellRef);
|
||||
col = cellReference.getColNumFromRef(parts[0]);
|
||||
assertEquals(0, col);
|
||||
|
||||
cellRef = "BC15";
|
||||
cellReference = new CellReference(cellRef);
|
||||
parts = cellReference.getCellRefParts(cellRef);
|
||||
col = cellReference.getColNumFromRef(parts[0]);
|
||||
assertEquals(54, col);
|
||||
}
|
||||
|
||||
public void testGetRowNumFromRef() {
|
||||
String cellRef = "A1";
|
||||
CellReference cellReference = new CellReference(cellRef);
|
||||
String[] parts = cellReference.getCellRefParts(cellRef);
|
||||
int row = cellReference.getRowNumFromRef(parts[1]);
|
||||
assertEquals(0, row);
|
||||
|
||||
cellRef = "A12";
|
||||
cellReference = new CellReference(cellRef);
|
||||
parts = cellReference.getCellRefParts(cellRef);
|
||||
row = cellReference.getRowNumFromRef(parts[1]);
|
||||
assertEquals(11, row);
|
||||
|
||||
cellRef = "AS121";
|
||||
cellReference = new CellReference(cellRef);
|
||||
parts = cellReference.getCellRefParts(cellRef);
|
||||
row = cellReference.getRowNumFromRef(parts[1]);
|
||||
assertEquals(120, row);
|
||||
}
|
||||
|
||||
public void testConvertNumToColString() {
|
||||
short col = 702;
|
||||
String collRef = new CellReference().convertNumToColString(col);
|
||||
assertEquals("AAA", collRef);
|
||||
System.err.println("***");
|
||||
short col2 = 0;
|
||||
String collRef2 = new CellReference().convertNumToColString(col2);
|
||||
assertEquals("A", collRef2);
|
||||
short col3 = 27;
|
||||
String collRef3 = new CellReference().convertNumToColString(col3);
|
||||
assertEquals("AB", collRef3);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue