2008-01-16 11:08:22 -05:00
|
|
|
/* ====================================================================
|
|
|
|
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;
|
|
|
|
|
2008-10-01 13:15:02 -04:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
2008-01-16 11:08:22 -05:00
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
|
2008-10-01 13:15:02 -04:00
|
|
|
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
2008-12-04 13:38:00 -05:00
|
|
|
import org.apache.poi.hssf.record.formula.Ptg;
|
2008-10-23 14:57:28 -04:00
|
|
|
import org.apache.poi.ss.usermodel.*;
|
2008-09-17 15:52:55 -04:00
|
|
|
import org.apache.poi.ss.util.CellReference;
|
2008-12-04 13:38:00 -05:00
|
|
|
import org.apache.poi.ss.formula.FormulaParser;
|
|
|
|
import org.apache.poi.ss.formula.FormulaType;
|
2008-09-16 08:25:54 -04:00
|
|
|
import org.apache.poi.xssf.model.StylesTable;
|
2008-10-19 08:54:40 -04:00
|
|
|
import org.apache.poi.xssf.model.SharedStringsTable;
|
2008-10-29 15:12:47 -04:00
|
|
|
import org.apache.poi.POIXMLException;
|
2008-01-16 11:08:22 -05:00
|
|
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
|
|
|
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
|
|
|
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
|
|
|
|
|
2008-04-06 16:27:40 -04:00
|
|
|
/**
|
2008-10-23 14:57:28 -04:00
|
|
|
* High level representation of a cell in a row of a spreadsheet.
|
|
|
|
* <p>
|
|
|
|
* Cells can be numeric, formula-based or string-based (text). The cell type
|
|
|
|
* specifies this. String cells cannot conatin numbers and numeric cells cannot
|
|
|
|
* contain strings (at least according to our model). Client apps should do the
|
|
|
|
* conversions themselves. Formula cells have the formula string, as well as
|
|
|
|
* the formula result, which can be numeric or string.
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* Cells should have their number (0 based) before being added to a row. Only
|
|
|
|
* cells that have values should be added.
|
|
|
|
* </p>
|
2008-04-06 16:27:40 -04:00
|
|
|
*/
|
|
|
|
public final class XSSFCell implements Cell {
|
2008-01-16 11:08:22 -05:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* The maximum number of columns in SpreadsheetML
|
|
|
|
*/
|
2008-12-04 13:38:00 -05:00
|
|
|
public static final int MAX_COLUMN_NUMBER = 16384; //2^14
|
2008-10-23 14:57:28 -04:00
|
|
|
|
2008-01-16 11:08:22 -05:00
|
|
|
private static final String FALSE_AS_STRING = "0";
|
|
|
|
private static final String TRUE_AS_STRING = "1";
|
2008-10-23 14:57:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the xml bean containing information about the cell's location, value,
|
|
|
|
* data type, formatting, and formula
|
|
|
|
*/
|
2008-01-16 11:08:22 -05:00
|
|
|
private final CTCell cell;
|
2008-10-23 14:57:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the XSSFRow this cell belongs to
|
|
|
|
*/
|
2008-01-16 11:08:22 -05:00
|
|
|
private final XSSFRow row;
|
2008-10-23 14:57:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 0-based column index
|
|
|
|
*/
|
2008-03-29 18:45:11 -04:00
|
|
|
private int cellNum;
|
2008-10-23 14:57:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table of strings shared across this workbook.
|
|
|
|
* If two cells contain the same string, then the cell value is the same index into SharedStringsTable
|
|
|
|
*/
|
2008-10-19 08:54:40 -04:00
|
|
|
private SharedStringsTable sharedStringSource;
|
2008-04-06 16:27:40 -04:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Table of cell styles shared across all cells in a workbook.
|
|
|
|
*/
|
|
|
|
private StylesTable stylesSource;
|
2008-04-06 16:27:40 -04:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Construct a XSSFCell.
|
|
|
|
*
|
|
|
|
* @param row the parent row.
|
2008-11-07 11:57:23 -05:00
|
|
|
* @param cell the xml bean containing information about the cell.
|
2008-10-23 14:57:28 -04:00
|
|
|
*/
|
|
|
|
protected XSSFCell(XSSFRow row, CTCell cell) {
|
2008-01-16 11:08:22 -05:00
|
|
|
this.cell = cell;
|
|
|
|
this.row = row;
|
2008-02-07 10:44:32 -05:00
|
|
|
if (cell.getR() != null) {
|
|
|
|
this.cellNum = parseCellNum(cell.getR());
|
|
|
|
}
|
2008-09-17 15:52:55 -04:00
|
|
|
this.sharedStringSource = row.getSheet().getWorkbook().getSharedStringSource();
|
2008-10-19 08:54:40 -04:00
|
|
|
this.stylesSource = row.getSheet().getWorkbook().getStylesSource();
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
2008-04-06 16:27:40 -04:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* @return table of strings shared across this workbook
|
|
|
|
*/
|
2008-10-19 08:54:40 -04:00
|
|
|
protected SharedStringsTable getSharedStringSource() {
|
2008-10-23 14:57:28 -04:00
|
|
|
return sharedStringSource;
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
2008-10-01 13:15:02 -04:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* @return table of cell styles shared across this workbook
|
|
|
|
*/
|
|
|
|
protected StylesTable getStylesSource() {
|
|
|
|
return stylesSource;
|
2008-03-16 20:10:17 -04:00
|
|
|
}
|
2008-01-16 11:08:22 -05:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Returns the sheet this cell belongs to
|
|
|
|
*
|
|
|
|
* @return the sheet this cell belongs to
|
|
|
|
*/
|
|
|
|
public XSSFSheet getSheet() {
|
|
|
|
return getRow().getSheet();
|
2008-09-13 09:56:04 -04:00
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Returns the row this cell belongs to
|
|
|
|
*
|
|
|
|
* @return the row this cell belongs to
|
|
|
|
*/
|
|
|
|
public XSSFRow getRow() {
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of the cell as a boolean.
|
|
|
|
* <p>
|
|
|
|
* For strings, numbers, and errors, we throw an exception. For blank cells we return a false.
|
|
|
|
* </p>
|
|
|
|
* @return the value of the cell as a boolean
|
|
|
|
* @throws IllegalStateException if the cell type returned by {@link #getCellType()}
|
|
|
|
* is not CELL_TYPE_BOOLEAN, CELL_TYPE_BLANK or CELL_TYPE_FORMULA
|
|
|
|
*/
|
2008-01-16 11:08:22 -05:00
|
|
|
public boolean getBooleanCellValue() {
|
2008-10-23 14:57:28 -04:00
|
|
|
int cellType = getCellType();
|
|
|
|
switch(cellType) {
|
|
|
|
case CELL_TYPE_BLANK:
|
|
|
|
return false;
|
|
|
|
case CELL_TYPE_BOOLEAN:
|
|
|
|
return cell.isSetV() && TRUE_AS_STRING.equals(cell.getV());
|
|
|
|
case CELL_TYPE_FORMULA:
|
|
|
|
//YK: should throw an exception if requesting boolean value from a non-boolean formula
|
|
|
|
return cell.isSetV() && TRUE_AS_STRING.equals(cell.getV());
|
|
|
|
default:
|
|
|
|
throw typeMismatch(CELL_TYPE_BOOLEAN, cellType, false);
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
2008-10-23 14:57:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a boolean value for the cell
|
|
|
|
*
|
|
|
|
* @param value the boolean value to set this cell to. For formulas we'll set the
|
|
|
|
* precalculated value, for booleans we'll set its value. For other types we
|
|
|
|
* will change the cell to a boolean cell and set its value.
|
|
|
|
*/
|
|
|
|
public void setCellValue(boolean value) {
|
|
|
|
cell.setT(STCellType.B);
|
|
|
|
cell.setV(value ? TRUE_AS_STRING : FALSE_AS_STRING);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of the cell as a number.
|
|
|
|
* <p>
|
|
|
|
* For strings we throw an exception. For blank cells we return a 0.
|
|
|
|
* For formulas or error cells we return the precalculated value;
|
|
|
|
* </p>
|
|
|
|
* @return the value of the cell as a number
|
|
|
|
* @throws IllegalStateException if the cell type returned by {@link #getCellType()} is CELL_TYPE_STRING
|
|
|
|
* @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
|
2008-10-29 15:12:47 -04:00
|
|
|
* @see DataFormatter for turning this number into a string similar to that which Excel would render this number as.
|
2008-10-23 14:57:28 -04:00
|
|
|
*/
|
|
|
|
public double getNumericCellValue() {
|
|
|
|
int cellType = getCellType();
|
|
|
|
switch(cellType) {
|
|
|
|
case CELL_TYPE_BLANK:
|
|
|
|
return 0.0;
|
|
|
|
case CELL_TYPE_ERROR:
|
|
|
|
case CELL_TYPE_FORMULA:
|
|
|
|
case CELL_TYPE_NUMERIC:
|
|
|
|
return cell.isSetV() ? Double.parseDouble(cell.getV()) : 0.0;
|
|
|
|
default:
|
|
|
|
throw typeMismatch(CELL_TYPE_NUMERIC, cellType, false);
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
2008-10-23 14:57:28 -04:00
|
|
|
}
|
|
|
|
|
2008-04-06 16:27:40 -04:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Set a numeric value for the cell
|
|
|
|
*
|
|
|
|
* @param value the numeric value to set this cell to. For formulas we'll set the
|
|
|
|
* precalculated value, for numerics we'll set its value. For other types we
|
|
|
|
* will change the cell to a numeric cell and set its value.
|
|
|
|
*/
|
|
|
|
public void setCellValue(double value) {
|
|
|
|
int cellType = getCellType();
|
|
|
|
switch (cellType) {
|
|
|
|
case CELL_TYPE_ERROR:
|
|
|
|
case CELL_TYPE_FORMULA:
|
|
|
|
cell.setV(String.valueOf(value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cell.setT(STCellType.N);
|
|
|
|
cell.setV(String.valueOf(value));
|
|
|
|
break;
|
|
|
|
}
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Get the value of the cell as a string
|
|
|
|
* <p>
|
|
|
|
* For numeric cells we throw an exception. For blank cells we return an empty string.
|
|
|
|
* For formulaCells that are not string Formulas, we return empty String.
|
|
|
|
* </p>
|
|
|
|
* @return the value of the cell as a string
|
|
|
|
*/
|
|
|
|
public String getStringCellValue() {
|
|
|
|
XSSFRichTextString str = getRichStringCellValue();
|
|
|
|
return str == null ? null : str.getString();
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Get the value of the cell as a XSSFRichTextString
|
|
|
|
* <p>
|
|
|
|
* For numeric cells we throw an exception. For blank cells we return an empty string.
|
|
|
|
* For formula cells we return the pre-calculated value.
|
|
|
|
* </p>
|
|
|
|
* @return the value of the cell as a XSSFRichTextString
|
|
|
|
*/
|
|
|
|
public XSSFRichTextString getRichStringCellValue() {
|
|
|
|
int cellType = getCellType();
|
|
|
|
XSSFRichTextString rt;
|
|
|
|
switch (cellType) {
|
|
|
|
case CELL_TYPE_BLANK:
|
|
|
|
rt = new XSSFRichTextString("");
|
|
|
|
break;
|
|
|
|
case CELL_TYPE_STRING:
|
|
|
|
if (!cell.isSetV()) rt = new XSSFRichTextString("");
|
|
|
|
else {
|
|
|
|
if (cell.getT() == STCellType.INLINE_STR) {
|
|
|
|
return new XSSFRichTextString(cell.getV());
|
|
|
|
} else {
|
|
|
|
int idx = Integer.parseInt(cell.getV());
|
|
|
|
rt = new XSSFRichTextString(sharedStringSource.getEntryAt(idx));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CELL_TYPE_FORMULA:
|
|
|
|
rt = new XSSFRichTextString(cell.isSetV() ? cell.getV() : "");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw typeMismatch(CELL_TYPE_STRING, cellType, false);
|
|
|
|
}
|
|
|
|
rt.setStylesTableReference(stylesSource);
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a string value for the cell.
|
|
|
|
*
|
|
|
|
* @param str value to set the cell to. For formulas we'll set the formula
|
|
|
|
* cached string result, for String cells we'll set its value. For other types we will
|
|
|
|
* change the cell to a string cell and set its value.
|
|
|
|
* If value is null then we will change the cell to a Blank cell.
|
|
|
|
*/
|
|
|
|
public void setCellValue(String str) {
|
|
|
|
setCellValue(str == null ? null : new XSSFRichTextString(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a string value for the cell.
|
|
|
|
*
|
|
|
|
* @param str value to set the cell to. For formulas we'll set the 'pre-evaluated result string,
|
|
|
|
* for String cells we'll set its value. For other types we will
|
|
|
|
* change the cell to a string cell and set its value.
|
|
|
|
* If value is null then we will change the cell to a Blank cell.
|
|
|
|
*/
|
|
|
|
public void setCellValue(RichTextString str) {
|
|
|
|
if(str == null){
|
|
|
|
setBlank();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int cellType = getCellType();
|
|
|
|
switch(cellType){
|
|
|
|
case Cell.CELL_TYPE_FORMULA:
|
|
|
|
cell.setV(str.getString());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(cell.getT() == STCellType.INLINE_STR) {
|
|
|
|
//set the 'pre-evaluated result
|
|
|
|
cell.setV(str.getString());
|
|
|
|
} else {
|
|
|
|
cell.setT(STCellType.S);
|
|
|
|
XSSFRichTextString rt = (XSSFRichTextString)str;
|
|
|
|
rt.setStylesTableReference(stylesSource);
|
|
|
|
int sRef = sharedStringSource.addEntry(rt.getCTRst());
|
|
|
|
cell.setV(Integer.toString(sRef));
|
|
|
|
}
|
|
|
|
break;
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
2008-10-23 14:57:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a formula for the cell, for example, <code>SUM(C4:E4)</code>
|
|
|
|
*
|
|
|
|
* @return a formula for the cell
|
|
|
|
* @throws IllegalStateException if the cell type returned by {@link #getCellType()} is not CELL_TYPE_FORMULA
|
|
|
|
*/
|
|
|
|
public String getCellFormula() {
|
|
|
|
int cellType = getCellType();
|
|
|
|
if(cellType != CELL_TYPE_FORMULA) throw typeMismatch(CELL_TYPE_FORMULA, cellType, false);
|
|
|
|
|
2008-01-16 11:08:22 -05:00
|
|
|
return this.cell.getF().getStringValue();
|
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Sets formula for this cell.
|
|
|
|
* <p>
|
|
|
|
* Note, this method only sets the formula string and does not calculate the formula value.
|
|
|
|
* To set the precalculated value use {@link #setCellValue(double)} or {@link #setCellValue(String)}
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @param formula the formula to set, e.g. <code>SUM(C4:E4)</code>.
|
|
|
|
* If the argument is <code>null</code> then the current formula is removed.
|
2008-12-04 13:38:00 -05:00
|
|
|
* @throws IllegalArgumentException if the formula is invalid
|
2008-10-23 14:57:28 -04:00
|
|
|
*/
|
|
|
|
public void setCellFormula(String formula) {
|
|
|
|
if (formula == null && cell.isSetF()) {
|
|
|
|
cell.unsetF();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-04 13:38:00 -05:00
|
|
|
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(row.getSheet().getWorkbook());
|
|
|
|
try {
|
|
|
|
Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL);
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
if (e.getClass().getName().startsWith(FormulaParser.class.getName())) {
|
|
|
|
throw new IllegalArgumentException("Unparsable formula '" + formula + "'", e);
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
CTCellFormula f = CTCellFormula.Factory.newInstance();
|
|
|
|
f.setStringValue(formula);
|
|
|
|
cell.setF(f);
|
|
|
|
if(cell.isSetV()) cell.unsetV();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns column index of this cell
|
|
|
|
*
|
|
|
|
* @return zero-based column index of a column in a sheet.
|
|
|
|
*/
|
2008-10-09 04:03:43 -04:00
|
|
|
public int getColumnIndex() {
|
|
|
|
return this.cellNum;
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
2008-10-23 14:57:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns row index of a row in the sheet that contains this cell
|
|
|
|
*
|
|
|
|
* @return zero-based row index of a row in the sheet that contains this cell
|
|
|
|
*/
|
|
|
|
public int getRowIndex() {
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-671321,671323-672229,672231-672549,672551-672552,672554-672561,672563-672566,672568,672571-673049,673051-673852,673854-673862,673864-673986,673988-673996,673998-674347,674349-674890,674892-674910,674912-674936,674938-674952,674954-675078,675080-675085,675087-675217,675219-675660,675662-675670,675672-675716,675718-675726,675728-675733,675735-675775,675777-675782,675784,675786-675791,675794-675852,675854-676200,676202,676204,676206-676220,676222-676309,676311-676456,676458-676994,676996-677027,677030-677040,677042-677056,677058-677375,677377-677968,677970-677971,677973,677975-677994,677996-678286,678288-678538,678540-680393,680395-680469,680471-680529,680531-680852,680854-681529,681531-681571,681573-682224,682226,682228,682231-682281,682283-682335,682337-682507,682509,682512-682517,682519-682532,682534-682619,682622-682777,682779-682998,683000-683019,683021-683022,683024-683080,683082-683092,683094-683095,683097-683127,683129-683131,683133-683166,683168-683698,683700-683705,683707-683757,683759-683787,683789-683870,683872-683879,683881-683900,683902-684066,684068-684074,684076-684222,684224-684254,684257-684370 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r684282 | nick | 2008-08-09 16:58:24 +0100 (Sat, 09 Aug 2008) | 1 line
Prepare to change how we do ranges, to handle different kinds of text in the cp area
........
r684287 | nick | 2008-08-09 17:24:20 +0100 (Sat, 09 Aug 2008) | 1 line
Start to document the whole FIB stuff better
........
r684293 | nick | 2008-08-09 17:46:39 +0100 (Sat, 09 Aug 2008) | 1 line
Add lots more getters/setters for useful things to the FIB
........
r684299 | nick | 2008-08-09 18:23:42 +0100 (Sat, 09 Aug 2008) | 1 line
More tests to show that the range based stuff is working properly
........
r684302 | nick | 2008-08-09 18:33:29 +0100 (Sat, 09 Aug 2008) | 1 line
More header and footer files, this time with unicode in it too
........
r684309 | nick | 2008-08-09 18:58:35 +0100 (Sat, 09 Aug 2008) | 1 line
More range tests, which show that we do have a bug in the hwpf unicode support
........
r684318 | josh | 2008-08-09 20:29:23 +0100 (Sat, 09 Aug 2008) | 1 line
Converted rows map within HSSFSheet to use Integer keys
........
r684319 | nick | 2008-08-09 20:34:38 +0100 (Sat, 09 Aug 2008) | 1 line
Big big unicode rationalisation in text piece code
........
r684321 | josh | 2008-08-09 20:47:39 +0100 (Sat, 09 Aug 2008) | 1 line
added getRowIndex() to HSSFCell, deprecated HSSFFormulaEvaluator.setCurrentRow()
........
r684322 | nick | 2008-08-09 20:56:37 +0100 (Sat, 09 Aug 2008) | 1 line
Get most of the hwpf tests passing again
........
r684336 | nick | 2008-08-09 21:31:48 +0100 (Sat, 09 Aug 2008) | 1 line
Improve FIB updating on range changes, and add passing tests for non unicode paragraph properties
........
r684349 | nick | 2008-08-09 22:31:28 +0100 (Sat, 09 Aug 2008) | 1 line
Start on headers/footers support
........
r684355 | nick | 2008-08-09 22:46:14 +0100 (Sat, 09 Aug 2008) | 1 line
Tests to show that header stuff all works right
........
r684362 | nick | 2008-08-09 23:08:34 +0100 (Sat, 09 Aug 2008) | 1 line
Add header/footer support to HWPF WordExtractor
........
r684370 | nick | 2008-08-09 23:24:47 +0100 (Sat, 09 Aug 2008) | 1 line
Disable a few HWPF tests that aren't working while the unicode/paragraph bug is outstanding
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@684374 13f79535-47bb-0310-9956-ffa450edef68
2008-08-09 18:55:33 -04:00
|
|
|
return row.getRowNum();
|
|
|
|
}
|
2008-01-16 11:08:22 -05:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Returns an A1 style reference to the location of this cell
|
|
|
|
*
|
|
|
|
* @return A1 style reference to the location of this cell
|
|
|
|
*/
|
|
|
|
public String getReference() {
|
|
|
|
return cell.getR();
|
|
|
|
}
|
|
|
|
|
2008-10-21 13:56:34 -04:00
|
|
|
/**
|
|
|
|
* Return the cell's style.
|
|
|
|
*
|
|
|
|
* @return the cell's style. Always not-null. Default cell style has zero index and can be obtained as
|
|
|
|
* <code>workbook.getCellStyleAt(0)</code>
|
|
|
|
*/
|
2008-09-25 02:51:18 -04:00
|
|
|
public XSSFCellStyle getCellStyle() {
|
2008-10-21 13:56:34 -04:00
|
|
|
long idx = cell.isSetS() ? cell.getS() : 0;
|
2008-10-25 07:48:50 -04:00
|
|
|
return stylesSource.getStyleAt((int)idx);
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Set the style for the cell. The style should be an XSSFCellStyle created/retreived from
|
|
|
|
* the XSSFWorkbook.
|
|
|
|
*
|
|
|
|
* @param style reference contained in the workbook.
|
|
|
|
* If the value is null then the style information is removed causing the cell to used the default workbook style.
|
|
|
|
*/
|
|
|
|
public void setCellStyle(CellStyle style) {
|
|
|
|
if(style == null) {
|
2008-10-29 15:12:47 -04:00
|
|
|
if(cell.isSetS()) cell.unsetS();
|
2008-10-23 14:57:28 -04:00
|
|
|
} else {
|
|
|
|
XSSFCellStyle xStyle = (XSSFCellStyle)style;
|
|
|
|
xStyle.verifyBelongsToStylesSource(stylesSource);
|
|
|
|
|
|
|
|
long idx = stylesSource.putStyle(xStyle);
|
|
|
|
cell.setS(idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the cell type.
|
|
|
|
*
|
|
|
|
* @return the cell type
|
|
|
|
* @see Cell#CELL_TYPE_BLANK
|
|
|
|
* @see Cell#CELL_TYPE_NUMERIC
|
|
|
|
* @see Cell#CELL_TYPE_STRING
|
|
|
|
* @see Cell#CELL_TYPE_FORMULA
|
|
|
|
* @see Cell#CELL_TYPE_BOOLEAN
|
|
|
|
* @see Cell#CELL_TYPE_ERROR
|
|
|
|
*/
|
2008-01-16 11:08:22 -05:00
|
|
|
public int getCellType() {
|
2008-10-23 14:57:28 -04:00
|
|
|
|
|
|
|
if (cell.getF() != null) {
|
2008-04-06 16:27:40 -04:00
|
|
|
return CELL_TYPE_FORMULA;
|
|
|
|
}
|
|
|
|
|
2008-01-16 11:08:22 -05:00
|
|
|
switch (this.cell.getT().intValue()) {
|
2008-10-23 14:57:28 -04:00
|
|
|
case STCellType.INT_B:
|
|
|
|
return CELL_TYPE_BOOLEAN;
|
|
|
|
case STCellType.INT_N:
|
|
|
|
if (!cell.isSetV()) {
|
|
|
|
// ooxml does have a separate cell type of 'blank'. A blank cell gets encoded as
|
|
|
|
// (either not present or) a numeric cell with no value set.
|
|
|
|
// The formula evaluator (and perhaps other clients of this interface) needs to
|
|
|
|
// distinguish blank values which sometimes get translated into zero and sometimes
|
|
|
|
// empty string, depending on context
|
|
|
|
return CELL_TYPE_BLANK;
|
|
|
|
}
|
|
|
|
return CELL_TYPE_NUMERIC;
|
|
|
|
case STCellType.INT_E:
|
|
|
|
return CELL_TYPE_ERROR;
|
|
|
|
case STCellType.INT_S: // String is in shared strings
|
|
|
|
case STCellType.INT_INLINE_STR: // String is inline in cell
|
|
|
|
return CELL_TYPE_STRING;
|
|
|
|
case STCellType.INT_STR:
|
|
|
|
return CELL_TYPE_FORMULA;
|
|
|
|
default:
|
|
|
|
throw new IllegalStateException("Illegal cell type: " + this.cell.getT());
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Get the value of the cell as a date.
|
|
|
|
* <p>
|
|
|
|
* For strings we throw an exception. For blank cells we return a null.
|
|
|
|
* </p>
|
|
|
|
* @return the value of the cell as a date
|
|
|
|
* @throws IllegalStateException if the cell type returned by {@link #getCellType()} is CELL_TYPE_STRING
|
|
|
|
* @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
|
2008-10-29 15:12:47 -04:00
|
|
|
* @see DataFormatter for formatting this date into a string similar to how excel does.
|
2008-10-23 14:57:28 -04:00
|
|
|
*/
|
2008-01-16 11:08:22 -05:00
|
|
|
public Date getDateCellValue() {
|
2008-10-23 14:57:28 -04:00
|
|
|
int cellType = getCellType();
|
|
|
|
if (cellType == CELL_TYPE_BLANK) {
|
|
|
|
return null;
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
2008-10-23 14:57:28 -04:00
|
|
|
|
|
|
|
double value = getNumericCellValue();
|
|
|
|
boolean date1904 = getSheet().getWorkbook().isDate1904();
|
|
|
|
return DateUtil.getJavaDate(value, date1904);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
|
|
|
|
* a date.
|
|
|
|
*
|
|
|
|
* @param value the date value to set this cell to. For formulas we'll set the
|
|
|
|
* precalculated value, for numerics we'll set its value. For other types we
|
|
|
|
* will change the cell to a numeric cell and set its value.
|
|
|
|
*/
|
|
|
|
public void setCellValue(Date value) {
|
|
|
|
boolean date1904 = getSheet().getWorkbook().isDate1904();
|
|
|
|
setCellValue(DateUtil.getExcelDate(value, date1904));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
|
|
|
|
* a date.
|
|
|
|
* <p>
|
|
|
|
* This will set the cell value based on the Calendar's timezone. As Excel
|
|
|
|
* does not support timezones this means that both 20:00+03:00 and
|
|
|
|
* 20:00-03:00 will be reported as the same value (20:00) even that there
|
|
|
|
* are 6 hours difference between the two times. This difference can be
|
|
|
|
* preserved by using <code>setCellValue(value.getTime())</code> which will
|
|
|
|
* automatically shift the times to the default timezone.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @param value the date value to set this cell to. For formulas we'll set the
|
|
|
|
* precalculated value, for numerics we'll set its value. For othertypes we
|
|
|
|
* will change the cell to a numeric cell and set its value.
|
|
|
|
*/
|
|
|
|
public void setCellValue(Calendar value) {
|
|
|
|
boolean date1904 = getSheet().getWorkbook().isDate1904();
|
|
|
|
setCellValue( DateUtil.getExcelDate(value, date1904 ));
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
|
|
|
|
2008-03-30 10:16:22 -04:00
|
|
|
/**
|
|
|
|
* Returns the error message, such as #VALUE!
|
2008-10-23 14:57:28 -04:00
|
|
|
*
|
|
|
|
* @return the error message such as #VALUE!
|
|
|
|
* @throws IllegalStateException if the cell type returned by {@link #getCellType()} isn't CELL_TYPE_ERROR
|
|
|
|
* @see FormulaError
|
2008-03-30 10:16:22 -04:00
|
|
|
*/
|
|
|
|
public String getErrorCellString() {
|
2008-10-23 14:57:28 -04:00
|
|
|
int cellType = getCellType();
|
|
|
|
if(cellType != CELL_TYPE_ERROR) throw typeMismatch(CELL_TYPE_ERROR, cellType, false);
|
|
|
|
|
|
|
|
return cell.getV();
|
2008-03-30 10:16:22 -04:00
|
|
|
}
|
|
|
|
/**
|
2008-10-23 14:57:28 -04:00
|
|
|
* Get the value of the cell as an error code.
|
|
|
|
* <p>
|
|
|
|
* For strings, numbers, and booleans, we throw an exception.
|
|
|
|
* For blank cells we return a 0.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @return the value of the cell as an error code
|
|
|
|
* @throws IllegalStateException if the cell type returned by {@link #getCellType()} isn't CELL_TYPE_ERROR
|
|
|
|
* @see FormulaError
|
2008-03-30 10:16:22 -04:00
|
|
|
*/
|
2008-01-16 11:08:22 -05:00
|
|
|
public byte getErrorCellValue() {
|
2008-10-23 14:57:28 -04:00
|
|
|
String code = getErrorCellString();
|
|
|
|
if(code == null) return 0;
|
2008-01-16 11:08:22 -05:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
return (byte)FormulaError.forString(code).getCode();
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
|
|
|
|
2008-10-01 13:15:02 -04:00
|
|
|
/**
|
2008-10-23 14:57:28 -04:00
|
|
|
* Set a error value for the cell
|
|
|
|
*
|
|
|
|
* @param errorCode the error value to set this cell to. For formulas we'll set the
|
|
|
|
* precalculated value , for errors we'll set
|
|
|
|
* its value. For other types we will change the cell to an error
|
|
|
|
* cell and set its value.
|
|
|
|
* @see FormulaError
|
2008-10-01 13:15:02 -04:00
|
|
|
*/
|
2008-10-23 14:57:28 -04:00
|
|
|
public void setCellErrorValue(byte errorCode) {
|
|
|
|
FormulaError error = FormulaError.forInt(errorCode);
|
|
|
|
setCellErrorValue(error);
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Set a error value for the cell
|
|
|
|
*
|
|
|
|
* @param error the error value to set this cell to. For formulas we'll set the
|
|
|
|
* precalculated value , for errors we'll set
|
|
|
|
* its value. For other types we will change the cell to an error
|
|
|
|
* cell and set its value.
|
|
|
|
*/
|
|
|
|
public void setCellErrorValue(FormulaError error) {
|
|
|
|
cell.setT(STCellType.E);
|
|
|
|
cell.setV(error.getString());
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
2008-04-06 16:27:40 -04:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Sets this cell as the active cell for the worksheet.
|
|
|
|
*/
|
|
|
|
public void setAsActiveCell() {
|
|
|
|
getSheet().setActiveCell(cell.getR());
|
|
|
|
}
|
2008-04-06 16:27:40 -04:00
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Blanks this cell. Blank cells have no formula or value but may have styling.
|
|
|
|
* This method erases all the data previously associated with this cell.
|
|
|
|
*/
|
|
|
|
private void setBlank(){
|
|
|
|
CTCell blank = CTCell.Factory.newInstance();
|
|
|
|
blank.setR(cell.getR());
|
|
|
|
cell.set(blank);
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Sets column index of this cell
|
|
|
|
*
|
|
|
|
* @param num column index of this cell
|
|
|
|
*/
|
2008-11-14 15:29:42 -05:00
|
|
|
protected void setCellNum(int num) {
|
2008-02-07 10:44:32 -05:00
|
|
|
checkBounds(num);
|
2008-10-23 14:57:28 -04:00
|
|
|
cellNum = num;
|
2008-12-04 13:38:00 -05:00
|
|
|
String ref = new CellReference(getRowIndex(), getColumnIndex()).formatAsString();
|
|
|
|
cell.setR(ref);
|
2008-02-07 10:44:32 -05:00
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Converts A1 style reference into 0-based column index
|
|
|
|
*
|
|
|
|
* @param r an A1 style reference to the location of this cell
|
|
|
|
* @return 0-based column index
|
|
|
|
*/
|
2008-02-07 10:44:32 -05:00
|
|
|
protected static short parseCellNum(String r) {
|
|
|
|
r = r.split("\\d+")[0];
|
|
|
|
if (r.length() == 1) {
|
|
|
|
return (short) (r.charAt(0) - 'A');
|
|
|
|
} else {
|
|
|
|
return (short) (r.charAt(1) - 'A' + 26 * (r.charAt(0) - '@'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-01 13:15:02 -04:00
|
|
|
/**
|
2008-10-23 14:57:28 -04:00
|
|
|
* Set the cells type (numeric, formula or string)
|
|
|
|
*
|
|
|
|
* @throws IllegalArgumentException if the specified cell type is invalid
|
2008-10-01 13:15:02 -04:00
|
|
|
* @see #CELL_TYPE_NUMERIC
|
|
|
|
* @see #CELL_TYPE_STRING
|
|
|
|
* @see #CELL_TYPE_FORMULA
|
|
|
|
* @see #CELL_TYPE_BLANK
|
|
|
|
* @see #CELL_TYPE_BOOLEAN
|
|
|
|
* @see #CELL_TYPE_ERROR
|
|
|
|
*/
|
2008-01-16 11:08:22 -05:00
|
|
|
public void setCellType(int cellType) {
|
|
|
|
switch (cellType) {
|
2008-10-23 14:57:28 -04:00
|
|
|
case CELL_TYPE_BLANK:
|
|
|
|
setBlank();
|
|
|
|
break;
|
|
|
|
case CELL_TYPE_BOOLEAN:
|
|
|
|
cell.setT(STCellType.B);
|
|
|
|
break;
|
|
|
|
case CELL_TYPE_NUMERIC:
|
|
|
|
cell.setT(STCellType.N);
|
|
|
|
break;
|
|
|
|
case CELL_TYPE_ERROR:
|
|
|
|
cell.setT(STCellType.E);
|
|
|
|
break;
|
|
|
|
case CELL_TYPE_STRING:
|
|
|
|
cell.setT(STCellType.S);
|
|
|
|
break;
|
|
|
|
case CELL_TYPE_FORMULA:
|
|
|
|
if(!cell.isSetF()){
|
|
|
|
CTCellFormula f = CTCellFormula.Factory.newInstance();
|
|
|
|
f.setStringValue("0");
|
|
|
|
cell.setF(f);
|
|
|
|
cell.unsetT();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException("Illegal cell type: " + cellType);
|
2008-04-06 16:27:40 -04:00
|
|
|
}
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
|
|
|
|
2008-10-01 13:15:02 -04:00
|
|
|
/**
|
|
|
|
* Returns a string representation of the cell
|
2008-10-23 14:57:28 -04:00
|
|
|
* <p>
|
|
|
|
* Formula cells return the formula string, rather than the formula result.
|
2008-10-01 13:15:02 -04:00
|
|
|
* Dates are displayed in dd-MMM-yyyy format
|
|
|
|
* Errors are displayed as #ERR<errIdx>
|
2008-10-23 14:57:28 -04:00
|
|
|
* </p>
|
2008-10-01 13:15:02 -04:00
|
|
|
*/
|
2008-01-16 11:08:22 -05:00
|
|
|
public String toString() {
|
2008-10-01 13:15:02 -04:00
|
|
|
switch (getCellType()) {
|
|
|
|
case CELL_TYPE_BLANK:
|
|
|
|
return "";
|
|
|
|
case CELL_TYPE_BOOLEAN:
|
|
|
|
return getBooleanCellValue() ? "TRUE" : "FALSE";
|
|
|
|
case CELL_TYPE_ERROR:
|
|
|
|
return ErrorEval.getText(getErrorCellValue());
|
|
|
|
case CELL_TYPE_FORMULA:
|
|
|
|
return getCellFormula();
|
|
|
|
case CELL_TYPE_NUMERIC:
|
|
|
|
if (DateUtil.isCellDateFormatted(this)) {
|
|
|
|
DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
|
|
|
|
return sdf.format(getDateCellValue());
|
|
|
|
} else {
|
|
|
|
return getNumericCellValue() + "";
|
|
|
|
}
|
|
|
|
case CELL_TYPE_STRING:
|
|
|
|
return getRichStringCellValue().toString();
|
|
|
|
default:
|
|
|
|
return "Unknown Cell Type: " + getCellType();
|
|
|
|
}
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|
2008-04-06 16:27:40 -04:00
|
|
|
|
2008-03-08 13:06:41 -05:00
|
|
|
/**
|
|
|
|
* Returns the raw, underlying ooxml value for the cell
|
2008-10-23 14:57:28 -04:00
|
|
|
* <p>
|
|
|
|
* If the cell contains a string, then this value is an index into
|
|
|
|
* the shared string table, pointing to the actual string value. Otherwise,
|
|
|
|
* the value of the cell is expressed directly in this element. Cells containing formulas express
|
|
|
|
* the last calculated result of the formula in this element.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @return the raw cell value as contained in the underlying CTCell bean,
|
|
|
|
* <code>null</code> for blank cells.
|
2008-03-08 13:06:41 -05:00
|
|
|
*/
|
|
|
|
public String getRawValue() {
|
2008-10-23 14:57:28 -04:00
|
|
|
return cell.getV();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to help format error messages
|
|
|
|
*/
|
|
|
|
private static String getCellTypeName(int cellTypeCode) {
|
|
|
|
switch (cellTypeCode) {
|
|
|
|
case CELL_TYPE_BLANK: return "blank";
|
|
|
|
case CELL_TYPE_STRING: return "text";
|
|
|
|
case CELL_TYPE_BOOLEAN: return "boolean";
|
|
|
|
case CELL_TYPE_ERROR: return "error";
|
|
|
|
case CELL_TYPE_NUMERIC: return "numeric";
|
|
|
|
case CELL_TYPE_FORMULA: return "formula";
|
|
|
|
}
|
|
|
|
return "#unknown cell type (" + cellTypeCode + ")#";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to help format error messages
|
|
|
|
*/
|
|
|
|
private static RuntimeException typeMismatch(int expectedTypeCode, int actualTypeCode, boolean isFormulaCell) {
|
|
|
|
String msg = "Cannot get a "
|
|
|
|
+ getCellTypeName(expectedTypeCode) + " value from a "
|
|
|
|
+ getCellTypeName(actualTypeCode) + " " + (isFormulaCell ? "formula " : "") + "cell";
|
|
|
|
return new IllegalStateException(msg);
|
2008-03-08 13:06:41 -05:00
|
|
|
}
|
2008-01-16 11:08:22 -05:00
|
|
|
|
2008-02-07 10:44:32 -05:00
|
|
|
/**
|
|
|
|
* @throws RuntimeException if the bounds are exceeded.
|
|
|
|
*/
|
2008-10-23 14:57:28 -04:00
|
|
|
private static void checkBounds(int cellNum) {
|
|
|
|
if (cellNum > MAX_COLUMN_NUMBER) {
|
2008-12-04 13:38:00 -05:00
|
|
|
throw new IllegalArgumentException("You cannot have more than "+MAX_COLUMN_NUMBER+" columns " +
|
2008-10-23 14:57:28 -04:00
|
|
|
"in a given row because Excel can't handle it");
|
2008-10-01 13:15:02 -04:00
|
|
|
} else if (cellNum < 0) {
|
2008-12-04 13:38:00 -05:00
|
|
|
throw new IllegalArgumentException("You cannot reference columns with an index of less then 0.");
|
2008-10-01 13:15:02 -04:00
|
|
|
}
|
2008-02-07 10:44:32 -05:00
|
|
|
}
|
|
|
|
|
2008-10-23 14:57:28 -04:00
|
|
|
/**
|
|
|
|
* Returns cell comment associated with this cell
|
|
|
|
*
|
|
|
|
* @return the cell comment associated with this cell or <code>null</code>
|
|
|
|
*/
|
|
|
|
public XSSFComment getCellComment() {
|
|
|
|
return getSheet().getCellComment(row.getRowNum(), getColumnIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assign a comment to this cell. If the supplied comment is null,
|
|
|
|
* the comment for this cell will be removed.
|
|
|
|
*
|
|
|
|
* @param comment comment associated with this cell
|
|
|
|
*/
|
|
|
|
public void setCellComment(Comment comment) {
|
|
|
|
String cellRef = new CellReference(row.getRowNum(), getColumnIndex()).formatAsString();
|
|
|
|
getSheet().setCellComment(cellRef, (XSSFComment)comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns hyperlink associated with this cell
|
|
|
|
*
|
|
|
|
* @return hyperlink associated with this cell or <code>null</code> if not found
|
|
|
|
*/
|
|
|
|
public XSSFHyperlink getHyperlink() {
|
|
|
|
return getSheet().getHyperlink(row.getRowNum(), cellNum);
|
2008-04-07 06:31:55 -04:00
|
|
|
}
|
2008-10-23 14:57:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Assign a hypelrink to this cell
|
|
|
|
*
|
|
|
|
* @param hyperlink the hypelrink to associate with this cell
|
|
|
|
*/
|
|
|
|
public void setHyperlink(Hyperlink hyperlink) {
|
2008-04-07 06:31:55 -04:00
|
|
|
XSSFHyperlink link = (XSSFHyperlink)hyperlink;
|
|
|
|
|
|
|
|
// Assign to us
|
|
|
|
link.setCellReference( new CellReference(row.getRowNum(), cellNum).formatAsString() );
|
|
|
|
|
|
|
|
// Add to the lists
|
2008-10-23 14:57:28 -04:00
|
|
|
getSheet().setCellHyperlink(link);
|
2008-04-07 06:31:55 -04:00
|
|
|
}
|
2008-10-23 14:57:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the xml bean containing information about the cell's location (reference), value,
|
|
|
|
* data type, formatting, and formula
|
|
|
|
*
|
|
|
|
* @return the xml bean containing information about this cell
|
|
|
|
*/
|
|
|
|
public CTCell getCTCell(){
|
|
|
|
return cell;
|
|
|
|
}
|
2008-10-30 05:42:53 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* update cell reference when shifting rows
|
|
|
|
*
|
|
|
|
* @param row
|
|
|
|
*/
|
|
|
|
protected void modifyCellReference(XSSFRow row) {
|
|
|
|
this.cell.setR(new CellReference(row.getRowNum(), cellNum).formatAsString());
|
|
|
|
|
|
|
|
CTCell[] ctCells = row.getCTRow().getCArray();
|
|
|
|
for (CTCell ctCell : ctCells) {
|
|
|
|
ctCell.setR(new CellReference(row.getRowNum(), cellNum).formatAsString());
|
|
|
|
}
|
|
|
|
}
|
2008-01-16 11:08:22 -05:00
|
|
|
}
|