Przeglądaj źródła

minor changes - initial work on bugzilla 48292 (support for array formulas)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@885006 13f79535-47bb-0310-9956-ffa450edef68
pull/1/head
Josh Micich 14 lat temu
rodzic
commit
c73dd9d324

+ 10
- 4
src/java/org/apache/poi/hssf/record/SharedValueRecordBase.java Wyświetl plik

@@ -24,7 +24,7 @@ import org.apache.poi.util.LittleEndianOutput;
/**
* Common base class for {@link SharedFormulaRecord}, {@link ArrayRecord} and
* {@link TableRecord} which are have similarities.
*
*
* @author Josh Micich
*/
public abstract class SharedValueRecordBase extends StandardRecord {
@@ -32,6 +32,9 @@ public abstract class SharedValueRecordBase extends StandardRecord {
private CellRangeAddress8Bit _range;

protected SharedValueRecordBase(CellRangeAddress8Bit range) {
if (range == null) {
throw new IllegalArgumentException("range must be supplied.");
}
_range = range;
}

@@ -46,6 +49,9 @@ public abstract class SharedValueRecordBase extends StandardRecord {
_range = new CellRangeAddress8Bit(in);
}

/**
* @return the range of cells that this record is shared across. Never <code>null</code>.
*/
public final CellRangeAddress8Bit getRange() {
return _range;
}
@@ -85,13 +91,13 @@ public abstract class SharedValueRecordBase extends StandardRecord {
*/
public final boolean isInRange(int rowIx, int colIx) {
CellRangeAddress8Bit r = _range;
return r.getFirstRow() <= rowIx
return r.getFirstRow() <= rowIx
&& r.getLastRow() >= rowIx
&& r.getFirstColumn() <= colIx
&& r.getFirstColumn() <= colIx
&& r.getLastColumn() >= colIx;
}
/**
* @return <code>true</code> if (rowIx, colIx) describes the first cell in this shared value
* @return <code>true</code> if (rowIx, colIx) describes the first cell in this shared value
* object's range ({@link #getRange()})
*/
public final boolean isFirstCell(int rowIx, int colIx) {

+ 13
- 12
src/java/org/apache/poi/hssf/record/formula/ExpPtg.java Wyświetl plik

@@ -30,41 +30,42 @@ import org.apache.poi.util.LittleEndianOutput;
public final class ExpPtg extends ControlPtg {
private final static int SIZE = 5;
public final static short sid = 0x1;
private final short field_1_first_row;
private final short field_2_first_col;
private final int field_1_first_row;
private final int field_2_first_col;

public ExpPtg(LittleEndianInput in)
{
public ExpPtg(LittleEndianInput in) {
field_1_first_row = in.readShort();
field_2_first_col = in.readShort();
}

public ExpPtg(int firstRow, int firstCol) {
this.field_1_first_row = firstRow;
this.field_2_first_col = firstCol;
}

public void write(LittleEndianOutput out) {
out.writeByte(sid + getPtgClass());
out.writeShort(field_1_first_row);
out.writeShort(field_2_first_col);
}

public int getSize()
{
public int getSize() {
return SIZE;
}

public short getRow() {
public int getRow() {
return field_1_first_row;
}

public short getColumn() {
public int getColumn() {
return field_2_first_col;
}

public String toFormulaString()
{
public String toFormulaString() {
throw new RecordFormatException("Coding Error: Expected ExpPtg to be converted from Shared to Non-Shared Formula by ValueRecordsAggregate, but it wasn't");
}

public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer("[Array Formula or Shared Formula]\n");
buffer.append("row = ").append(getRow()).append("\n");
buffer.append("col = ").append(getColumn()).append("\n");

+ 48
- 42
src/java/org/apache/poi/ss/util/CellRangeAddressBase.java Wyświetl plik

@@ -6,7 +6,7 @@
(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
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,
@@ -18,13 +18,14 @@
package org.apache.poi.ss.util;

import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;


/**
* See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address'<p/>
*
*
* Common subclass of 8-bit and 16-bit versions
*
*
* @author Josh Micich
*/
public abstract class CellRangeAddressBase {
@@ -41,44 +42,44 @@ public abstract class CellRangeAddressBase {
_lastCol = lastCol;
}

/**
* Validate the range limits against the supplied version of Excel
*
* @param ssVersion the version of Excel to validate against
* @throws IllegalArgumentException if the range limits are outside of the allowed range
*/
public void validate(SpreadsheetVersion ssVersion) {
validateRow(_firstRow, ssVersion);
/**
* Validate the range limits against the supplied version of Excel
*
* @param ssVersion the version of Excel to validate against
* @throws IllegalArgumentException if the range limits are outside of the allowed range
*/
public void validate(SpreadsheetVersion ssVersion) {
validateRow(_firstRow, ssVersion);
validateRow(_lastRow, ssVersion);
validateColumn(_firstCol, ssVersion);
validateColumn(_firstCol, ssVersion);
validateColumn(_lastCol, ssVersion);
}
/**
* Runs a bounds check for row numbers
* @param row
*/
private static void validateRow(int row, SpreadsheetVersion ssVersion) {
int maxrow = ssVersion.getLastRowIndex();
if (row > maxrow) throw new IllegalArgumentException("Maximum row number is " + maxrow);
if (row < 0) throw new IllegalArgumentException("Minumum row number is 0");
}
/**
* Runs a bounds check for column numbers
* @param column
*/
private static void validateColumn(int column, SpreadsheetVersion ssVersion) {
int maxcol = ssVersion.getLastColumnIndex();
if (column > maxcol) throw new IllegalArgumentException("Maximum column number is " + maxcol);
if (column < 0) throw new IllegalArgumentException("Minimum column number is 0");
}
//TODO use the correct SpreadsheetVersion
public final boolean isFullColumnRange() {
/**
* Runs a bounds check for row numbers
* @param row
*/
private static void validateRow(int row, SpreadsheetVersion ssVersion) {
int maxrow = ssVersion.getLastRowIndex();
if (row > maxrow) throw new IllegalArgumentException("Maximum row number is " + maxrow);
if (row < 0) throw new IllegalArgumentException("Minumum row number is 0");
}
/**
* Runs a bounds check for column numbers
* @param column
*/
private static void validateColumn(int column, SpreadsheetVersion ssVersion) {
int maxcol = ssVersion.getLastColumnIndex();
if (column > maxcol) throw new IllegalArgumentException("Maximum column number is " + maxcol);
if (column < 0) throw new IllegalArgumentException("Minimum column number is 0");
}
//TODO use the correct SpreadsheetVersion
public final boolean isFullColumnRange() {
return _firstRow == 0 && _lastRow == SpreadsheetVersion.EXCEL97.getLastRowIndex();
}
//TODO use the correct SpreadsheetVersion
//TODO use the correct SpreadsheetVersion
public final boolean isFullRowRange() {
return _firstCol == 0 && _lastCol == SpreadsheetVersion.EXCEL97.getLastColumnIndex();
}
@@ -111,6 +112,11 @@ public abstract class CellRangeAddressBase {
return _lastRow;
}

public boolean isInRange(int rowInd, int colInd) {
return _firstRow <= rowInd && rowInd <= _lastRow &&
_firstCol <= colInd && colInd <= _lastCol;
}

/**
* @param firstCol column number for the upper left hand corner
*/
@@ -138,12 +144,12 @@ public abstract class CellRangeAddressBase {
public final void setLastRow(int lastRow) {
_lastRow = lastRow;
}
/**
* @return the size of the range (number of cells in the area).
*/
public int getNumberOfCells() {
return (_lastRow - _firstRow + 1) * (_lastCol - _firstCol + 1);
}
/**
* @return the size of the range (number of cells in the area).
*/
public int getNumberOfCells() {
return (_lastRow - _firstRow + 1) * (_lastCol - _firstCol + 1);
}

public final String toString() {
CellReference crA = new CellReference(_firstRow, _firstCol);

+ 1
- 1
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Wyświetl plik

@@ -888,7 +888,7 @@ public final class XSSFCell implements Cell {
int sstIndex = Integer.parseInt(_cell.getV());
XSSFRichTextString rt = new XSSFRichTextString(_sharedStringSource.getEntryAt(sstIndex));
String text = rt.getString();
return Boolean.valueOf(text);
return Boolean.parseBoolean(text);
case CELL_TYPE_NUMERIC:
return Double.parseDouble(_cell.getV()) != 0;


+ 706
- 705
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
Plik diff jest za duży
Wyświetl plik


Ładowanie…
Anuluj
Zapisz