move cleaned up jxl into this project, get rid of log4j dependency
This commit is contained in:
parent
fe833de27a
commit
0925fc31f5
451 changed files with 80883 additions and 7 deletions
15
datastructures-xslx/NOTICE.txt
Normal file
15
datastructures-xslx/NOTICE.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
datastructures-xslx is composed of the following works
|
||||
|
||||
jxl
|
||||
https://sourceforge.net/projects/jexcelapi/
|
||||
GNU Library or Lesser General Public License version 2.0 (LGPLv2)
|
||||
|
||||
with the log4j dependency removed
|
||||
|
||||
and
|
||||
|
||||
com.incesoft.tools.excel
|
||||
https://code.google.com/archive/p/sjxslx/ -> https://github.com/davidpelfree/sjxlsx
|
||||
License: Apache License 2.0
|
||||
|
||||
The code will be refactored to the org.xbib package group.
|
|
@ -1,3 +0,0 @@
|
|||
dependencies {
|
||||
implementation libs.jxl
|
||||
}
|
45
datastructures-xslx/src/main/java/jxl/BooleanCell.java
Executable file
45
datastructures-xslx/src/main/java/jxl/BooleanCell.java
Executable file
|
@ -0,0 +1,45 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* This type represents the Microsoft concept of a Boolean. Accordingly, this
|
||||
* cell represents either TRUE, FALSE or an error condition. This third
|
||||
* state naturally makes handling BooleanCells quite tricky, and use of
|
||||
* the specific access methods should be handled with care
|
||||
*/
|
||||
public interface BooleanCell extends Cell {
|
||||
/**
|
||||
* Gets the boolean value stored in this cell. If this cell contains an
|
||||
* error, then returns FALSE. Always query this cell type using the
|
||||
* accessor method isError() prior to calling this method
|
||||
*
|
||||
* @return TRUE if this cell contains TRUE, FALSE if it contains FALSE or
|
||||
* an error code
|
||||
*/
|
||||
boolean getValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
27
datastructures-xslx/src/main/java/jxl/BooleanFormulaCell.java
Executable file
27
datastructures-xslx/src/main/java/jxl/BooleanFormulaCell.java
Executable file
|
@ -0,0 +1,27 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* A mixin interface for numerical formulas, which combines the interfaces
|
||||
* for formulas and for numbers
|
||||
*/
|
||||
public interface BooleanFormulaCell extends BooleanCell, FormulaCell {
|
||||
}
|
86
datastructures-xslx/src/main/java/jxl/Cell.java
Executable file
86
datastructures-xslx/src/main/java/jxl/Cell.java
Executable file
|
@ -0,0 +1,86 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import jxl.format.CellFormat;
|
||||
|
||||
/**
|
||||
* Represents an individual Cell within a Sheet. May be queried for its
|
||||
* type and its content
|
||||
*/
|
||||
public interface Cell {
|
||||
/**
|
||||
* Returns the row number of this cell
|
||||
*
|
||||
* @return the row number of this cell
|
||||
*/
|
||||
int getRow();
|
||||
|
||||
/**
|
||||
* Returns the column number of this cell
|
||||
*
|
||||
* @return the column number of this cell
|
||||
*/
|
||||
int getColumn();
|
||||
|
||||
/**
|
||||
* Returns the content type of this cell
|
||||
*
|
||||
* @return the content type for this cell
|
||||
*/
|
||||
CellType getType();
|
||||
|
||||
/**
|
||||
* Indicates whether or not this cell is hidden, by virtue of either
|
||||
* the entire row or column being collapsed
|
||||
*
|
||||
* @return TRUE if this cell is hidden, FALSE otherwise
|
||||
*/
|
||||
boolean isHidden();
|
||||
|
||||
/**
|
||||
* Quick and dirty function to return the contents of this cell as a string.
|
||||
* For more complex manipulation of the contents, it is necessary to cast
|
||||
* this interface to correct subinterface
|
||||
*
|
||||
* @return the contents of this cell as a string
|
||||
*/
|
||||
String getContents();
|
||||
|
||||
/**
|
||||
* Gets the cell format which applies to this cell
|
||||
* Note that for cell with a cell type of EMPTY, which has no formatting
|
||||
* information, this method will return null. Some empty cells (eg. on
|
||||
* template spreadsheets) may have a cell type of EMPTY, but will
|
||||
* actually contain formatting information
|
||||
*
|
||||
* @return the cell format applied to this cell, or NULL if this is an
|
||||
* empty cell
|
||||
*/
|
||||
CellFormat getCellFormat();
|
||||
|
||||
/**
|
||||
* Gets any special cell features, such as comments (notes) or cell
|
||||
* validation present for this cell
|
||||
*
|
||||
* @return the cell features, or NULL if this cell has no special features
|
||||
*/
|
||||
CellFeatures getCellFeatures();
|
||||
}
|
74
datastructures-xslx/src/main/java/jxl/CellFeatures.java
Executable file
74
datastructures-xslx/src/main/java/jxl/CellFeatures.java
Executable file
|
@ -0,0 +1,74 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2004 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import jxl.biff.BaseCellFeatures;
|
||||
|
||||
/**
|
||||
* Container for any additional cell features
|
||||
*/
|
||||
public class CellFeatures extends BaseCellFeatures {
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public CellFeatures() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @param cf cell to copy
|
||||
*/
|
||||
protected CellFeatures(CellFeatures cf) {
|
||||
super(cf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the cell comment
|
||||
*
|
||||
* @return the cell comment, or NULL if this cell doesn't have
|
||||
* a comment associated with it
|
||||
*/
|
||||
public String getComment() {
|
||||
return super.getComment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data validation list
|
||||
*
|
||||
* @return the data validation list
|
||||
*/
|
||||
public String getDataValidationList() {
|
||||
return super.getDataValidationList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the range of cells to which the data validation applies. If the
|
||||
* validation applies to just this cell, this will be reflected in the
|
||||
* returned range
|
||||
*
|
||||
* @return the range to which the same validation extends, or NULL if this
|
||||
* cell doesn't have a validation
|
||||
*/
|
||||
public Range getSharedDataValidationRange() {
|
||||
return super.getSharedDataValidationRange();
|
||||
}
|
||||
}
|
28
datastructures-xslx/src/main/java/jxl/CellFormat.java
Executable file
28
datastructures-xslx/src/main/java/jxl/CellFormat.java
Executable file
|
@ -0,0 +1,28 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* Interface for cell formats - used for typing information
|
||||
*
|
||||
* @deprecated Repackaged as jxl.format.CellFormat
|
||||
*/
|
||||
public interface CellFormat extends jxl.format.CellFormat {
|
||||
}
|
254
datastructures-xslx/src/main/java/jxl/CellReferenceHelper.java
Executable file
254
datastructures-xslx/src/main/java/jxl/CellReferenceHelper.java
Executable file
|
@ -0,0 +1,254 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2003 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import jxl.write.WritableWorkbook;
|
||||
|
||||
/**
|
||||
* Exposes some cell reference helper methods to the public interface.
|
||||
* This class merely delegates to the internally used reference helper
|
||||
*/
|
||||
public final class CellReferenceHelper {
|
||||
/**
|
||||
* Hide the default constructor
|
||||
*/
|
||||
private CellReferenceHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the cell reference for the column and row passed in to the string
|
||||
* buffer
|
||||
*
|
||||
* @param column the column
|
||||
* @param row the row
|
||||
* @param buf the string buffer to append
|
||||
*/
|
||||
public static void getCellReference(int column, int row, StringBuffer buf) {
|
||||
jxl.biff.CellReferenceHelper.getCellReference(column, row, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded method which prepends $ for absolute reference
|
||||
*
|
||||
* @param column the column number
|
||||
* @param colabs TRUE if the column reference is absolute
|
||||
* @param row the row number
|
||||
* @param rowabs TRUE if the row reference is absolute
|
||||
* @param buf the string buffer
|
||||
*/
|
||||
public static void getCellReference(int column,
|
||||
boolean colabs,
|
||||
int row,
|
||||
boolean rowabs,
|
||||
StringBuffer buf) {
|
||||
jxl.biff.CellReferenceHelper.getCellReference(column, colabs,
|
||||
row, rowabs,
|
||||
buf);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the cell reference for the specified column and row
|
||||
*
|
||||
* @param column the column
|
||||
* @param row the row
|
||||
* @return the cell reference
|
||||
*/
|
||||
public static String getCellReference(int column, int row) {
|
||||
return jxl.biff.CellReferenceHelper.getCellReference(column, row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the columnn number of the string cell reference
|
||||
*
|
||||
* @param s the string to parse
|
||||
* @return the column portion of the cell reference
|
||||
*/
|
||||
public static int getColumn(String s) {
|
||||
return jxl.biff.CellReferenceHelper.getColumn(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the column letter corresponding to the 0-based column number
|
||||
*
|
||||
* @param c the column number
|
||||
* @return the letter for that column number
|
||||
*/
|
||||
public static String getColumnReference(int c) {
|
||||
return jxl.biff.CellReferenceHelper.getColumnReference(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the row number of the cell reference
|
||||
*
|
||||
* @param s the cell reference
|
||||
* @return the row number
|
||||
*/
|
||||
public static int getRow(String s) {
|
||||
return jxl.biff.CellReferenceHelper.getRow(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sees if the column component is relative or not
|
||||
*
|
||||
* @param s the cell
|
||||
* @return TRUE if the column is relative, FALSE otherwise
|
||||
*/
|
||||
public static boolean isColumnRelative(String s) {
|
||||
return jxl.biff.CellReferenceHelper.isColumnRelative(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sees if the row component is relative or not
|
||||
*
|
||||
* @param s the cell
|
||||
* @return TRUE if the row is relative, FALSE otherwise
|
||||
*/
|
||||
public static boolean isRowRelative(String s) {
|
||||
return jxl.biff.CellReferenceHelper.isRowRelative(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully qualified cell reference given the column, row
|
||||
* external sheet reference etc
|
||||
*
|
||||
* @param sheet the sheet index
|
||||
* @param column the column index
|
||||
* @param row the row index
|
||||
* @param workbook the workbook
|
||||
* @param buf a string buffer
|
||||
*/
|
||||
public static void getCellReference
|
||||
(int sheet, int column, int row,
|
||||
Workbook workbook, StringBuffer buf) {
|
||||
jxl.biff.CellReferenceHelper.getCellReference
|
||||
(sheet, column, row, (jxl.biff.formula.ExternalSheet) workbook, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully qualified cell reference given the column, row
|
||||
* external sheet reference etc
|
||||
*
|
||||
* @param sheet the sheet
|
||||
* @param column the column
|
||||
* @param row the row
|
||||
* @param workbook the workbook
|
||||
* @param buf the buffer
|
||||
*/
|
||||
public static void getCellReference(int sheet,
|
||||
int column,
|
||||
int row,
|
||||
WritableWorkbook workbook,
|
||||
StringBuffer buf) {
|
||||
jxl.biff.CellReferenceHelper.getCellReference
|
||||
(sheet, column, row, (jxl.biff.formula.ExternalSheet) workbook, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully qualified cell reference given the column, row
|
||||
* external sheet reference etc
|
||||
*
|
||||
* @param sheet the sheet
|
||||
* @param column the column
|
||||
* @param colabs TRUE if the column is an absolute reference
|
||||
* @param row the row
|
||||
* @param rowabs TRUE if the row is an absolute reference
|
||||
* @param workbook the workbook
|
||||
* @param buf the string buffer
|
||||
*/
|
||||
public static void getCellReference(int sheet,
|
||||
int column,
|
||||
boolean colabs,
|
||||
int row,
|
||||
boolean rowabs,
|
||||
Workbook workbook,
|
||||
StringBuffer buf) {
|
||||
jxl.biff.CellReferenceHelper.getCellReference
|
||||
(sheet, column, colabs, row, rowabs,
|
||||
(jxl.biff.formula.ExternalSheet) workbook, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully qualified cell reference given the column, row
|
||||
* external sheet reference etc
|
||||
*
|
||||
* @param sheet the sheet
|
||||
* @param column the column
|
||||
* @param row the row
|
||||
* @param workbook the workbook
|
||||
* @return the cell reference in the form 'Sheet 1'!A1
|
||||
*/
|
||||
public static String getCellReference(int sheet,
|
||||
int column,
|
||||
int row,
|
||||
Workbook workbook) {
|
||||
return jxl.biff.CellReferenceHelper.getCellReference
|
||||
(sheet, column, row, (jxl.biff.formula.ExternalSheet) workbook);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully qualified cell reference given the column, row
|
||||
* external sheet reference etc
|
||||
*
|
||||
* @param sheet the sheet
|
||||
* @param column the column
|
||||
* @param row the row
|
||||
* @param workbook the workbook
|
||||
* @return the cell reference in the form 'Sheet 1'!A1
|
||||
*/
|
||||
public static String getCellReference(int sheet,
|
||||
int column,
|
||||
int row,
|
||||
WritableWorkbook workbook) {
|
||||
return jxl.biff.CellReferenceHelper.getCellReference
|
||||
(sheet, column, row, (jxl.biff.formula.ExternalSheet) workbook);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the sheet name from the cell reference string
|
||||
*
|
||||
* @param ref the cell reference
|
||||
* @return the sheet name
|
||||
*/
|
||||
public static String getSheet(String ref) {
|
||||
return jxl.biff.CellReferenceHelper.getSheet(ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell reference for the cell
|
||||
*
|
||||
* @param the cell
|
||||
*/
|
||||
public static String getCellReference(Cell c) {
|
||||
return getCellReference(c.getColumn(), c.getRow());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell reference for the cell
|
||||
*
|
||||
* @param c the cell
|
||||
* @param sb string buffer
|
||||
*/
|
||||
public static void getCellReference(Cell c, StringBuffer sb) {
|
||||
getCellReference(c.getColumn(), c.getRow(), sb);
|
||||
}
|
||||
|
||||
}
|
97
datastructures-xslx/src/main/java/jxl/CellType.java
Executable file
97
datastructures-xslx/src/main/java/jxl/CellType.java
Executable file
|
@ -0,0 +1,97 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* An enumeration type listing the available content types for a cell
|
||||
*/
|
||||
public final class CellType {
|
||||
|
||||
/**
|
||||
* An empty cell can still contain formatting information and comments
|
||||
*/
|
||||
public static final CellType EMPTY = new CellType("Empty");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final CellType LABEL = new CellType("Label");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final CellType NUMBER = new CellType("Number");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final CellType BOOLEAN = new CellType("Boolean");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final CellType ERROR = new CellType("Error");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final CellType NUMBER_FORMULA =
|
||||
new CellType("Numerical Formula");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final CellType DATE_FORMULA = new CellType("Date Formula");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final CellType STRING_FORMULA = new CellType("String Formula");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final CellType BOOLEAN_FORMULA =
|
||||
new CellType("Boolean Formula");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final CellType FORMULA_ERROR = new CellType("Formula Error");
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final CellType DATE = new CellType("Date");
|
||||
/**
|
||||
* The text description of this cell type
|
||||
*/
|
||||
private final String description;
|
||||
/**
|
||||
* Private constructor
|
||||
*
|
||||
* @param desc the description of this type
|
||||
*/
|
||||
private CellType(String desc) {
|
||||
description = desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string description of this cell
|
||||
*
|
||||
* @return the string description for this type
|
||||
*/
|
||||
public String toString() {
|
||||
return description;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
196
datastructures-xslx/src/main/java/jxl/CellView.java
Executable file
196
datastructures-xslx/src/main/java/jxl/CellView.java
Executable file
|
@ -0,0 +1,196 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import jxl.format.CellFormat;
|
||||
|
||||
/**
|
||||
* This is a bean which client applications may use to get/set various
|
||||
* properties for a row or column on a spreadsheet
|
||||
*/
|
||||
public final class CellView {
|
||||
/**
|
||||
* The dimension for the associated group of cells. For columns this
|
||||
* will be width in characters, for rows this will be the
|
||||
* height in points
|
||||
* This attribute is deprecated in favour of the size attribute
|
||||
*/
|
||||
private int dimension;
|
||||
|
||||
/**
|
||||
* The size for the associated group of cells. For columns this
|
||||
* will be width in characters multiplied by 256, for rows this will be the
|
||||
* height in points
|
||||
*/
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* Indicates whether the deprecated function was used to set the dimension
|
||||
*/
|
||||
private boolean depUsed;
|
||||
|
||||
/**
|
||||
* Indicates whether or not this sheet is hidden
|
||||
*/
|
||||
private boolean hidden;
|
||||
|
||||
/**
|
||||
* The cell format for the row/column
|
||||
*/
|
||||
private CellFormat format;
|
||||
|
||||
/**
|
||||
* Indicates that this column/row should be autosized
|
||||
*/
|
||||
private boolean autosize;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public CellView() {
|
||||
hidden = false;
|
||||
depUsed = false;
|
||||
dimension = 1;
|
||||
size = 1;
|
||||
autosize = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
public CellView(CellView cv) {
|
||||
hidden = cv.hidden;
|
||||
depUsed = cv.depUsed;
|
||||
dimension = cv.dimension;
|
||||
size = cv.size;
|
||||
autosize = cv.autosize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the hidden nature of this row/column
|
||||
*
|
||||
* @return TRUE if this row/column is hidden, FALSE otherwise
|
||||
*/
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hidden status of this row/column
|
||||
*
|
||||
* @param h the hidden flag
|
||||
*/
|
||||
public void setHidden(boolean h) {
|
||||
hidden = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of the column in characters or the height of the
|
||||
* row in 1/20ths
|
||||
*
|
||||
* @return the dimension
|
||||
* @deprecated use getSize() instead
|
||||
*/
|
||||
public int getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the dimension for this view
|
||||
*
|
||||
* @param d the width of the column in characters, or the height of the
|
||||
* row in 1/20ths of a point
|
||||
* @deprecated use the setSize method instead
|
||||
*/
|
||||
public void setDimension(int d) {
|
||||
dimension = d;
|
||||
depUsed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of the column in characters multiplied by 256, or the
|
||||
* height of the row in 1/20ths of a point
|
||||
*
|
||||
* @return the dimension
|
||||
*/
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the dimension for this view
|
||||
*
|
||||
* @param d the width of the column in characters multiplied by 256,
|
||||
* or the height of the row in 1/20ths of a point
|
||||
*/
|
||||
public void setSize(int d) {
|
||||
size = d;
|
||||
depUsed = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the cell format for this group.
|
||||
*
|
||||
* @return the format for the column/row, or NULL if no format was
|
||||
* specified
|
||||
*/
|
||||
public CellFormat getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cell format for this group of cells
|
||||
*
|
||||
* @param cf the format for every cell in the column/row
|
||||
*/
|
||||
public void setFormat(CellFormat cf) {
|
||||
format = cf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the depUsed attribute
|
||||
*
|
||||
* @return TRUE if the deprecated methods were used to set the size,
|
||||
* FALSE otherwise
|
||||
*/
|
||||
public boolean depUsed() {
|
||||
return depUsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the autosize flag
|
||||
* NOTE: use of the autosize function is very processor intensive, so
|
||||
* use with care
|
||||
*
|
||||
* @return TRUE if this row/column is to be autosized
|
||||
*/
|
||||
public boolean isAutosize() {
|
||||
return autosize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the autosize flag. Currently, this only works for column views
|
||||
*
|
||||
* @param a autosize
|
||||
*/
|
||||
public void setAutosize(boolean a) {
|
||||
autosize = a;
|
||||
}
|
||||
}
|
53
datastructures-xslx/src/main/java/jxl/DateCell.java
Executable file
53
datastructures-xslx/src/main/java/jxl/DateCell.java
Executable file
|
@ -0,0 +1,53 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* A date cell
|
||||
*/
|
||||
public interface DateCell extends Cell {
|
||||
/**
|
||||
* Gets the date contained in this cell
|
||||
*
|
||||
* @return the cell contents
|
||||
*/
|
||||
Date getDate();
|
||||
|
||||
/**
|
||||
* Indicates whether the date value contained in this cell refers to a date,
|
||||
* or merely a time
|
||||
*
|
||||
* @return TRUE if the value refers to a time
|
||||
*/
|
||||
boolean isTime();
|
||||
|
||||
/**
|
||||
* Gets the DateFormat used to format the cell. This will normally be
|
||||
* the format specified in the excel spreadsheet, but in the event of any
|
||||
* difficulty parsing this, it will revert to the default date/time format.
|
||||
*
|
||||
* @return the DateFormat object used to format the date in the original
|
||||
* excel cell
|
||||
*/
|
||||
DateFormat getDateFormat();
|
||||
}
|
27
datastructures-xslx/src/main/java/jxl/DateFormulaCell.java
Executable file
27
datastructures-xslx/src/main/java/jxl/DateFormulaCell.java
Executable file
|
@ -0,0 +1,27 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2003 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* A mixin interface for date formulas, which combines the interfaces
|
||||
* for formulas and for dates
|
||||
*/
|
||||
public interface DateFormulaCell extends DateCell, FormulaCell {
|
||||
}
|
36
datastructures-xslx/src/main/java/jxl/ErrorCell.java
Executable file
36
datastructures-xslx/src/main/java/jxl/ErrorCell.java
Executable file
|
@ -0,0 +1,36 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* This type represents a cell which contains an error. This error will
|
||||
* usually, but not always be the result of some error resulting from
|
||||
* a formula
|
||||
*/
|
||||
public interface ErrorCell extends Cell {
|
||||
/**
|
||||
* Gets the error code for this cell. If this cell does not represent
|
||||
* an error, then it returns 0. Always use the method isError() to
|
||||
* determine this prior to calling this method
|
||||
*
|
||||
* @return the error code if this cell contains an error, 0 otherwise
|
||||
*/
|
||||
int getErrorCode();
|
||||
}
|
27
datastructures-xslx/src/main/java/jxl/ErrorFormulaCell.java
Executable file
27
datastructures-xslx/src/main/java/jxl/ErrorFormulaCell.java
Executable file
|
@ -0,0 +1,27 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* A mixin interface for numerical formulas, which combines the interfaces
|
||||
* for formulas and for numbers
|
||||
*/
|
||||
public interface ErrorFormulaCell extends ErrorCell, FormulaCell {
|
||||
}
|
35
datastructures-xslx/src/main/java/jxl/FormulaCell.java
Executable file
35
datastructures-xslx/src/main/java/jxl/FormulaCell.java
Executable file
|
@ -0,0 +1,35 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import jxl.biff.formula.FormulaException;
|
||||
|
||||
/**
|
||||
* Interface for formulas which allow clients to read the Excel formula
|
||||
*/
|
||||
public interface FormulaCell extends Cell {
|
||||
/**
|
||||
* Gets the formula as a string
|
||||
*
|
||||
* @return the formula as a string
|
||||
* @throws FormulaException if an error occurred whilst parsing
|
||||
*/
|
||||
String getFormula() throws FormulaException;
|
||||
}
|
344
datastructures-xslx/src/main/java/jxl/HeaderFooter.java
Executable file
344
datastructures-xslx/src/main/java/jxl/HeaderFooter.java
Executable file
|
@ -0,0 +1,344 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan, Eric Jung
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* Class which represents an Excel header or footer.
|
||||
*/
|
||||
public final class HeaderFooter extends jxl.biff.HeaderFooter {
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public HeaderFooter() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @param hf the item to copy
|
||||
*/
|
||||
public HeaderFooter(HeaderFooter hf) {
|
||||
super(hf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used when reading workbooks to separate the left, right
|
||||
* a central part of the strings into their constituent parts
|
||||
*
|
||||
* @param s the header string
|
||||
*/
|
||||
public HeaderFooter(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a <code>String</code>ified
|
||||
* version of this object
|
||||
*
|
||||
* @return the header string
|
||||
*/
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the contents which appear on the right hand side of the page
|
||||
*
|
||||
* @return the right aligned contents
|
||||
*/
|
||||
public Contents getRight() {
|
||||
return (Contents) super.getRightText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the contents which in the centre of the page
|
||||
*
|
||||
* @return the centrally aligned contents
|
||||
*/
|
||||
public Contents getCentre() {
|
||||
return (Contents) super.getCentreText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the contents which appear on the left hand side of the page
|
||||
*
|
||||
* @return the left aligned contents
|
||||
*/
|
||||
public Contents getLeft() {
|
||||
return (Contents) super.getLeftText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the contents of the header/footer
|
||||
*/
|
||||
public void clear() {
|
||||
super.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates internal class of the appropriate type
|
||||
*
|
||||
* @return the created contents
|
||||
*/
|
||||
protected jxl.biff.HeaderFooter.Contents createContents() {
|
||||
return new Contents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates internal class of the appropriate type
|
||||
*
|
||||
* @param s the string to create the contents
|
||||
* @return the created contents
|
||||
*/
|
||||
protected jxl.biff.HeaderFooter.Contents createContents(String s) {
|
||||
return new Contents(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates internal class of the appropriate type
|
||||
*
|
||||
* @param c the contents to copy
|
||||
* @return the new contents
|
||||
*/
|
||||
protected jxl.biff.HeaderFooter.Contents
|
||||
createContents(jxl.biff.HeaderFooter.Contents c) {
|
||||
return new Contents((Contents) c);
|
||||
}
|
||||
|
||||
/**
|
||||
* The contents - a simple wrapper around a string buffer
|
||||
*/
|
||||
public static class Contents extends jxl.biff.HeaderFooter.Contents {
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
Contents() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used when reading worksheets. The string contains all
|
||||
* the formatting (but not alignment characters
|
||||
*
|
||||
* @param s the format string
|
||||
*/
|
||||
Contents(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @param copy the contents to copy
|
||||
*/
|
||||
Contents(Contents copy) {
|
||||
super(copy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the text to the string buffer
|
||||
*
|
||||
* @param txt the text to append
|
||||
*/
|
||||
public void append(String txt) {
|
||||
super.append(txt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns bold printing on or off. Bold printing
|
||||
* is initially off. Text subsequently appended to
|
||||
* this object will be bolded until this method is
|
||||
* called again.
|
||||
*/
|
||||
public void toggleBold() {
|
||||
super.toggleBold();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns underline printing on or off. Underline printing
|
||||
* is initially off. Text subsequently appended to
|
||||
* this object will be underlined until this method is
|
||||
* called again.
|
||||
*/
|
||||
public void toggleUnderline() {
|
||||
super.toggleUnderline();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns italics printing on or off. Italics printing
|
||||
* is initially off. Text subsequently appended to
|
||||
* this object will be italicized until this method is
|
||||
* called again.
|
||||
*/
|
||||
public void toggleItalics() {
|
||||
super.toggleItalics();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns strikethrough printing on or off. Strikethrough printing
|
||||
* is initially off. Text subsequently appended to
|
||||
* this object will be striked out until this method is
|
||||
* called again.
|
||||
*/
|
||||
public void toggleStrikethrough() {
|
||||
super.toggleStrikethrough();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns double-underline printing on or off. Double-underline printing
|
||||
* is initially off. Text subsequently appended to
|
||||
* this object will be double-underlined until this method is
|
||||
* called again.
|
||||
*/
|
||||
public void toggleDoubleUnderline() {
|
||||
super.toggleDoubleUnderline();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns superscript printing on or off. Superscript printing
|
||||
* is initially off. Text subsequently appended to
|
||||
* this object will be superscripted until this method is
|
||||
* called again.
|
||||
*/
|
||||
public void toggleSuperScript() {
|
||||
super.toggleSuperScript();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns subscript printing on or off. Subscript printing
|
||||
* is initially off. Text subsequently appended to
|
||||
* this object will be subscripted until this method is
|
||||
* called again.
|
||||
*/
|
||||
public void toggleSubScript() {
|
||||
super.toggleSubScript();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns outline printing on or off (Macintosh only).
|
||||
* Outline printing is initially off. Text subsequently appended
|
||||
* to this object will be outlined until this method is
|
||||
* called again.
|
||||
*/
|
||||
public void toggleOutline() {
|
||||
super.toggleOutline();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns shadow printing on or off (Macintosh only).
|
||||
* Shadow printing is initially off. Text subsequently appended
|
||||
* to this object will be shadowed until this method is
|
||||
* called again.
|
||||
*/
|
||||
public void toggleShadow() {
|
||||
super.toggleShadow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the font of text subsequently appended to this
|
||||
* object.. Previously appended text is not affected.
|
||||
* <p/>
|
||||
* <strong>Note:</strong> no checking is performed to
|
||||
* determine if fontName is a valid font.
|
||||
*
|
||||
* @param fontName name of the font to use
|
||||
*/
|
||||
public void setFontName(String fontName) {
|
||||
super.setFontName(fontName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the font size of text subsequently appended to this
|
||||
* object. Previously appended text is not affected.
|
||||
* <p/>
|
||||
* Valid point sizes are between 1 and 99 (inclusive). If
|
||||
* size is outside this range, this method returns false
|
||||
* and does not change font size. If size is within this
|
||||
* range, the font size is changed and true is returned.
|
||||
*
|
||||
* @param size The size in points. Valid point sizes are
|
||||
* between 1 and 99 (inclusive).
|
||||
* @return true if the font size was changed, false if font
|
||||
* size was not changed because 1 > size > 99.
|
||||
*/
|
||||
public boolean setFontSize(int size) {
|
||||
return super.setFontSize(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the page number
|
||||
*/
|
||||
public void appendPageNumber() {
|
||||
super.appendPageNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the total number of pages
|
||||
*/
|
||||
public void appendTotalPages() {
|
||||
super.appendTotalPages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the current date
|
||||
*/
|
||||
public void appendDate() {
|
||||
super.appendDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the current time
|
||||
*/
|
||||
public void appendTime() {
|
||||
super.appendTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the workbook name
|
||||
*/
|
||||
public void appendWorkbookName() {
|
||||
super.appendWorkbookName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the worksheet name
|
||||
*/
|
||||
public void appendWorkSheetName() {
|
||||
super.appendWorkSheetName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the contents of this portion
|
||||
*/
|
||||
public void clear() {
|
||||
super.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries if the contents are empty
|
||||
*
|
||||
* @return TRUE if the contents are empty, FALSE otherwise
|
||||
*/
|
||||
public boolean empty() {
|
||||
return super.empty();
|
||||
}
|
||||
}
|
||||
}
|
106
datastructures-xslx/src/main/java/jxl/Hyperlink.java
Executable file
106
datastructures-xslx/src/main/java/jxl/Hyperlink.java
Executable file
|
@ -0,0 +1,106 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Hyperlink information. Only URLs or file links are supported
|
||||
* <p>
|
||||
* Hyperlinks may apply to a range of cells; in such cases the methods
|
||||
* getRow and getColumn return the cell at the top left of the range
|
||||
* the hyperlink refers to. Hyperlinks have no specific cell format
|
||||
* information applied to them, so the getCellFormat method will return null
|
||||
*/
|
||||
public interface Hyperlink {
|
||||
/**
|
||||
* Returns the row number of this cell
|
||||
*
|
||||
* @return the row number of this cell
|
||||
*/
|
||||
int getRow();
|
||||
|
||||
/**
|
||||
* Returns the column number of this cell
|
||||
*
|
||||
* @return the column number of this cell
|
||||
*/
|
||||
int getColumn();
|
||||
|
||||
/**
|
||||
* Gets the range of cells which activate this hyperlink
|
||||
* The get sheet index methods will all return -1, because the
|
||||
* cells will all be present on the same sheet
|
||||
*
|
||||
* @return the range of cells which activate the hyperlink
|
||||
*/
|
||||
Range getRange();
|
||||
|
||||
/**
|
||||
* Determines whether this is a hyperlink to a file
|
||||
*
|
||||
* @return TRUE if this is a hyperlink to a file, FALSE otherwise
|
||||
*/
|
||||
boolean isFile();
|
||||
|
||||
/**
|
||||
* Determines whether this is a hyperlink to a web resource
|
||||
*
|
||||
* @return TRUE if this is a URL
|
||||
*/
|
||||
boolean isURL();
|
||||
|
||||
/**
|
||||
* Determines whether this is a hyperlink to a location in this workbook
|
||||
*
|
||||
* @return TRUE if this is a link to an internal location
|
||||
*/
|
||||
boolean isLocation();
|
||||
|
||||
/**
|
||||
* Returns the row number of the bottom right cell
|
||||
*
|
||||
* @return the row number of this cell
|
||||
*/
|
||||
int getLastRow();
|
||||
|
||||
/**
|
||||
* Returns the column number of the bottom right cell
|
||||
*
|
||||
* @return the column number of this cell
|
||||
*/
|
||||
int getLastColumn();
|
||||
|
||||
/**
|
||||
* Gets the URL referenced by this Hyperlink
|
||||
*
|
||||
* @return the URL, or NULL if this hyperlink is not a URL
|
||||
*/
|
||||
URL getURL();
|
||||
|
||||
/**
|
||||
* Returns the local file eferenced by this Hyperlink
|
||||
*
|
||||
* @return the file, or NULL if this hyperlink is not a file
|
||||
*/
|
||||
File getFile();
|
||||
}
|
||||
|
120
datastructures-xslx/src/main/java/jxl/Image.java
Executable file
120
datastructures-xslx/src/main/java/jxl/Image.java
Executable file
|
@ -0,0 +1,120 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2004 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import java.io.File;
|
||||
import jxl.common.LengthUnit;
|
||||
|
||||
/**
|
||||
* Accessor functions for an image
|
||||
*/
|
||||
public interface Image {
|
||||
/**
|
||||
* Accessor for the image position
|
||||
*
|
||||
* @return the column number at which the image is positioned
|
||||
*/
|
||||
double getColumn();
|
||||
|
||||
/**
|
||||
* Accessor for the image position
|
||||
*
|
||||
* @return the row number at which the image is positioned
|
||||
*/
|
||||
double getRow();
|
||||
|
||||
/**
|
||||
* Accessor for the image dimensions
|
||||
*
|
||||
* @return the number of columns this image spans
|
||||
*/
|
||||
double getWidth();
|
||||
|
||||
/**
|
||||
* Accessor for the image dimensions
|
||||
*
|
||||
* @return the number of rows which this image spans
|
||||
*/
|
||||
double getHeight();
|
||||
|
||||
/**
|
||||
* Accessor for the image file
|
||||
*
|
||||
* @return the file which the image references
|
||||
*/
|
||||
File getImageFile();
|
||||
|
||||
/**
|
||||
* Accessor for the image data
|
||||
*
|
||||
* @return the image data
|
||||
*/
|
||||
byte[] getImageData();
|
||||
|
||||
/**
|
||||
* Get the width of this image as rendered within Excel
|
||||
*
|
||||
* @param unit the unit of measurement
|
||||
* @return the width of the image within Excel
|
||||
*/
|
||||
double getWidth(LengthUnit unit);
|
||||
|
||||
/**
|
||||
* Get the height of this image as rendered within Excel
|
||||
*
|
||||
* @param unit the unit of measurement
|
||||
* @return the height of the image within Excel
|
||||
*/
|
||||
double getHeight(LengthUnit unit);
|
||||
|
||||
/**
|
||||
* Gets the width of the image. Note that this is the width of the
|
||||
* underlying image, and does not take into account any size manipulations
|
||||
* that may have occurred when the image was added into Excel
|
||||
*
|
||||
* @return the image width in pixels
|
||||
*/
|
||||
int getImageWidth();
|
||||
|
||||
/**
|
||||
* Gets the height of the image. Note that this is the height of the
|
||||
* underlying image, and does not take into account any size manipulations
|
||||
* that may have occurred when the image was added into Excel
|
||||
*
|
||||
* @return the image height in pixels
|
||||
*/
|
||||
int getImageHeight();
|
||||
|
||||
/**
|
||||
* Gets the horizontal resolution of the image, if that information
|
||||
* is available.
|
||||
*
|
||||
* @return the number of dots per unit specified, if available, 0 otherwise
|
||||
*/
|
||||
double getHorizontalResolution(LengthUnit unit);
|
||||
|
||||
/**
|
||||
* Gets the vertical resolution of the image, if that information
|
||||
* is available.
|
||||
*
|
||||
* @return the number of dots per unit specified, if available, 0 otherwise
|
||||
*/
|
||||
double getVerticalResolution(LengthUnit unit);
|
||||
}
|
34
datastructures-xslx/src/main/java/jxl/JXLException.java
Executable file
34
datastructures-xslx/src/main/java/jxl/JXLException.java
Executable file
|
@ -0,0 +1,34 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* Base exception class for JExcelAPI exceptions
|
||||
*/
|
||||
public class JXLException extends Exception {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param message the exception message
|
||||
*/
|
||||
protected JXLException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
33
datastructures-xslx/src/main/java/jxl/LabelCell.java
Executable file
33
datastructures-xslx/src/main/java/jxl/LabelCell.java
Executable file
|
@ -0,0 +1,33 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* A label cell
|
||||
*/
|
||||
public interface LabelCell extends Cell {
|
||||
/**
|
||||
* Gets the label for this cell. The value returned will be the same
|
||||
* as for the getContents method in the base class
|
||||
*
|
||||
* @return the cell contents
|
||||
*/
|
||||
String getString();
|
||||
}
|
43
datastructures-xslx/src/main/java/jxl/NumberCell.java
Executable file
43
datastructures-xslx/src/main/java/jxl/NumberCell.java
Executable file
|
@ -0,0 +1,43 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
/**
|
||||
* A cell which contains a numerical value
|
||||
*/
|
||||
public interface NumberCell extends Cell {
|
||||
/**
|
||||
* Gets the double contents for this cell.
|
||||
*
|
||||
* @return the cell contents
|
||||
*/
|
||||
double getValue();
|
||||
|
||||
/**
|
||||
* Gets the NumberFormat used to format this cell. This is the java
|
||||
* equivalent of the Excel format
|
||||
*
|
||||
* @return the NumberFormat used to format the cell
|
||||
*/
|
||||
NumberFormat getNumberFormat();
|
||||
}
|
||||
|
27
datastructures-xslx/src/main/java/jxl/NumberFormulaCell.java
Executable file
27
datastructures-xslx/src/main/java/jxl/NumberFormulaCell.java
Executable file
|
@ -0,0 +1,27 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* A mixin interface for numerical formulas, which combines the interfaces
|
||||
* for formulas and for numbers
|
||||
*/
|
||||
public interface NumberFormulaCell extends NumberCell, FormulaCell {
|
||||
}
|
57
datastructures-xslx/src/main/java/jxl/Range.java
Executable file
57
datastructures-xslx/src/main/java/jxl/Range.java
Executable file
|
@ -0,0 +1,57 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* Represents a 3-D range of cells in a workbook. This object is
|
||||
* returned by the method findByName in a workbook
|
||||
*/
|
||||
public interface Range {
|
||||
/**
|
||||
* Gets the cell at the top left of this range
|
||||
*
|
||||
* @return the cell at the top left
|
||||
*/
|
||||
Cell getTopLeft();
|
||||
|
||||
/**
|
||||
* Gets the cell at the bottom right of this range
|
||||
*
|
||||
* @return the cell at the bottom right
|
||||
*/
|
||||
Cell getBottomRight();
|
||||
|
||||
/**
|
||||
* Gets the index of the first sheet in the range
|
||||
*
|
||||
* @return the index of the first sheet in the range
|
||||
*/
|
||||
int getFirstSheetIndex();
|
||||
|
||||
/**
|
||||
* Gets the index of the last sheet in the range
|
||||
*
|
||||
* @return the index of the last sheet in the range
|
||||
*/
|
||||
int getLastSheetIndex();
|
||||
}
|
||||
|
||||
|
||||
|
278
datastructures-xslx/src/main/java/jxl/Sheet.java
Executable file
278
datastructures-xslx/src/main/java/jxl/Sheet.java
Executable file
|
@ -0,0 +1,278 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import jxl.format.CellFormat;
|
||||
|
||||
/**
|
||||
* Represents a sheet within a workbook. Provides a handle to the individual
|
||||
* cells, or lines of cells (grouped by Row or Column)
|
||||
*/
|
||||
public interface Sheet {
|
||||
/**
|
||||
* Returns the cell specified at this row and at this column.
|
||||
* If a column/row combination forms part of a merged group of cells
|
||||
* then (unless it is the first cell of the group) a blank cell
|
||||
* will be returned
|
||||
*
|
||||
* @param column the column number
|
||||
* @param row the row number
|
||||
* @return the cell at the specified co-ordinates
|
||||
*/
|
||||
Cell getCell(int column, int row);
|
||||
|
||||
/**
|
||||
* Returns the cell for the specified location eg. "A4". Note that this
|
||||
* method is identical to calling getCell(CellReferenceHelper.getColumn(loc),
|
||||
* CellReferenceHelper.getRow(loc)) and its implicit performance
|
||||
* overhead for string parsing. As such,this method should therefore
|
||||
* be used sparingly
|
||||
*
|
||||
* @param loc the cell reference
|
||||
* @return the cell at the specified co-ordinates
|
||||
*/
|
||||
Cell getCell(String loc);
|
||||
|
||||
/**
|
||||
* Returns the number of rows in this sheet
|
||||
*
|
||||
* @return the number of rows in this sheet
|
||||
*/
|
||||
int getRows();
|
||||
|
||||
/**
|
||||
* Returns the number of columns in this sheet
|
||||
*
|
||||
* @return the number of columns in this sheet
|
||||
*/
|
||||
int getColumns();
|
||||
|
||||
/**
|
||||
* Gets all the cells on the specified row
|
||||
*
|
||||
* @param row the rows whose cells are to be returned
|
||||
* @return the cells on the given row
|
||||
*/
|
||||
Cell[] getRow(int row);
|
||||
|
||||
/**
|
||||
* Gets all the cells on the specified column
|
||||
*
|
||||
* @param col the column whose cells are to be returned
|
||||
* @return the cells on the specified column
|
||||
*/
|
||||
Cell[] getColumn(int col);
|
||||
|
||||
/**
|
||||
* Gets the name of this sheet
|
||||
*
|
||||
* @return the name of the sheet
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Determines whether the sheet is hidden
|
||||
*
|
||||
* @return whether or not the sheet is hidden
|
||||
* @deprecated in favour of the getSettings() method
|
||||
*/
|
||||
boolean isHidden();
|
||||
|
||||
/**
|
||||
* Determines whether the sheet is protected
|
||||
*
|
||||
* @return whether or not the sheet is protected
|
||||
* @deprecated in favour of the getSettings() method
|
||||
*/
|
||||
boolean isProtected();
|
||||
|
||||
/**
|
||||
* Gets the cell whose contents match the string passed in.
|
||||
* If no match is found, then null is returned. The search is performed
|
||||
* on a row by row basis, so the lower the row number, the more
|
||||
* efficiently the algorithm will perform
|
||||
*
|
||||
* @param contents the string to match
|
||||
* @return the Cell whose contents match the paramter, null if not found
|
||||
*/
|
||||
Cell findCell(String contents);
|
||||
|
||||
/**
|
||||
* Gets the cell whose contents match the string passed in.
|
||||
* If no match is found, then null is returned. The search is performed
|
||||
* on a row by row basis, so the lower the row number, the more
|
||||
* efficiently the algorithm will perform
|
||||
*
|
||||
* @param contents the string to match
|
||||
* @param firstCol the first column within the range
|
||||
* @param firstRow the first row of the range
|
||||
* @param lastCol the last column within the range
|
||||
* @param lastRow the last row within the range
|
||||
* @param reverse indicates whether to perform a reverse search or not
|
||||
* @return the Cell whose contents match the parameter, null if not found
|
||||
*/
|
||||
Cell findCell(String contents,
|
||||
int firstCol,
|
||||
int firstRow,
|
||||
int lastCol,
|
||||
int lastRow,
|
||||
boolean reverse);
|
||||
|
||||
/**
|
||||
* Gets the cell whose contents match the regular expressionstring passed in.
|
||||
* If no match is found, then null is returned. The search is performed
|
||||
* on a row by row basis, so the lower the row number, the more
|
||||
* efficiently the algorithm will perform
|
||||
*
|
||||
* @param pattern the regular expression string to match
|
||||
* @param firstCol the first column within the range
|
||||
* @param firstRow the first row of the rang
|
||||
* @param lastCol the last column within the range
|
||||
* @param lastRow the last row within the range
|
||||
* @param reverse indicates whether to perform a reverse search or not
|
||||
* @return the Cell whose contents match the parameter, null if not found
|
||||
*/
|
||||
Cell findCell(Pattern pattern,
|
||||
int firstCol,
|
||||
int firstRow,
|
||||
int lastCol,
|
||||
int lastRow,
|
||||
boolean reverse);
|
||||
|
||||
/**
|
||||
* Gets the cell whose contents match the string passed in.
|
||||
* If no match is found, then null is returned. The search is performed
|
||||
* on a row by row basis, so the lower the row number, the more
|
||||
* efficiently the algorithm will perform. This method differs
|
||||
* from the findCell method in that only cells with labels are
|
||||
* queried - all numerical cells are ignored. This should therefore
|
||||
* improve performance.
|
||||
*
|
||||
* @param contents the string to match
|
||||
* @return the Cell whose contents match the paramter, null if not found
|
||||
*/
|
||||
LabelCell findLabelCell(String contents);
|
||||
|
||||
/**
|
||||
* Gets the hyperlinks on this sheet
|
||||
*
|
||||
* @return an array of hyperlinks
|
||||
*/
|
||||
Hyperlink[] getHyperlinks();
|
||||
|
||||
/**
|
||||
* Gets the cells which have been merged on this sheet
|
||||
*
|
||||
* @return an array of range objects
|
||||
*/
|
||||
Range[] getMergedCells();
|
||||
|
||||
/**
|
||||
* Gets the settings used on a particular sheet
|
||||
*
|
||||
* @return the sheet settings
|
||||
*/
|
||||
SheetSettings getSettings();
|
||||
|
||||
/**
|
||||
* Gets the column format for the specified column
|
||||
*
|
||||
* @param col the column number
|
||||
* @return the column format, or NULL if the column has no specific format
|
||||
* @deprecated Use getColumnView and the CellView bean instead
|
||||
*/
|
||||
CellFormat getColumnFormat(int col);
|
||||
|
||||
/**
|
||||
* Gets the column width for the specified column
|
||||
*
|
||||
* @param col the column number
|
||||
* @return the column width, or the default width if the column has no
|
||||
* specified format
|
||||
* @deprecated Use getColumnView instead
|
||||
*/
|
||||
int getColumnWidth(int col);
|
||||
|
||||
/**
|
||||
* Gets the column width for the specified column
|
||||
*
|
||||
* @param col the column number
|
||||
* @return the column format, or the default format if no override is
|
||||
* specified
|
||||
*/
|
||||
CellView getColumnView(int col);
|
||||
|
||||
/**
|
||||
* Gets the row height for the specified column
|
||||
*
|
||||
* @param row the row number
|
||||
* @return the row height, or the default height if the column has no
|
||||
* specified format
|
||||
* @deprecated use getRowView instead
|
||||
*/
|
||||
int getRowHeight(int row);
|
||||
|
||||
/**
|
||||
* Gets the row height for the specified column
|
||||
*
|
||||
* @param row the row number
|
||||
* @return the row format, which may be the default format if no format
|
||||
* is specified
|
||||
*/
|
||||
CellView getRowView(int row);
|
||||
|
||||
/**
|
||||
* Accessor for the number of images on the sheet
|
||||
*
|
||||
* @return the number of images on this sheet
|
||||
*/
|
||||
int getNumberOfImages();
|
||||
|
||||
/**
|
||||
* Accessor for the image
|
||||
*
|
||||
* @param i the 0 based image number
|
||||
* @return the image at the specified position
|
||||
*/
|
||||
Image getDrawing(int i);
|
||||
|
||||
/**
|
||||
* Accessor for the page breaks on this sheet
|
||||
*
|
||||
* @return the page breaks on this sheet
|
||||
*/
|
||||
int[] getRowPageBreaks();
|
||||
|
||||
/**
|
||||
* Accessor for the page breaks on this sheet
|
||||
*
|
||||
* @return the page breaks on this sheet
|
||||
*/
|
||||
int[] getColumnPageBreaks();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
1204
datastructures-xslx/src/main/java/jxl/SheetSettings.java
Executable file
1204
datastructures-xslx/src/main/java/jxl/SheetSettings.java
Executable file
File diff suppressed because it is too large
Load diff
29
datastructures-xslx/src/main/java/jxl/StringFormulaCell.java
Executable file
29
datastructures-xslx/src/main/java/jxl/StringFormulaCell.java
Executable file
|
@ -0,0 +1,29 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
/**
|
||||
* A mixin interface for numerical formulas, which combines the interfaces
|
||||
* for formulas and for strings
|
||||
*/
|
||||
public interface StringFormulaCell extends LabelCell, FormulaCell {
|
||||
}
|
||||
|
||||
|
397
datastructures-xslx/src/main/java/jxl/Workbook.java
Executable file
397
datastructures-xslx/src/main/java/jxl/Workbook.java
Executable file
|
@ -0,0 +1,397 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import jxl.read.biff.BiffException;
|
||||
import jxl.read.biff.File;
|
||||
import jxl.read.biff.PasswordException;
|
||||
import jxl.read.biff.WorkbookParser;
|
||||
import jxl.write.WritableWorkbook;
|
||||
import jxl.write.biff.WritableWorkbookImpl;
|
||||
|
||||
/**
|
||||
* Represents a Workbook. Contains the various factory methods and provides
|
||||
* a variety of accessors which provide access to the work sheets.
|
||||
*/
|
||||
public abstract class Workbook {
|
||||
/**
|
||||
* The current version of the software
|
||||
*/
|
||||
private static final String VERSION = "2.6.12";
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
protected Workbook() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the software version
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
public static String getVersion() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory method which takes in an excel file and reads in the contents.
|
||||
*
|
||||
* @param file the excel 97 spreadsheet to parse
|
||||
* @return a workbook instance
|
||||
* @throws IOException
|
||||
* @throws BiffException
|
||||
*/
|
||||
public static Workbook getWorkbook(java.io.File file)
|
||||
throws IOException, BiffException {
|
||||
return getWorkbook(file, new WorkbookSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory method which takes in an excel file and reads in the contents.
|
||||
*
|
||||
* @param file the excel 97 spreadsheet to parse
|
||||
* @param ws the settings for the workbook
|
||||
* @return a workbook instance
|
||||
* @throws IOException
|
||||
* @throws BiffException
|
||||
*/
|
||||
public static Workbook getWorkbook(java.io.File file, WorkbookSettings ws)
|
||||
throws IOException, BiffException {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
|
||||
// Always close down the input stream, regardless of whether or not the
|
||||
// file can be parsed. Thanks to Steve Hahn for this
|
||||
File dataFile = null;
|
||||
|
||||
try {
|
||||
dataFile = new File(fis, ws);
|
||||
} catch (IOException e) {
|
||||
fis.close();
|
||||
throw e;
|
||||
} catch (BiffException e) {
|
||||
fis.close();
|
||||
throw e;
|
||||
}
|
||||
|
||||
fis.close();
|
||||
|
||||
Workbook workbook = new WorkbookParser(dataFile, ws);
|
||||
workbook.parse();
|
||||
|
||||
return workbook;
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory method which takes in an excel file and reads in the contents.
|
||||
*
|
||||
* @param is an open stream which is the the excel 97 spreadsheet to parse
|
||||
* @return a workbook instance
|
||||
* @throws IOException
|
||||
* @throws BiffException
|
||||
*/
|
||||
public static Workbook getWorkbook(InputStream is)
|
||||
throws IOException, BiffException {
|
||||
return getWorkbook(is, new WorkbookSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory method which takes in an excel file and reads in the contents.
|
||||
*
|
||||
* @param is an open stream which is the the excel 97 spreadsheet to parse
|
||||
* @param ws the settings for the workbook
|
||||
* @return a workbook instance
|
||||
* @throws IOException
|
||||
* @throws BiffException
|
||||
*/
|
||||
public static Workbook getWorkbook(InputStream is, WorkbookSettings ws)
|
||||
throws IOException, BiffException {
|
||||
File dataFile = new File(is, ws);
|
||||
|
||||
Workbook workbook = new WorkbookParser(dataFile, ws);
|
||||
workbook.parse();
|
||||
|
||||
return workbook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a writable workbook with the given file name
|
||||
*
|
||||
* @param file the workbook to copy
|
||||
* @return a writable workbook
|
||||
* @throws IOException
|
||||
*/
|
||||
public static WritableWorkbook createWorkbook(java.io.File file)
|
||||
throws IOException {
|
||||
return createWorkbook(file, new WorkbookSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a writable workbook with the given file name
|
||||
*
|
||||
* @param file the file to copy from
|
||||
* @param ws the global workbook settings
|
||||
* @return a writable workbook
|
||||
* @throws IOException
|
||||
*/
|
||||
public static WritableWorkbook createWorkbook(java.io.File file,
|
||||
WorkbookSettings ws)
|
||||
throws IOException {
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
WritableWorkbook w = new WritableWorkbookImpl(fos, true, ws);
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a writable workbook with the given filename as a copy of
|
||||
* the workbook passed in. Once created, the contents of the writable
|
||||
* workbook may be modified
|
||||
*
|
||||
* @param file the output file for the copy
|
||||
* @param in the workbook to copy
|
||||
* @return a writable workbook
|
||||
* @throws IOException
|
||||
*/
|
||||
public static WritableWorkbook createWorkbook(java.io.File file,
|
||||
Workbook in)
|
||||
throws IOException {
|
||||
return createWorkbook(file, in, new WorkbookSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a writable workbook with the given filename as a copy of
|
||||
* the workbook passed in. Once created, the contents of the writable
|
||||
* workbook may be modified
|
||||
*
|
||||
* @param file the output file for the copy
|
||||
* @param in the workbook to copy
|
||||
* @param ws the configuration for this workbook
|
||||
* @return a writable workbook
|
||||
*/
|
||||
public static WritableWorkbook createWorkbook(java.io.File file,
|
||||
Workbook in,
|
||||
WorkbookSettings ws)
|
||||
throws IOException {
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
WritableWorkbook w = new WritableWorkbookImpl(fos, in, true, ws);
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a writable workbook as a copy of
|
||||
* the workbook passed in. Once created, the contents of the writable
|
||||
* workbook may be modified
|
||||
*
|
||||
* @param os the stream to write to
|
||||
* @param in the workbook to copy
|
||||
* @return a writable workbook
|
||||
* @throws IOException
|
||||
*/
|
||||
public static WritableWorkbook createWorkbook(OutputStream os,
|
||||
Workbook in)
|
||||
throws IOException {
|
||||
return createWorkbook(os, in, ((WorkbookParser) in).getSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a writable workbook as a copy of
|
||||
* the workbook passed in. Once created, the contents of the writable
|
||||
* workbook may be modified
|
||||
*
|
||||
* @param os the output stream to write to
|
||||
* @param in the workbook to copy
|
||||
* @param ws the configuration for this workbook
|
||||
* @return a writable workbook
|
||||
* @throws IOException
|
||||
*/
|
||||
public static WritableWorkbook createWorkbook(OutputStream os,
|
||||
Workbook in,
|
||||
WorkbookSettings ws)
|
||||
throws IOException {
|
||||
WritableWorkbook w = new WritableWorkbookImpl(os, in, false, ws);
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a writable workbook. When the workbook is closed,
|
||||
* it will be streamed directly to the output stream. In this
|
||||
* manner, a generated excel spreadsheet can be passed from
|
||||
* a servlet to the browser over HTTP
|
||||
*
|
||||
* @param os the output stream
|
||||
* @return the writable workbook
|
||||
* @throws IOException
|
||||
*/
|
||||
public static WritableWorkbook createWorkbook(OutputStream os)
|
||||
throws IOException {
|
||||
return createWorkbook(os, new WorkbookSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a writable workbook. When the workbook is closed,
|
||||
* it will be streamed directly to the output stream. In this
|
||||
* manner, a generated excel spreadsheet can be passed from
|
||||
* a servlet to the browser over HTTP
|
||||
*
|
||||
* @param os the output stream
|
||||
* @param ws the configuration for this workbook
|
||||
* @return the writable workbook
|
||||
* @throws IOException
|
||||
*/
|
||||
public static WritableWorkbook createWorkbook(OutputStream os,
|
||||
WorkbookSettings ws)
|
||||
throws IOException {
|
||||
WritableWorkbook w = new WritableWorkbookImpl(os, false, ws);
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sheets within this workbook. Use of this method for
|
||||
* large worksheets can cause performance problems.
|
||||
*
|
||||
* @return an array of the individual sheets
|
||||
*/
|
||||
public abstract Sheet[] getSheets();
|
||||
|
||||
/**
|
||||
* Gets the sheet names
|
||||
*
|
||||
* @return an array of strings containing the sheet names
|
||||
*/
|
||||
public abstract String[] getSheetNames();
|
||||
|
||||
/**
|
||||
* Gets the specified sheet within this workbook
|
||||
* As described in the accompanying technical notes, each call
|
||||
* to getSheet forces a reread of the sheet (for memory reasons).
|
||||
* Therefore, do not make unnecessary calls to this method. Furthermore,
|
||||
* do not hold unnecessary references to Sheets in client code, as
|
||||
* this will prevent the garbage collector from freeing the memory
|
||||
*
|
||||
* @param index the zero based index of the reQuired sheet
|
||||
* @return The sheet specified by the index
|
||||
* @throws IndexOutOfBoundException when index refers to a non-existent
|
||||
* sheet
|
||||
*/
|
||||
public abstract Sheet getSheet(int index)
|
||||
throws IndexOutOfBoundsException;
|
||||
|
||||
/**
|
||||
* Gets the sheet with the specified name from within this workbook.
|
||||
* As described in the accompanying technical notes, each call
|
||||
* to getSheet forces a reread of the sheet (for memory reasons).
|
||||
* Therefore, do not make unnecessary calls to this method. Furthermore,
|
||||
* do not hold unnecessary references to Sheets in client code, as
|
||||
* this will prevent the garbage collector from freeing the memory
|
||||
*
|
||||
* @param name the sheet name
|
||||
* @return The sheet with the specified name, or null if it is not found
|
||||
*/
|
||||
public abstract Sheet getSheet(String name);
|
||||
|
||||
/**
|
||||
* Returns the number of sheets in this workbook
|
||||
*
|
||||
* @return the number of sheets in this workbook
|
||||
*/
|
||||
public abstract int getNumberOfSheets();
|
||||
|
||||
/**
|
||||
* Gets the named cell from this workbook. If the name refers to a
|
||||
* range of cells, then the cell on the top left is returned. If
|
||||
* the name cannot be found, null is returned.
|
||||
* This is a convenience function to quickly access the contents
|
||||
* of a single cell. If you need further information (such as the
|
||||
* sheet or adjacent cells in the range) use the functionally
|
||||
* richer method, findByName which returns a list of ranges
|
||||
*
|
||||
* @param name the name of the cell/range to search for
|
||||
* @return the cell in the top left of the range if found, NULL
|
||||
* otherwise
|
||||
*/
|
||||
public abstract Cell findCellByName(String name);
|
||||
|
||||
/**
|
||||
* Returns the cell for the specified location eg. "Sheet1!A4".
|
||||
* This is identical to using the CellReferenceHelper with its
|
||||
* associated performance overheads, consequently it should
|
||||
* be use sparingly
|
||||
*
|
||||
* @param loc the cell to retrieve
|
||||
* @return the cell at the specified location
|
||||
*/
|
||||
public abstract Cell getCell(String loc);
|
||||
|
||||
/**
|
||||
* Gets the named range from this workbook. The Range object returns
|
||||
* contains all the cells from the top left to the bottom right
|
||||
* of the range.
|
||||
* If the named range comprises an adjacent range,
|
||||
* the Range[] will contain one object; for non-adjacent
|
||||
* ranges, it is necessary to return an array of length greater than
|
||||
* one.
|
||||
* If the named range contains a single cell, the top left and
|
||||
* bottom right cell will be the same cell
|
||||
*
|
||||
* @param name the name of the cell/range to search for
|
||||
* @return the range of cells, or NULL if the range does not exist
|
||||
*/
|
||||
public abstract Range[] findByName(String name);
|
||||
|
||||
/**
|
||||
* Gets the named ranges
|
||||
*
|
||||
* @return the list of named cells within the workbook
|
||||
*/
|
||||
public abstract String[] getRangeNames();
|
||||
|
||||
/**
|
||||
* Determines whether the sheet is protected
|
||||
*
|
||||
* @return TRUE if the workbook is protected, FALSE otherwise
|
||||
*/
|
||||
public abstract boolean isProtected();
|
||||
|
||||
/**
|
||||
* Parses the excel file.
|
||||
* If the workbook is password protected a PasswordException is thrown
|
||||
* in case consumers of the API wish to handle this in a particular way
|
||||
*
|
||||
* @throws BiffException
|
||||
* @throws PasswordException
|
||||
*/
|
||||
protected abstract void parse() throws BiffException, PasswordException;
|
||||
|
||||
/**
|
||||
* Closes this workbook, and frees makes any memory allocated available
|
||||
* for garbage collection
|
||||
*/
|
||||
public abstract void close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
798
datastructures-xslx/src/main/java/jxl/WorkbookSettings.java
Executable file
798
datastructures-xslx/src/main/java/jxl/WorkbookSettings.java
Executable file
|
@ -0,0 +1,798 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import jxl.biff.CountryCode;
|
||||
import jxl.biff.formula.FunctionNames;
|
||||
import jxl.common.Logger;
|
||||
|
||||
/**
|
||||
* This is a bean which client applications may use to set various advanced
|
||||
* workbook properties. Use of this bean is not mandatory, and its absence
|
||||
* will merely result in workbooks being read/written using the default
|
||||
* settings
|
||||
*/
|
||||
public final class WorkbookSettings {
|
||||
/**
|
||||
* The HIDEOBJ record stores options selected in the Options dialog,View tab.
|
||||
*/
|
||||
public final static int HIDEOBJ_HIDE_ALL = 2;
|
||||
/**
|
||||
* The HIDEOBJ record stores options selected in the Options dialog,View tab.
|
||||
*/
|
||||
public final static int HIDEOBJ_SHOW_PLACEHOLDERS = 1;
|
||||
/**
|
||||
* The HIDEOBJ record stores options selected in the Options dialog,View tab.
|
||||
*/
|
||||
public final static int HIDEOBJ_SHOW_ALL = 0;
|
||||
// **
|
||||
// The default values
|
||||
// **
|
||||
private static final int DEFAULT_INITIAL_FILE_SIZE = 5 * 1024 * 1024;
|
||||
// 5 megabytes
|
||||
private static final int DEFAULT_ARRAY_GROW_SIZE = 1024 * 1024; // 1 megabyte
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(WorkbookSettings.class);
|
||||
/**
|
||||
* The amount of memory allocated to store the workbook data when
|
||||
* reading a worksheet. For processeses reading many small workbooks inside
|
||||
* a WAS it might be necessary to reduce the default size
|
||||
*/
|
||||
private int initialFileSize;
|
||||
/**
|
||||
* The amount of memory allocated to the array containing the workbook
|
||||
* data when its current amount is exhausted.
|
||||
*/
|
||||
private int arrayGrowSize;
|
||||
/**
|
||||
* Flag to indicate whether the drawing feature is enabled or not
|
||||
* Drawings deactivated using -Djxl.nodrawings=true on the JVM command line
|
||||
* Activated by default or by using -Djxl.nodrawings=false on the JVM command
|
||||
* line
|
||||
*/
|
||||
private boolean drawingsDisabled;
|
||||
/**
|
||||
* Flag to indicate whether the name feature is enabled or not
|
||||
* Names deactivated using -Djxl.nonames=true on the JVM command line
|
||||
* Activated by default or by using -Djxl.nonames=false on the JVM command
|
||||
* line
|
||||
*/
|
||||
private boolean namesDisabled;
|
||||
/**
|
||||
* Flag to indicate whether formula cell references should be adjusted
|
||||
* following row/column insertion/deletion
|
||||
*/
|
||||
private boolean formulaReferenceAdjustDisabled;
|
||||
/**
|
||||
* Flag to indicate whether the system hint garbage collection
|
||||
* is enabled or not.
|
||||
* As a rule of thumb, it is desirable to enable garbage collection
|
||||
* when reading large spreadsheets from a batch process or from the
|
||||
* command line, but better to deactivate the feature when reading
|
||||
* large spreadsheets within a WAS, as the calls to System.gc() not
|
||||
* only garbage collect the junk in JExcelApi, but also in the
|
||||
* webservers JVM and can cause significant slowdown
|
||||
* GC deactivated using -Djxl.nogc=true on the JVM command line
|
||||
* Activated by default or by using -Djxl.nogc=false on the JVM command line
|
||||
*/
|
||||
private boolean gcDisabled;
|
||||
/**
|
||||
* Flag to indicate whether the rationalization of cell formats is
|
||||
* disabled or not.
|
||||
* Rationalization is enabled by default, but may be disabled for
|
||||
* performance reasons. It can be deactivated using -Djxl.norat=true on
|
||||
* the JVM command line
|
||||
*/
|
||||
private boolean rationalizationDisabled;
|
||||
/**
|
||||
* Flag to indicate whether or not the merged cell checking has been
|
||||
* disabled
|
||||
*/
|
||||
private boolean mergedCellCheckingDisabled;
|
||||
/**
|
||||
* Flag to indicate whether the copying of additional property sets
|
||||
* are disabled
|
||||
*/
|
||||
private boolean propertySetsDisabled;
|
||||
/**
|
||||
* Flag to indicate that cell validation criteria are ignored
|
||||
*/
|
||||
private boolean cellValidationDisabled;
|
||||
/**
|
||||
* Flag to indicate whether or not to ignore blank cells when processing
|
||||
* sheets. Cells which are identified as blank can still have associated
|
||||
* cell formats which the processing program may still need to read
|
||||
*/
|
||||
private boolean ignoreBlankCells;
|
||||
/**
|
||||
* Flag to indicate whether auto filtering should be read/copied
|
||||
*/
|
||||
private boolean autoFilterDisabled;
|
||||
/**
|
||||
* Flag to indicate whether a temporary file should be used when
|
||||
* writing out the workbook
|
||||
*/
|
||||
private boolean useTemporaryFileDuringWrite;
|
||||
/**
|
||||
* The directory for used for the temporary file during write. If this
|
||||
* is NULL, the default system directory is used
|
||||
*/
|
||||
private File temporaryFileDuringWriteDirectory;
|
||||
/**
|
||||
* The locale. Normally this is the same as the system locale, but there
|
||||
* may be cases (eg. where you are uploading many spreadsheets from foreign
|
||||
* sources) where you may want to specify the locale on an individual
|
||||
* worksheet basis
|
||||
* The locale may also be specified on the command line using the lang and
|
||||
* country System properties eg. -Djxl.lang=en -Djxl.country=UK for UK
|
||||
* English
|
||||
*/
|
||||
private Locale locale;
|
||||
/**
|
||||
* The locale specific function names for this workbook
|
||||
*/
|
||||
private FunctionNames functionNames;
|
||||
/**
|
||||
* The character encoding used for reading non-unicode strings. This can
|
||||
* be different from the default platform encoding if processing spreadsheets
|
||||
* from abroad. This may also be set using the system property jxl.encoding
|
||||
*/
|
||||
private String encoding;
|
||||
/**
|
||||
* The character set used by the readable spreadsheeet
|
||||
*/
|
||||
private int characterSet;
|
||||
/**
|
||||
* The display language used by Excel (ISO 3166 mnemonic)
|
||||
*/
|
||||
private String excelDisplayLanguage;
|
||||
/**
|
||||
* The regional settings used by Excel (ISO 3166 mnemonic)
|
||||
*/
|
||||
private String excelRegionalSettings;
|
||||
/**
|
||||
* A hash map of function names keyed on locale
|
||||
*/
|
||||
private final HashMap localeFunctionNames;
|
||||
/**
|
||||
* Flag to indicate whether all external data and pivot stuff should
|
||||
* refreshed
|
||||
*/
|
||||
private boolean refreshAll;
|
||||
/**
|
||||
* Flag to indicate whether the file is a template or not (Usually with .xlt
|
||||
* file name extension)
|
||||
*/
|
||||
private boolean template;
|
||||
/**
|
||||
* Flag to indicate whether the file has been written by excel 2000.
|
||||
* <p>
|
||||
* The EXCEL9FILE record indicates the file was written by Excel 2000. It has
|
||||
* no record data field and is C0010000h. Any application other than Excel
|
||||
* 2000 that edits the file should not write out this record.
|
||||
* <p>
|
||||
* However, it seemas that excel 2003 + 2007 still set this flag....
|
||||
*/
|
||||
private boolean excel9file = false;
|
||||
/**
|
||||
* The WINDOWPROTECT record stores an option from the Protect Workbook
|
||||
* dialog box.
|
||||
* <p>
|
||||
* =1 if the workbook windows are protected
|
||||
*/
|
||||
private boolean windowProtected;
|
||||
/**
|
||||
* Write access user name.
|
||||
* When not set (null) then we set it to Java Excel API + Version number
|
||||
*/
|
||||
private String writeAccess;
|
||||
/**
|
||||
* The HIDEOBJ record stores options selected in the Options dialog,View tab.
|
||||
*/
|
||||
private int hideobj;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public WorkbookSettings() {
|
||||
initialFileSize = DEFAULT_INITIAL_FILE_SIZE;
|
||||
arrayGrowSize = DEFAULT_ARRAY_GROW_SIZE;
|
||||
localeFunctionNames = new HashMap();
|
||||
excelDisplayLanguage = CountryCode.USA.getCode();
|
||||
excelRegionalSettings = CountryCode.UK.getCode();
|
||||
refreshAll = false;
|
||||
template = false;
|
||||
excel9file = false;
|
||||
windowProtected = false;
|
||||
hideobj = HIDEOBJ_SHOW_ALL;
|
||||
|
||||
// Initialize other properties from the system properties
|
||||
try {
|
||||
boolean suppressWarnings = Boolean.getBoolean("jxl.nowarnings");
|
||||
setSuppressWarnings(suppressWarnings);
|
||||
drawingsDisabled = Boolean.getBoolean("jxl.nodrawings");
|
||||
namesDisabled = Boolean.getBoolean("jxl.nonames");
|
||||
gcDisabled = Boolean.getBoolean("jxl.nogc");
|
||||
rationalizationDisabled = Boolean.getBoolean("jxl.norat");
|
||||
mergedCellCheckingDisabled =
|
||||
Boolean.getBoolean("jxl.nomergedcellchecks");
|
||||
formulaReferenceAdjustDisabled =
|
||||
Boolean.getBoolean("jxl.noformulaadjust");
|
||||
propertySetsDisabled = Boolean.getBoolean("jxl.nopropertysets");
|
||||
ignoreBlankCells = Boolean.getBoolean("jxl.ignoreblanks");
|
||||
cellValidationDisabled = Boolean.getBoolean("jxl.nocellvalidation");
|
||||
autoFilterDisabled = !Boolean.getBoolean("jxl.autofilter");
|
||||
// autofilter currently disabled by default
|
||||
useTemporaryFileDuringWrite =
|
||||
Boolean.getBoolean("jxl.usetemporaryfileduringwrite");
|
||||
String tempdir =
|
||||
System.getProperty("jxl.temporaryfileduringwritedirectory");
|
||||
|
||||
if (tempdir != null) {
|
||||
temporaryFileDuringWriteDirectory = new File(tempdir);
|
||||
}
|
||||
|
||||
encoding = System.getProperty("file.encoding");
|
||||
} catch (SecurityException e) {
|
||||
logger.warn("Error accessing system properties.", e);
|
||||
}
|
||||
|
||||
// Initialize the locale to the system locale
|
||||
try {
|
||||
if (System.getProperty("jxl.lang") == null ||
|
||||
System.getProperty("jxl.country") == null) {
|
||||
locale = Locale.getDefault();
|
||||
} else {
|
||||
locale = new Locale(System.getProperty("jxl.lang"),
|
||||
System.getProperty("jxl.country"));
|
||||
}
|
||||
|
||||
if (System.getProperty("jxl.encoding") != null) {
|
||||
encoding = System.getProperty("jxl.encoding");
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
logger.warn("Error accessing system properties.", e);
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the array grow size property
|
||||
*
|
||||
* @return the array grow size
|
||||
*/
|
||||
public int getArrayGrowSize() {
|
||||
return arrayGrowSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the amount of memory by which to increase the amount of
|
||||
* memory allocated to storing the workbook data.
|
||||
* For processeses reading many small workbooks
|
||||
* inside a WAS it might be necessary to reduce the default size
|
||||
* Default value is 1 megabyte
|
||||
*
|
||||
* @param sz the file size in bytes
|
||||
*/
|
||||
public void setArrayGrowSize(int sz) {
|
||||
arrayGrowSize = sz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the initial file size property
|
||||
*
|
||||
* @return the initial file size
|
||||
*/
|
||||
public int getInitialFileSize() {
|
||||
return initialFileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initial amount of memory allocated to store the workbook data
|
||||
* when reading a worksheet. For processeses reading many small workbooks
|
||||
* inside a WAS it might be necessary to reduce the default size
|
||||
* Default value is 5 megabytes
|
||||
*
|
||||
* @param sz the file size in bytes
|
||||
*/
|
||||
public void setInitialFileSize(int sz) {
|
||||
initialFileSize = sz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the drawings disabled flag
|
||||
*
|
||||
* @return TRUE if drawings are disabled, FALSE otherwise
|
||||
*/
|
||||
public boolean getDrawingsDisabled() {
|
||||
return drawingsDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the handling of drawings
|
||||
*
|
||||
* @param b TRUE to disable the names feature, FALSE otherwise
|
||||
*/
|
||||
public void setDrawingsDisabled(boolean b) {
|
||||
drawingsDisabled = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the disabling of garbage collection
|
||||
*
|
||||
* @return FALSE if JExcelApi hints for garbage collection, TRUE otherwise
|
||||
*/
|
||||
public boolean getGCDisabled() {
|
||||
return gcDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the garbage collection disabled
|
||||
*
|
||||
* @param disabled TRUE to disable garbage collection, FALSE to enable it
|
||||
*/
|
||||
public void setGCDisabled(boolean disabled) {
|
||||
gcDisabled = disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the disabling of interpretation of named ranges
|
||||
*
|
||||
* @return FALSE if named cells are interpreted, TRUE otherwise
|
||||
*/
|
||||
public boolean getNamesDisabled() {
|
||||
return namesDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the handling of names
|
||||
*
|
||||
* @param b TRUE to disable the names feature, FALSE otherwise
|
||||
*/
|
||||
public void setNamesDisabled(boolean b) {
|
||||
namesDisabled = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not to rationalize the cell formats before
|
||||
* writing out the sheet. The default value is true
|
||||
*
|
||||
* @param r the rationalization flag
|
||||
*/
|
||||
public void setRationalization(boolean r) {
|
||||
rationalizationDisabled = !r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to retrieve the rationalization flag
|
||||
*
|
||||
* @return TRUE if rationalization is off, FALSE if rationalization is on
|
||||
*/
|
||||
public boolean getRationalizationDisabled() {
|
||||
return rationalizationDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to retrieve the merged cell checking flag
|
||||
*
|
||||
* @return TRUE if merged cell checking is off, FALSE if it is on
|
||||
*/
|
||||
public boolean getMergedCellCheckingDisabled() {
|
||||
return mergedCellCheckingDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to set the merged cell checking
|
||||
*
|
||||
* @param b - TRUE to enable merged cell checking, FALSE otherwise
|
||||
*/
|
||||
public void setMergedCellChecking(boolean b) {
|
||||
mergedCellCheckingDisabled = !b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not to enable any property sets (such as macros)
|
||||
* to be copied along with the workbook
|
||||
* Leaving this feature enabled will result in the JXL process using
|
||||
* more memory
|
||||
*
|
||||
* @param r the property sets flag
|
||||
*/
|
||||
public void setPropertySets(boolean r) {
|
||||
propertySetsDisabled = !r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to retrieve the property sets disabled flag
|
||||
*
|
||||
* @return TRUE if property sets are disabled, FALSE otherwise
|
||||
*/
|
||||
public boolean getPropertySetsDisabled() {
|
||||
return propertySetsDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to set the suppress warnings flag. Due to the change
|
||||
* in logging in version 2.4, this will now set the warning
|
||||
* behaviour across the JVM (depending on the type of logger used)
|
||||
*
|
||||
* @param w the flag
|
||||
*/
|
||||
public void setSuppressWarnings(boolean w) {
|
||||
logger.setSuppressWarnings(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the formula adjust disabled
|
||||
*
|
||||
* @return TRUE if formulas are adjusted following row/column inserts/deletes
|
||||
* FALSE otherwise
|
||||
*/
|
||||
public boolean getFormulaAdjust() {
|
||||
return !formulaReferenceAdjustDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the formula adjust disabled property
|
||||
*
|
||||
* @param b TRUE to adjust formulas, FALSE otherwise
|
||||
*/
|
||||
public void setFormulaAdjust(boolean b) {
|
||||
formulaReferenceAdjustDisabled = !b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locale used by JExcelAPI to read the spreadsheet
|
||||
*
|
||||
* @return the locale
|
||||
*/
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the locale used by JExcelApi to generate the spreadsheet.
|
||||
* Setting this value has no effect on the language or region of
|
||||
* the generated excel file
|
||||
*
|
||||
* @param l the locale
|
||||
*/
|
||||
public void setLocale(Locale l) {
|
||||
locale = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the character encoding
|
||||
*
|
||||
* @return the character encoding for this workbook
|
||||
*/
|
||||
public String getEncoding() {
|
||||
return encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the encoding for this workbook
|
||||
*
|
||||
* @param enc the encoding
|
||||
*/
|
||||
public void setEncoding(String enc) {
|
||||
encoding = enc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the function names. This is used by the formula parsing package
|
||||
* in order to get the locale specific function names for this particular
|
||||
* workbook
|
||||
*
|
||||
* @return the list of function names
|
||||
*/
|
||||
public FunctionNames getFunctionNames() {
|
||||
if (functionNames == null) {
|
||||
functionNames = (FunctionNames) localeFunctionNames.get(locale);
|
||||
|
||||
// have not previously accessed function names for this locale,
|
||||
// so create a brand new one and add it to the list
|
||||
if (functionNames == null) {
|
||||
functionNames = new FunctionNames(locale);
|
||||
localeFunctionNames.put(locale, functionNames);
|
||||
}
|
||||
}
|
||||
|
||||
return functionNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the character set. This value is only used for reading
|
||||
* and has no effect when writing out the spreadsheet
|
||||
*
|
||||
* @return the character set used by this spreadsheet
|
||||
*/
|
||||
public int getCharacterSet() {
|
||||
return characterSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the character set. This is only used when the spreadsheet is
|
||||
* read, and has no effect when the spreadsheet is written
|
||||
*
|
||||
* @param cs the character set encoding value
|
||||
*/
|
||||
public void setCharacterSet(int cs) {
|
||||
characterSet = cs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the ignore blanks flag
|
||||
*
|
||||
* @return TRUE if blank cells are being ignored, FALSE otherwise
|
||||
*/
|
||||
public boolean getIgnoreBlanks() {
|
||||
return ignoreBlankCells;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ignore blanks flag
|
||||
*
|
||||
* @param ignoreBlanks TRUE to ignore blanks, FALSE to take them into account
|
||||
*/
|
||||
public void setIgnoreBlanks(boolean ignoreBlanks) {
|
||||
ignoreBlankCells = ignoreBlanks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the ignore cell validation
|
||||
*
|
||||
* @return TRUE if cell validation is disabled
|
||||
*/
|
||||
public boolean getCellValidationDisabled() {
|
||||
return cellValidationDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ignore cell validation flag
|
||||
*
|
||||
* @param cv TRUE to disable cell validation, FALSE to enable it
|
||||
*/
|
||||
public void setCellValidationDisabled(boolean cv) {
|
||||
cellValidationDisabled = cv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the two character ISO 3166 mnemonic used by excel for user
|
||||
* language displayto display
|
||||
*
|
||||
* @return the display language
|
||||
*/
|
||||
public String getExcelDisplayLanguage() {
|
||||
return excelDisplayLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the language in which the generated file will display
|
||||
*
|
||||
* @param code the two character ISO 3166 country code
|
||||
*/
|
||||
public void setExcelDisplayLanguage(String code) {
|
||||
excelDisplayLanguage = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the two character ISO 3166 mnemonic used by excel for
|
||||
* its regional settings
|
||||
*
|
||||
* @return the regional settings
|
||||
*/
|
||||
public String getExcelRegionalSettings() {
|
||||
return excelRegionalSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the regional settings for the generated excel file
|
||||
*
|
||||
* @param code the two character ISO 3166 country code
|
||||
*/
|
||||
public void setExcelRegionalSettings(String code) {
|
||||
excelRegionalSettings = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the autofilter disabled feature
|
||||
*
|
||||
* @return TRUE if autofilter is disabled, FALSE otherwise
|
||||
*/
|
||||
public boolean getAutoFilterDisabled() {
|
||||
return autoFilterDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the autofilter disabled
|
||||
*
|
||||
* @param disabled
|
||||
*/
|
||||
public void setAutoFilterDisabled(boolean disabled) {
|
||||
autoFilterDisabled = disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the temporary file during write. If this is set, then
|
||||
* when the workbook is written a temporary file will be used to store
|
||||
* the interim binary data, otherwise it will take place in memory. Setting
|
||||
* this flag involves an assessment of the trade-offs between memory usage
|
||||
* and performance
|
||||
*
|
||||
* @return TRUE if a temporary is file is used during writing,
|
||||
* FALSE otherwise
|
||||
*/
|
||||
public boolean getUseTemporaryFileDuringWrite() {
|
||||
return useTemporaryFileDuringWrite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether a temporary file is used during the generation of
|
||||
* the workbook. If not set, the workbook will take place entirely in
|
||||
* memory. Setting
|
||||
* this flag involves an assessment of the trade-offs between memory usage
|
||||
* and performance
|
||||
*
|
||||
* @return TRUE if a temporary is file is used during writing,
|
||||
* FALSE otherwise
|
||||
*/
|
||||
public void setUseTemporaryFileDuringWrite(boolean temp) {
|
||||
useTemporaryFileDuringWrite = temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in conjunction with the UseTemporaryFileDuringWrite setting to
|
||||
* set the target directory for the temporary files. This value can
|
||||
* be NULL, in which case the normal system default temporary directory
|
||||
* is used instead
|
||||
*
|
||||
* @return the temporary directory used during write, or NULL if it is
|
||||
* not set
|
||||
*/
|
||||
public File getTemporaryFileDuringWriteDirectory() {
|
||||
return temporaryFileDuringWriteDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in conjunction with the UseTemporaryFileDuringWrite setting to
|
||||
* set the target directory for the temporary files. If this is not set,
|
||||
* the system default temporary directory is used.
|
||||
* This has no effect unless the useTemporaryFileDuringWrite setting
|
||||
* is TRUE
|
||||
*
|
||||
* @param dir the directory to which temporary files should be written
|
||||
*/
|
||||
public void setTemporaryFileDuringWriteDirectory(File dir) {
|
||||
temporaryFileDuringWriteDirectory = dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* When true then Refresh All should be done on all external data ranges and
|
||||
* PivotTables when loading the workbook (the default is =0)
|
||||
*
|
||||
* @return the refreshAll value
|
||||
*/
|
||||
public boolean getRefreshAll() {
|
||||
return refreshAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* When true then Refresh All should be done on all external data ranges and
|
||||
* PivotTables when loading the workbook (the default is =0)
|
||||
*
|
||||
* @param refreshAll the refreshAll to set
|
||||
*/
|
||||
public void setRefreshAll(boolean refreshAll) {
|
||||
this.refreshAll = refreshAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Workbook Is a Template
|
||||
*
|
||||
* @return the template
|
||||
*/
|
||||
public boolean getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Workbook Is a Template
|
||||
*
|
||||
* @param template the template to set
|
||||
*/
|
||||
public void setTemplate(boolean template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has this file been written by excel 2000?
|
||||
*
|
||||
* @return the excel9file
|
||||
*/
|
||||
public boolean getExcel9File() {
|
||||
return excel9file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param excel9file the excel9file to set
|
||||
*/
|
||||
public void setExcel9File(boolean excel9file) {
|
||||
this.excel9file = excel9file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the windowprotected
|
||||
*/
|
||||
public boolean getWindowProtected() {
|
||||
return windowProtected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param windowprotected the windowprotected to set
|
||||
*/
|
||||
public void setWindowProtected(boolean windowprotected) {
|
||||
this.windowProtected = windowProtected;
|
||||
}
|
||||
|
||||
/**
|
||||
* The HIDEOBJ record stores options selected in the Options dialog,View tab
|
||||
* <p>
|
||||
* Possible values are:
|
||||
* HIDEOBJ_HIDE_ALL, HIDEOBJ_SHOW_ALL and HIDEOBJ_SHOW_PLACEHOLDERS
|
||||
*
|
||||
* @return the hideobj
|
||||
*/
|
||||
public int getHideobj() {
|
||||
return hideobj;
|
||||
}
|
||||
|
||||
/**
|
||||
* The HIDEOBJ record stores options selected in the Options dialog,View tab
|
||||
* <p>
|
||||
* Possible values are:
|
||||
* HIDEOBJ_HIDE_ALL, HIDEOBJ_SHOW_ALL and HIDEOBJ_SHOW_PLACEHOLDERS
|
||||
*
|
||||
* @param hideobj the hideobj to set
|
||||
*/
|
||||
public void setHideobj(int hideobj) {
|
||||
this.hideobj = hideobj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the writeAccess
|
||||
*/
|
||||
public String getWriteAccess() {
|
||||
return writeAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param writeAccess the writeAccess to set
|
||||
*/
|
||||
public void setWriteAccess(String writeAccess) {
|
||||
this.writeAccess = writeAccess;
|
||||
}
|
||||
}
|
||||
|
65
datastructures-xslx/src/main/java/jxl/biff/AutoFilter.java
Executable file
65
datastructures-xslx/src/main/java/jxl/biff/AutoFilter.java
Executable file
|
@ -0,0 +1,65 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2007 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import java.io.IOException;
|
||||
import jxl.write.biff.File;
|
||||
|
||||
/**
|
||||
* Information for autofiltering
|
||||
*/
|
||||
public class AutoFilter {
|
||||
private final FilterModeRecord filterMode;
|
||||
private final AutoFilterInfoRecord autoFilterInfo;
|
||||
private AutoFilterRecord autoFilter;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public AutoFilter(FilterModeRecord fmr,
|
||||
AutoFilterInfoRecord afir) {
|
||||
filterMode = fmr;
|
||||
autoFilterInfo = afir;
|
||||
}
|
||||
|
||||
public void add(AutoFilterRecord af) {
|
||||
autoFilter = af; // make this into a list sometime
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes out the data validation
|
||||
*
|
||||
* @param outputFile the output file
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(File outputFile) throws IOException {
|
||||
if (filterMode != null) {
|
||||
outputFile.write(filterMode);
|
||||
}
|
||||
|
||||
if (autoFilterInfo != null) {
|
||||
outputFile.write(autoFilterInfo);
|
||||
}
|
||||
|
||||
if (autoFilter != null) {
|
||||
outputFile.write(autoFilter);
|
||||
}
|
||||
}
|
||||
}
|
56
datastructures-xslx/src/main/java/jxl/biff/AutoFilterInfoRecord.java
Executable file
56
datastructures-xslx/src/main/java/jxl/biff/AutoFilterInfoRecord.java
Executable file
|
@ -0,0 +1,56 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2007 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import jxl.common.Logger;
|
||||
import jxl.read.biff.Record;
|
||||
|
||||
/**
|
||||
* Range information for conditional formatting
|
||||
*/
|
||||
public class AutoFilterInfoRecord extends WritableRecordData {
|
||||
// The logger
|
||||
private static final Logger logger = Logger.getLogger(AutoFilterInfoRecord.class);
|
||||
|
||||
/**
|
||||
* The data
|
||||
*/
|
||||
private final byte[] data;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public AutoFilterInfoRecord(Record t) {
|
||||
super(t);
|
||||
|
||||
data = getRecord().getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the data for output to binary file
|
||||
*
|
||||
* @return the data to be written
|
||||
*/
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
56
datastructures-xslx/src/main/java/jxl/biff/AutoFilterRecord.java
Executable file
56
datastructures-xslx/src/main/java/jxl/biff/AutoFilterRecord.java
Executable file
|
@ -0,0 +1,56 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2007 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import jxl.common.Logger;
|
||||
import jxl.read.biff.Record;
|
||||
|
||||
/**
|
||||
* Range information for conditional formatting
|
||||
*/
|
||||
public class AutoFilterRecord extends WritableRecordData {
|
||||
// The logger
|
||||
private static final Logger logger = Logger.getLogger(AutoFilterRecord.class);
|
||||
|
||||
/**
|
||||
* The data
|
||||
*/
|
||||
private final byte[] data;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public AutoFilterRecord(Record t) {
|
||||
super(t);
|
||||
|
||||
data = getRecord().getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the data for output to binary file
|
||||
*
|
||||
* @return the data to be written
|
||||
*/
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
489
datastructures-xslx/src/main/java/jxl/biff/BaseCellFeatures.java
Executable file
489
datastructures-xslx/src/main/java/jxl/biff/BaseCellFeatures.java
Executable file
|
@ -0,0 +1,489 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2004 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import java.util.Collection;
|
||||
import jxl.CellReferenceHelper;
|
||||
import jxl.Range;
|
||||
import jxl.biff.drawing.ComboBox;
|
||||
import jxl.biff.drawing.Comment;
|
||||
import jxl.common.Assert;
|
||||
import jxl.common.Logger;
|
||||
import jxl.write.biff.CellValue;
|
||||
|
||||
/**
|
||||
* Container for any additional cell features
|
||||
*/
|
||||
public class BaseCellFeatures {
|
||||
public static final ValidationCondition BETWEEN =
|
||||
new ValidationCondition(DVParser.BETWEEN);
|
||||
public static final ValidationCondition NOT_BETWEEN =
|
||||
new ValidationCondition(DVParser.NOT_BETWEEN);
|
||||
public static final ValidationCondition EQUAL =
|
||||
new ValidationCondition(DVParser.EQUAL);
|
||||
public static final ValidationCondition NOT_EQUAL =
|
||||
new ValidationCondition(DVParser.NOT_EQUAL);
|
||||
public static final ValidationCondition GREATER_THAN =
|
||||
new ValidationCondition(DVParser.GREATER_THAN);
|
||||
public static final ValidationCondition LESS_THAN =
|
||||
new ValidationCondition(DVParser.LESS_THAN);
|
||||
public static final ValidationCondition GREATER_EQUAL =
|
||||
new ValidationCondition(DVParser.GREATER_EQUAL);
|
||||
public static final ValidationCondition LESS_EQUAL =
|
||||
new ValidationCondition(DVParser.LESS_EQUAL);
|
||||
// Constants
|
||||
private final static double defaultCommentWidth = 3;
|
||||
private final static double defaultCommentHeight = 4;
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
public static Logger logger = Logger.getLogger(BaseCellFeatures.class);
|
||||
/**
|
||||
* The comment
|
||||
*/
|
||||
private String comment;
|
||||
/**
|
||||
* The comment width in cells
|
||||
*/
|
||||
private double commentWidth;
|
||||
/**
|
||||
* The comment height in cells
|
||||
*/
|
||||
private double commentHeight;
|
||||
/**
|
||||
* A handle to the drawing object
|
||||
*/
|
||||
private Comment commentDrawing;
|
||||
/**
|
||||
* A handle to the combo box object
|
||||
*/
|
||||
private ComboBox comboBox;
|
||||
/**
|
||||
* The data validation settings
|
||||
*/
|
||||
private DataValiditySettingsRecord validationSettings;
|
||||
/**
|
||||
* The DV Parser used to contain the validation details
|
||||
*/
|
||||
private DVParser dvParser;
|
||||
/**
|
||||
* Indicates whether a drop down is required
|
||||
*/
|
||||
private boolean dropDown;
|
||||
/**
|
||||
* Indicates whether this cell features has data validation
|
||||
*/
|
||||
private boolean dataValidation;
|
||||
/**
|
||||
* The cell to which this is attached, and which may need to be notified
|
||||
*/
|
||||
private CellValue writableCell;
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
protected BaseCellFeatures() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @param the cell to copy
|
||||
*/
|
||||
public BaseCellFeatures(BaseCellFeatures cf) {
|
||||
// The comment stuff
|
||||
comment = cf.comment;
|
||||
commentWidth = cf.commentWidth;
|
||||
commentHeight = cf.commentHeight;
|
||||
|
||||
// The data validation stuff.
|
||||
dropDown = cf.dropDown;
|
||||
dataValidation = cf.dataValidation;
|
||||
|
||||
validationSettings = cf.validationSettings; // ?
|
||||
|
||||
if (cf.dvParser != null) {
|
||||
dvParser = new DVParser(cf.dvParser);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the cell comment
|
||||
*/
|
||||
protected String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cell comment
|
||||
*
|
||||
* @param s the comment
|
||||
*/
|
||||
public void setComment(String s) {
|
||||
setComment(s, defaultCommentWidth, defaultCommentHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the comment width
|
||||
*/
|
||||
public double getCommentWidth() {
|
||||
return commentWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the comment height
|
||||
*/
|
||||
public double getCommentHeight() {
|
||||
return commentHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the cell when the features are added
|
||||
*
|
||||
* @param wc the writable cell
|
||||
*/
|
||||
public final void setWritableCell(CellValue wc) {
|
||||
writableCell = wc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to set the cell comment. Used when reading
|
||||
*/
|
||||
public void setReadComment(String s, double w, double h) {
|
||||
comment = s;
|
||||
commentWidth = w;
|
||||
commentHeight = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to set the data validation. Used when reading
|
||||
*/
|
||||
public void setValidationSettings(DataValiditySettingsRecord dvsr) {
|
||||
Assert.verify(dvsr != null);
|
||||
|
||||
validationSettings = dvsr;
|
||||
dataValidation = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cell comment
|
||||
*
|
||||
* @param s the comment
|
||||
* @param height the height of the comment box in cells
|
||||
* @param width the width of the comment box in cells
|
||||
*/
|
||||
public void setComment(String s, double width, double height) {
|
||||
comment = s;
|
||||
commentWidth = width;
|
||||
commentHeight = height;
|
||||
|
||||
if (commentDrawing != null) {
|
||||
commentDrawing.setCommentText(s);
|
||||
commentDrawing.setWidth(width);
|
||||
commentDrawing.setWidth(height);
|
||||
// commentDrawing is set up when trying to modify a copied cell
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the cell comment, if present
|
||||
*/
|
||||
public void removeComment() {
|
||||
// Set the comment string to be empty
|
||||
comment = null;
|
||||
|
||||
// Remove the drawing from the drawing group
|
||||
if (commentDrawing != null) {
|
||||
// do not call DrawingGroup.remove() because comments are not present
|
||||
// on the Workbook DrawingGroup record
|
||||
writableCell.removeComment(commentDrawing);
|
||||
commentDrawing = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Public function which removes any data validation, if present
|
||||
*/
|
||||
public void removeDataValidation() {
|
||||
if (!dataValidation) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the data validation is shared, then generate a warning
|
||||
DVParser dvp = getDVParser();
|
||||
if (dvp.extendedCellsValidation()) {
|
||||
logger.warn("Cannot remove data validation from " +
|
||||
CellReferenceHelper.getCellReference(writableCell) +
|
||||
" as it is part of the shared reference " +
|
||||
CellReferenceHelper.getCellReference(dvp.getFirstColumn(),
|
||||
dvp.getFirstRow()) +
|
||||
"-" +
|
||||
CellReferenceHelper.getCellReference(dvp.getLastColumn(),
|
||||
dvp.getLastRow()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the validation from the WritableSheet object if present
|
||||
writableCell.removeDataValidation();
|
||||
clearValidationSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function which removes any data validation, including
|
||||
* shared ones, if present. This is called from WritableSheetImpl
|
||||
* in response to a call to removeDataValidation
|
||||
*/
|
||||
public void removeSharedDataValidation() {
|
||||
if (!dataValidation) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the validation from the WritableSheet object if present
|
||||
writableCell.removeDataValidation();
|
||||
clearValidationSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the comment drawing
|
||||
*/
|
||||
public final Comment getCommentDrawing() {
|
||||
return commentDrawing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment drawing object
|
||||
*/
|
||||
public final void setCommentDrawing(Comment c) {
|
||||
commentDrawing = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data validation list as a formula. Used only when reading
|
||||
*
|
||||
* @return the validation formula as a list
|
||||
*/
|
||||
public String getDataValidationList() {
|
||||
if (validationSettings == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return validationSettings.getValidationFormula();
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of items to validate for this cell. For each object in the
|
||||
* collection, the toString() method will be called and the data entered
|
||||
* will be validated against that string
|
||||
*
|
||||
* @param c the list of valid values
|
||||
*/
|
||||
public void setDataValidationList(Collection c) {
|
||||
if (dataValidation && getDVParser().extendedCellsValidation()) {
|
||||
logger.warn("Cannot set data validation on " +
|
||||
CellReferenceHelper.getCellReference(writableCell) +
|
||||
" as it is part of a shared data validation");
|
||||
return;
|
||||
}
|
||||
clearValidationSettings();
|
||||
dvParser = new DVParser(c);
|
||||
dropDown = true;
|
||||
dataValidation = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of items to validate for this cell in the form of a cell range.
|
||||
*
|
||||
* @param c the list of valid values
|
||||
*/
|
||||
public void setDataValidationRange(int col1, int r1, int col2, int r2) {
|
||||
if (dataValidation && getDVParser().extendedCellsValidation()) {
|
||||
logger.warn("Cannot set data validation on " +
|
||||
CellReferenceHelper.getCellReference(writableCell) +
|
||||
" as it is part of a shared data validation");
|
||||
return;
|
||||
}
|
||||
clearValidationSettings();
|
||||
dvParser = new DVParser(col1, r1, col2, r2);
|
||||
dropDown = true;
|
||||
dataValidation = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data validation based upon a named range
|
||||
*/
|
||||
public void setDataValidationRange(String namedRange) {
|
||||
if (dataValidation && getDVParser().extendedCellsValidation()) {
|
||||
logger.warn("Cannot set data validation on " +
|
||||
CellReferenceHelper.getCellReference(writableCell) +
|
||||
" as it is part of a shared data validation");
|
||||
return;
|
||||
}
|
||||
clearValidationSettings();
|
||||
dvParser = new DVParser(namedRange);
|
||||
dropDown = true;
|
||||
dataValidation = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data validation based upon a numerical condition
|
||||
*/
|
||||
public void setNumberValidation(double val, ValidationCondition c) {
|
||||
if (dataValidation && getDVParser().extendedCellsValidation()) {
|
||||
logger.warn("Cannot set data validation on " +
|
||||
CellReferenceHelper.getCellReference(writableCell) +
|
||||
" as it is part of a shared data validation");
|
||||
return;
|
||||
}
|
||||
clearValidationSettings();
|
||||
dvParser = new DVParser(val, Double.NaN, c.getCondition());
|
||||
dropDown = false;
|
||||
dataValidation = true;
|
||||
}
|
||||
|
||||
public void setNumberValidation(double val1, double val2,
|
||||
ValidationCondition c) {
|
||||
if (dataValidation && getDVParser().extendedCellsValidation()) {
|
||||
logger.warn("Cannot set data validation on " +
|
||||
CellReferenceHelper.getCellReference(writableCell) +
|
||||
" as it is part of a shared data validation");
|
||||
return;
|
||||
}
|
||||
clearValidationSettings();
|
||||
dvParser = new DVParser(val1, val2, c.getCondition());
|
||||
dropDown = false;
|
||||
dataValidation = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the data validation
|
||||
*
|
||||
* @return TRUE if this has a data validation associated with it,
|
||||
* FALSE otherwise
|
||||
*/
|
||||
public boolean hasDataValidation() {
|
||||
return dataValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears out any existing validation settings
|
||||
*/
|
||||
private void clearValidationSettings() {
|
||||
validationSettings = null;
|
||||
dvParser = null;
|
||||
dropDown = false;
|
||||
comboBox = null;
|
||||
dataValidation = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for whether a drop down is required
|
||||
*
|
||||
* @return TRUE if this requires a drop down, FALSE otherwise
|
||||
*/
|
||||
public boolean hasDropDown() {
|
||||
return dropDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the combo box drawing object for list validations
|
||||
*
|
||||
* @param cb the combo box
|
||||
*/
|
||||
public void setComboBox(ComboBox cb) {
|
||||
comboBox = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the dv parser
|
||||
*/
|
||||
public DVParser getDVParser() {
|
||||
// straightforward - this was created as a writable cell
|
||||
if (dvParser != null) {
|
||||
return dvParser;
|
||||
}
|
||||
|
||||
// this was copied from a readable cell, and then copied again
|
||||
if (validationSettings != null) {
|
||||
dvParser = new DVParser(validationSettings.getDVParser());
|
||||
return dvParser;
|
||||
}
|
||||
|
||||
return null; // keep the compiler happy
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the same data validation logic as the specified cell features
|
||||
*
|
||||
* @param cf the data validation to reuse
|
||||
*/
|
||||
public void shareDataValidation(BaseCellFeatures source) {
|
||||
if (dataValidation) {
|
||||
logger.warn("Attempting to share a data validation on cell " +
|
||||
CellReferenceHelper.getCellReference(writableCell) +
|
||||
" which already has a data validation");
|
||||
return;
|
||||
}
|
||||
clearValidationSettings();
|
||||
dvParser = source.getDVParser();
|
||||
validationSettings = null;
|
||||
dataValidation = true;
|
||||
dropDown = source.dropDown;
|
||||
comboBox = source.comboBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the range of cells to which the data validation applies. If the
|
||||
* validation applies to just this cell, this will be reflected in the
|
||||
* returned range
|
||||
*
|
||||
* @return the range to which the same validation extends, or NULL if this
|
||||
* cell doesn't have a validation
|
||||
*/
|
||||
public Range getSharedDataValidationRange() {
|
||||
if (!dataValidation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DVParser dvp = getDVParser();
|
||||
|
||||
return new SheetRangeImpl(writableCell.getSheet(),
|
||||
dvp.getFirstColumn(),
|
||||
dvp.getFirstRow(),
|
||||
dvp.getLastColumn(),
|
||||
dvp.getLastRow());
|
||||
}
|
||||
|
||||
// Validation conditions
|
||||
protected static class ValidationCondition {
|
||||
private static ValidationCondition[] types = new ValidationCondition[0];
|
||||
private final DVParser.Condition condition;
|
||||
|
||||
ValidationCondition(DVParser.Condition c) {
|
||||
condition = c;
|
||||
ValidationCondition[] oldtypes = types;
|
||||
types = new ValidationCondition[oldtypes.length + 1];
|
||||
System.arraycopy(oldtypes, 0, types, 0, oldtypes.length);
|
||||
types[oldtypes.length] = this;
|
||||
}
|
||||
|
||||
public DVParser.Condition getCondition() {
|
||||
return condition;
|
||||
}
|
||||
}
|
||||
}
|
349
datastructures-xslx/src/main/java/jxl/biff/BaseCompoundFile.java
Executable file
349
datastructures-xslx/src/main/java/jxl/biff/BaseCompoundFile.java
Executable file
|
@ -0,0 +1,349 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import jxl.common.Assert;
|
||||
import jxl.common.Logger;
|
||||
|
||||
/**
|
||||
* Contains the common data for a compound file
|
||||
*/
|
||||
public abstract class BaseCompoundFile {
|
||||
/**
|
||||
* The standard property sets
|
||||
*/
|
||||
public final static String ROOT_ENTRY_NAME = "Root Entry";
|
||||
public final static String WORKBOOK_NAME = "Workbook";
|
||||
public final static String SUMMARY_INFORMATION_NAME =
|
||||
"\u0005SummaryInformation";
|
||||
public final static String DOCUMENT_SUMMARY_INFORMATION_NAME =
|
||||
"\u0005DocumentSummaryInformation";
|
||||
public final static String COMP_OBJ_NAME =
|
||||
"\u0001CompObj";
|
||||
public final static String[] STANDARD_PROPERTY_SETS =
|
||||
new String[]{ROOT_ENTRY_NAME, WORKBOOK_NAME,
|
||||
SUMMARY_INFORMATION_NAME,
|
||||
DOCUMENT_SUMMARY_INFORMATION_NAME};
|
||||
/**
|
||||
* Property storage types
|
||||
*/
|
||||
public final static int NONE_PS_TYPE = 0;
|
||||
public final static int DIRECTORY_PS_TYPE = 1;
|
||||
public final static int FILE_PS_TYPE = 2;
|
||||
public final static int ROOT_ENTRY_PS_TYPE = 5;
|
||||
/**
|
||||
* The identifier at the beginning of every OLE file
|
||||
*/
|
||||
protected static final byte[] IDENTIFIER = new byte[]
|
||||
{(byte) 0xd0,
|
||||
(byte) 0xcf,
|
||||
(byte) 0x11,
|
||||
(byte) 0xe0,
|
||||
(byte) 0xa1,
|
||||
(byte) 0xb1,
|
||||
(byte) 0x1a,
|
||||
(byte) 0xe1};
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c;
|
||||
|
||||
// property storage offsets
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int NUM_SMALL_BLOCK_DEPOT_BLOCKS_POS = 0x40;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int ROOT_START_BLOCK_POS = 0x30;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int BIG_BLOCK_SIZE = 0x200;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int SMALL_BLOCK_SIZE = 0x40;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int EXTENSION_BLOCK_POS = 0x44;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int NUM_EXTENSION_BLOCK_POS = 0x48;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int PROPERTY_STORAGE_BLOCK_SIZE = 0x80;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static final int SMALL_BLOCK_THRESHOLD = 0x1000;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int SIZE_OF_NAME_POS = 0x40;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int TYPE_POS = 0x42;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int COLOUR_POS = 0x43;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int PREVIOUS_POS = 0x44;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int NEXT_POS = 0x48;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int CHILD_POS = 0x4c;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int START_BLOCK_POS = 0x74;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final int SIZE_POS = 0x78;
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(BaseCompoundFile.class);
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
protected BaseCompoundFile() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner class to represent the property storage sets. Access is public
|
||||
* to allow access from the PropertySetsReader demo utility
|
||||
*/
|
||||
public class PropertyStorage {
|
||||
/**
|
||||
* The name of this property set
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* The type of the property set
|
||||
*/
|
||||
public int type;
|
||||
/**
|
||||
* The colour of the property set
|
||||
*/
|
||||
public int colour;
|
||||
/**
|
||||
* The block number in the stream which this property sets starts at
|
||||
*/
|
||||
public int startBlock;
|
||||
/**
|
||||
* The size, in bytes, of this property set
|
||||
*/
|
||||
public int size;
|
||||
/**
|
||||
* The previous property set
|
||||
*/
|
||||
public int previous;
|
||||
/**
|
||||
* The next property set
|
||||
*/
|
||||
public int next;
|
||||
/**
|
||||
* The child for this property set
|
||||
*/
|
||||
public int child;
|
||||
|
||||
/**
|
||||
* The data that created this set
|
||||
*/
|
||||
public byte[] data;
|
||||
|
||||
/**
|
||||
* Constructs a property set
|
||||
*
|
||||
* @param d the bytes
|
||||
*/
|
||||
public PropertyStorage(byte[] d) {
|
||||
data = d;
|
||||
int nameSize = IntegerHelper.getInt(data[SIZE_OF_NAME_POS],
|
||||
data[SIZE_OF_NAME_POS + 1]);
|
||||
|
||||
if (nameSize > SIZE_OF_NAME_POS) {
|
||||
logger.warn("property set name exceeds max length - truncating");
|
||||
nameSize = SIZE_OF_NAME_POS;
|
||||
|
||||
}
|
||||
type = data[TYPE_POS];
|
||||
colour = data[COLOUR_POS];
|
||||
|
||||
startBlock = IntegerHelper.getInt
|
||||
(data[START_BLOCK_POS],
|
||||
data[START_BLOCK_POS + 1],
|
||||
data[START_BLOCK_POS + 2],
|
||||
data[START_BLOCK_POS + 3]);
|
||||
size = IntegerHelper.getInt
|
||||
(data[SIZE_POS],
|
||||
data[SIZE_POS + 1],
|
||||
data[SIZE_POS + 2],
|
||||
data[SIZE_POS + 3]);
|
||||
previous = IntegerHelper.getInt
|
||||
(data[PREVIOUS_POS],
|
||||
data[PREVIOUS_POS + 1],
|
||||
data[PREVIOUS_POS + 2],
|
||||
data[PREVIOUS_POS + 3]);
|
||||
next = IntegerHelper.getInt
|
||||
(data[NEXT_POS],
|
||||
data[NEXT_POS + 1],
|
||||
data[NEXT_POS + 2],
|
||||
data[NEXT_POS + 3]);
|
||||
child = IntegerHelper.getInt
|
||||
(data[CHILD_POS],
|
||||
data[CHILD_POS + 1],
|
||||
data[CHILD_POS + 2],
|
||||
data[CHILD_POS + 3]);
|
||||
|
||||
int chars = 0;
|
||||
if (nameSize > 2) {
|
||||
chars = (nameSize - 1) / 2;
|
||||
}
|
||||
|
||||
StringBuffer n = new StringBuffer();
|
||||
for (int i = 0; i < chars; i++) {
|
||||
n.append((char) data[i * 2]);
|
||||
}
|
||||
|
||||
name = n.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an empty property set. Used when writing the file
|
||||
*
|
||||
* @param name the property storage name
|
||||
*/
|
||||
public PropertyStorage(String name) {
|
||||
data = new byte[PROPERTY_STORAGE_BLOCK_SIZE];
|
||||
|
||||
Assert.verify(name.length() < 32);
|
||||
|
||||
IntegerHelper.getTwoBytes((name.length() + 1) * 2,
|
||||
data,
|
||||
SIZE_OF_NAME_POS);
|
||||
// add one to the name length to allow for the null character at
|
||||
// the end
|
||||
for (int i = 0; i < name.length(); i++) {
|
||||
data[i * 2] = (byte) name.charAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type
|
||||
*
|
||||
* @param t the type
|
||||
*/
|
||||
public void setType(int t) {
|
||||
type = t;
|
||||
data[TYPE_POS] = (byte) t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of the start block
|
||||
*
|
||||
* @param sb the number of the start block
|
||||
*/
|
||||
public void setStartBlock(int sb) {
|
||||
startBlock = sb;
|
||||
IntegerHelper.getFourBytes(sb, data, START_BLOCK_POS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the file
|
||||
*
|
||||
* @param s the size
|
||||
*/
|
||||
public void setSize(int s) {
|
||||
size = s;
|
||||
IntegerHelper.getFourBytes(s, data, SIZE_POS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the previous block
|
||||
*
|
||||
* @param prev the previous block
|
||||
*/
|
||||
public void setPrevious(int prev) {
|
||||
previous = prev;
|
||||
IntegerHelper.getFourBytes(prev, data, PREVIOUS_POS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the next block
|
||||
*
|
||||
* @param nxt the next block
|
||||
*/
|
||||
public void setNext(int nxt) {
|
||||
next = nxt;
|
||||
IntegerHelper.getFourBytes(next, data, NEXT_POS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the child
|
||||
*
|
||||
* @param dir the child
|
||||
*/
|
||||
public void setChild(int dir) {
|
||||
child = dir;
|
||||
IntegerHelper.getFourBytes(child, data, CHILD_POS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the colour
|
||||
*
|
||||
* @param col colour
|
||||
*/
|
||||
public void setColour(int col) {
|
||||
colour = col == 0 ? 0 : 1;
|
||||
data[COLOUR_POS] = (byte) colour;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
166
datastructures-xslx/src/main/java/jxl/biff/BuiltInFormat.java
Executable file
166
datastructures-xslx/src/main/java/jxl/biff/BuiltInFormat.java
Executable file
|
@ -0,0 +1,166 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import jxl.format.Format;
|
||||
|
||||
/**
|
||||
* The excel string for the various built in formats. Used to present
|
||||
* the cell format information back to the user
|
||||
* <p>
|
||||
* The difference between this class and the various format object contained
|
||||
* in the jxl.write package is that this object contains the Excel strings,
|
||||
* not their java equivalents
|
||||
*/
|
||||
final class BuiltInFormat implements Format, DisplayFormat {
|
||||
/**
|
||||
* The list of built in formats
|
||||
*/
|
||||
public static BuiltInFormat[] builtIns = new BuiltInFormat[0x32];
|
||||
|
||||
// Populate the built ins
|
||||
static {
|
||||
builtIns[0x0] = new BuiltInFormat("", 0);
|
||||
builtIns[0x1] = new BuiltInFormat("0", 1);
|
||||
builtIns[0x2] = new BuiltInFormat("0.00", 2);
|
||||
builtIns[0x3] = new BuiltInFormat("#,##0", 3);
|
||||
builtIns[0x4] = new BuiltInFormat("#,##0.00", 4);
|
||||
builtIns[0x5] = new BuiltInFormat("($#,##0_);($#,##0)", 5);
|
||||
builtIns[0x6] = new BuiltInFormat("($#,##0_);[Red]($#,##0)", 6);
|
||||
builtIns[0x7] = new BuiltInFormat("($#,##0_);[Red]($#,##0)", 7);
|
||||
builtIns[0x8] = new BuiltInFormat("($#,##0.00_);[Red]($#,##0.00)", 8);
|
||||
builtIns[0x9] = new BuiltInFormat("0%", 9);
|
||||
builtIns[0xa] = new BuiltInFormat("0.00%", 10);
|
||||
builtIns[0xb] = new BuiltInFormat("0.00E+00", 11);
|
||||
builtIns[0xc] = new BuiltInFormat("# ?/?", 12);
|
||||
builtIns[0xd] = new BuiltInFormat("# ??/??", 13);
|
||||
builtIns[0xe] = new BuiltInFormat("dd/mm/yyyy", 14);
|
||||
builtIns[0xf] = new BuiltInFormat("d-mmm-yy", 15);
|
||||
builtIns[0x10] = new BuiltInFormat("d-mmm", 16);
|
||||
builtIns[0x11] = new BuiltInFormat("mmm-yy", 17);
|
||||
builtIns[0x12] = new BuiltInFormat("h:mm AM/PM", 18);
|
||||
builtIns[0x13] = new BuiltInFormat("h:mm:ss AM/PM", 19);
|
||||
builtIns[0x14] = new BuiltInFormat("h:mm", 20);
|
||||
builtIns[0x15] = new BuiltInFormat("h:mm:ss", 21);
|
||||
builtIns[0x16] = new BuiltInFormat("m/d/yy h:mm", 22);
|
||||
builtIns[0x25] = new BuiltInFormat("(#,##0_);(#,##0)", 0x25);
|
||||
builtIns[0x26] = new BuiltInFormat("(#,##0_);[Red](#,##0)", 0x26);
|
||||
builtIns[0x27] = new BuiltInFormat("(#,##0.00_);(#,##0.00)", 0x27);
|
||||
builtIns[0x28] = new BuiltInFormat("(#,##0.00_);[Red](#,##0.00)", 0x28);
|
||||
builtIns[0x29] = new BuiltInFormat
|
||||
("_(*#,##0_);_(*(#,##0);_(*\"-\"_);(@_)", 0x29);
|
||||
builtIns[0x2a] = new BuiltInFormat
|
||||
("_($*#,##0_);_($*(#,##0);_($*\"-\"_);(@_)", 0x2a);
|
||||
builtIns[0x2b] = new BuiltInFormat
|
||||
("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);(@_)", 0x2b);
|
||||
builtIns[0x2c] = new BuiltInFormat
|
||||
("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);(@_)", 0x2c);
|
||||
builtIns[0x2d] = new BuiltInFormat("mm:ss", 0x2d);
|
||||
builtIns[0x2e] = new BuiltInFormat("[h]mm:ss", 0x2e);
|
||||
builtIns[0x2f] = new BuiltInFormat("mm:ss.0", 0x2f);
|
||||
builtIns[0x30] = new BuiltInFormat("##0.0E+0", 0x30);
|
||||
builtIns[0x31] = new BuiltInFormat("@", 0x31);
|
||||
}
|
||||
|
||||
/**
|
||||
* The excel format string
|
||||
*/
|
||||
private final String formatString;
|
||||
/**
|
||||
* The index
|
||||
*/
|
||||
private final int formatIndex;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param s the format string
|
||||
* @param i the format index
|
||||
*/
|
||||
private BuiltInFormat(String s, int i) {
|
||||
formatIndex = i;
|
||||
formatString = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accesses the excel format string which is applied to the cell
|
||||
* Note that this is the string that excel uses, and not the java
|
||||
* equivalent
|
||||
*
|
||||
* @return the cell format string
|
||||
*/
|
||||
public String getFormatString() {
|
||||
return formatString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the index style of this format
|
||||
*
|
||||
* @return the index for this format
|
||||
*/
|
||||
public int getFormatIndex() {
|
||||
return formatIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to see whether this format has been initialized
|
||||
*
|
||||
* @return TRUE if initialized, FALSE otherwise
|
||||
*/
|
||||
public boolean isInitialized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this format with the specified index number
|
||||
*
|
||||
* @param pos the position of this format record in the workbook
|
||||
*/
|
||||
public void initialize(int pos) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to determine whether or not this format is built in
|
||||
*
|
||||
* @return TRUE if this format is a built in format, FALSE otherwise
|
||||
*/
|
||||
public boolean isBuiltIn() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals method
|
||||
*
|
||||
* @return TRUE if the two built in formats are equal, FALSE otherwise
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof BuiltInFormat)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BuiltInFormat bif = (BuiltInFormat) o;
|
||||
return (formatIndex == bif.formatIndex);
|
||||
}
|
||||
}
|
||||
|
110
datastructures-xslx/src/main/java/jxl/biff/BuiltInName.java
Executable file
110
datastructures-xslx/src/main/java/jxl/biff/BuiltInName.java
Executable file
|
@ -0,0 +1,110 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2006 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
/**
|
||||
* Enumeration of built in names
|
||||
*/
|
||||
public class BuiltInName {
|
||||
// The list of built in names
|
||||
public static final BuiltInName CONSOLIDATE_AREA =
|
||||
new BuiltInName("Consolidate_Area", 0x0);
|
||||
public static final BuiltInName AUTO_OPEN =
|
||||
new BuiltInName("Auto_Open", 0x1);
|
||||
public static final BuiltInName AUTO_CLOSE =
|
||||
new BuiltInName("Auto_Open", 0x2);
|
||||
public static final BuiltInName EXTRACT =
|
||||
new BuiltInName("Extract", 0x3);
|
||||
public static final BuiltInName DATABASE =
|
||||
new BuiltInName("Database", 0x4);
|
||||
public static final BuiltInName CRITERIA =
|
||||
new BuiltInName("Criteria", 0x5);
|
||||
public static final BuiltInName PRINT_AREA =
|
||||
new BuiltInName("Print_Area", 0x6);
|
||||
public static final BuiltInName PRINT_TITLES =
|
||||
new BuiltInName("Print_Titles", 0x7);
|
||||
public static final BuiltInName RECORDER =
|
||||
new BuiltInName("Recorder", 0x8);
|
||||
public static final BuiltInName DATA_FORM =
|
||||
new BuiltInName("Data_Form", 0x9);
|
||||
public static final BuiltInName AUTO_ACTIVATE =
|
||||
new BuiltInName("Auto_Activate", 0xa);
|
||||
public static final BuiltInName AUTO_DEACTIVATE =
|
||||
new BuiltInName("Auto_Deactivate", 0xb);
|
||||
public static final BuiltInName SHEET_TITLE =
|
||||
new BuiltInName("Sheet_Title", 0xb);
|
||||
public static final BuiltInName FILTER_DATABASE =
|
||||
new BuiltInName("_FilterDatabase", 0xd);
|
||||
/**
|
||||
* The list of name
|
||||
*/
|
||||
private static BuiltInName[] builtInNames = new BuiltInName[0];
|
||||
/**
|
||||
* The name
|
||||
*/
|
||||
private final String name;
|
||||
/**
|
||||
* The value
|
||||
*/
|
||||
private final int value;
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
private BuiltInName(String n, int v) {
|
||||
name = n;
|
||||
value = v;
|
||||
|
||||
BuiltInName[] oldnames = builtInNames;
|
||||
builtInNames = new BuiltInName[oldnames.length + 1];
|
||||
System.arraycopy(oldnames, 0, builtInNames, 0, oldnames.length);
|
||||
builtInNames[oldnames.length] = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the built in name for the value
|
||||
*/
|
||||
public static BuiltInName getBuiltInName(int val) {
|
||||
BuiltInName ret = FILTER_DATABASE;
|
||||
for (int i = 0; i < builtInNames.length; i++) {
|
||||
if (builtInNames[i].getValue() == val) {
|
||||
ret = builtInNames[i];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the name
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the value
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
70
datastructures-xslx/src/main/java/jxl/biff/BuiltInStyle.java
Executable file
70
datastructures-xslx/src/main/java/jxl/biff/BuiltInStyle.java
Executable file
|
@ -0,0 +1,70 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
/**
|
||||
* Represents a built in, rather than a user defined, style.
|
||||
* This class is used by the FormattingRecords class when writing out the hard*
|
||||
* coded styles
|
||||
*/
|
||||
class BuiltInStyle extends WritableRecordData {
|
||||
/**
|
||||
* The XF index of this style
|
||||
*/
|
||||
private final int xfIndex;
|
||||
/**
|
||||
* The reference number of this style
|
||||
*/
|
||||
private final int styleNumber;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param xfind the xf index of this style
|
||||
* @param sn the style number of this style
|
||||
*/
|
||||
public BuiltInStyle(int xfind, int sn) {
|
||||
super(Type.STYLE);
|
||||
|
||||
xfIndex = xfind;
|
||||
styleNumber = sn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method implementation to get the raw byte data ready to write out
|
||||
*
|
||||
* @return The byte data
|
||||
*/
|
||||
public byte[] getData() {
|
||||
byte[] data = new byte[4];
|
||||
|
||||
IntegerHelper.getTwoBytes(xfIndex, data, 0);
|
||||
|
||||
// Set the built in bit
|
||||
data[1] |= 0x80;
|
||||
|
||||
data[2] = (byte) styleNumber;
|
||||
|
||||
// Set the outline level
|
||||
data[3] = (byte) 0xff;
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
106
datastructures-xslx/src/main/java/jxl/biff/ByteArray.java
Executable file
106
datastructures-xslx/src/main/java/jxl/biff/ByteArray.java
Executable file
|
@ -0,0 +1,106 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
/**
|
||||
* A growable array of bytes
|
||||
*/
|
||||
public class ByteArray {
|
||||
// The default grow size
|
||||
private final static int defaultGrowSize = 1024;
|
||||
/**
|
||||
* The array grow size
|
||||
*/
|
||||
private final int growSize;
|
||||
/**
|
||||
* The current array
|
||||
*/
|
||||
private byte[] bytes;
|
||||
/**
|
||||
* The current position
|
||||
*/
|
||||
private int pos;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public ByteArray() {
|
||||
this(defaultGrowSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param gs
|
||||
*/
|
||||
public ByteArray(int gs) {
|
||||
growSize = gs;
|
||||
bytes = new byte[defaultGrowSize];
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a byte onto the array
|
||||
*
|
||||
* @param b the byte
|
||||
*/
|
||||
public void add(byte b) {
|
||||
checkSize(1);
|
||||
bytes[pos] = b;
|
||||
pos++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an array of bytes onto the array
|
||||
*
|
||||
* @param b the array of bytes
|
||||
*/
|
||||
public void add(byte[] b) {
|
||||
checkSize(b.length);
|
||||
System.arraycopy(b, 0, bytes, pos, b.length);
|
||||
pos += b.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the complete array
|
||||
*
|
||||
* @return the array
|
||||
*/
|
||||
public byte[] getBytes() {
|
||||
byte[] returnArray = new byte[pos];
|
||||
System.arraycopy(bytes, 0, returnArray, 0, pos);
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if there is sufficient space left on the array. If not,
|
||||
* then it grows the array
|
||||
*
|
||||
* @param sz the amount of bytes to add
|
||||
*/
|
||||
private void checkSize(int sz) {
|
||||
while (pos + sz >= bytes.length) {
|
||||
// Grow the array
|
||||
byte[] newArray = new byte[bytes.length + growSize];
|
||||
System.arraycopy(bytes, 0, newArray, 0, pos);
|
||||
bytes = newArray;
|
||||
}
|
||||
}
|
||||
}
|
33
datastructures-xslx/src/main/java/jxl/biff/ByteData.java
Executable file
33
datastructures-xslx/src/main/java/jxl/biff/ByteData.java
Executable file
|
@ -0,0 +1,33 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
/**
|
||||
* Interface which provides a method for transferring chunks of binary
|
||||
* data from one Excel file (read in) to another (written out)
|
||||
*/
|
||||
public interface ByteData {
|
||||
/**
|
||||
* Used when writing out records
|
||||
*
|
||||
* @return the full data to be included in the final compound file
|
||||
*/
|
||||
byte[] getBytes();
|
||||
}
|
196
datastructures-xslx/src/main/java/jxl/biff/CellFinder.java
Executable file
196
datastructures-xslx/src/main/java/jxl/biff/CellFinder.java
Executable file
|
@ -0,0 +1,196 @@
|
|||
/**********************************************************************
|
||||
*
|
||||
* Copyright (C) 2008 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import jxl.Cell;
|
||||
import jxl.CellType;
|
||||
import jxl.LabelCell;
|
||||
import jxl.Sheet;
|
||||
|
||||
/**
|
||||
* Refactorisation to provide more sophisticated find cell by contents
|
||||
* functionality
|
||||
*/
|
||||
public class CellFinder {
|
||||
private final Sheet sheet;
|
||||
|
||||
public CellFinder(Sheet s) {
|
||||
sheet = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell whose contents match the string passed in.
|
||||
* If no match is found, then null is returned. The search is performed
|
||||
* on a row by row basis, so the lower the row number, the more
|
||||
* efficiently the algorithm will perform
|
||||
*
|
||||
* @param contents the string to match
|
||||
* @param firstCol the first column within the range
|
||||
* @param firstRow the first row of the range
|
||||
* @param lastCol the last column within the range
|
||||
* @param lastRow the last row within the range
|
||||
* @param reverse indicates whether to perform a reverse search or not
|
||||
* @return the Cell whose contents match the parameter, null if not found
|
||||
*/
|
||||
public Cell findCell(String contents,
|
||||
int firstCol,
|
||||
int firstRow,
|
||||
int lastCol,
|
||||
int lastRow,
|
||||
boolean reverse) {
|
||||
Cell cell = null;
|
||||
boolean found = false;
|
||||
|
||||
int numCols = lastCol - firstCol;
|
||||
int numRows = lastRow - firstRow;
|
||||
|
||||
int row1 = reverse ? lastRow : firstRow;
|
||||
int row2 = reverse ? firstRow : lastRow;
|
||||
int col1 = reverse ? lastCol : firstCol;
|
||||
int col2 = reverse ? firstCol : lastCol;
|
||||
int inc = reverse ? -1 : 1;
|
||||
|
||||
for (int i = 0; i <= numCols && found == false; i++) {
|
||||
for (int j = 0; j <= numRows && found == false; j++) {
|
||||
int curCol = col1 + i * inc;
|
||||
int curRow = row1 + j * inc;
|
||||
if (curCol < sheet.getColumns() && curRow < sheet.getRows()) {
|
||||
Cell c = sheet.getCell(curCol, curRow);
|
||||
if (c.getType() != CellType.EMPTY) {
|
||||
if (c.getContents().equals(contents)) {
|
||||
cell = c;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a cell within a given range of cells
|
||||
*
|
||||
* @param contents the string to match
|
||||
* @return the Cell whose contents match the parameter, null if not found
|
||||
*/
|
||||
public Cell findCell(String contents) {
|
||||
Cell cell = null;
|
||||
boolean found = false;
|
||||
|
||||
for (int i = 0; i < sheet.getRows() && found == false; i++) {
|
||||
Cell[] row = sheet.getRow(i);
|
||||
for (int j = 0; j < row.length && found == false; j++) {
|
||||
if (row[j].getContents().equals(contents)) {
|
||||
cell = row[j];
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell whose contents match the regular expressionstring passed in.
|
||||
* If no match is found, then null is returned. The search is performed
|
||||
* on a row by row basis, so the lower the row number, the more
|
||||
* efficiently the algorithm will perform
|
||||
*
|
||||
* @param pattern the regular expression string to match
|
||||
* @param firstCol the first column within the range
|
||||
* @param firstRow the first row of the range
|
||||
* @param lastCol the last column within the range
|
||||
* @param lastRow the last row within the range
|
||||
* @param reverse indicates whether to perform a reverse search or not
|
||||
* @return the Cell whose contents match the parameter, null if not found
|
||||
*/
|
||||
public Cell findCell(Pattern pattern,
|
||||
int firstCol,
|
||||
int firstRow,
|
||||
int lastCol,
|
||||
int lastRow,
|
||||
boolean reverse) {
|
||||
Cell cell = null;
|
||||
boolean found = false;
|
||||
|
||||
int numCols = lastCol - firstCol;
|
||||
int numRows = lastRow - firstRow;
|
||||
|
||||
int row1 = reverse ? lastRow : firstRow;
|
||||
int row2 = reverse ? firstRow : lastRow;
|
||||
int col1 = reverse ? lastCol : firstCol;
|
||||
int col2 = reverse ? firstCol : lastCol;
|
||||
int inc = reverse ? -1 : 1;
|
||||
|
||||
for (int i = 0; i <= numCols && found == false; i++) {
|
||||
for (int j = 0; j <= numRows && found == false; j++) {
|
||||
int curCol = col1 + i * inc;
|
||||
int curRow = row1 + j * inc;
|
||||
if (curCol < sheet.getColumns() && curRow < sheet.getRows()) {
|
||||
Cell c = sheet.getCell(curCol, curRow);
|
||||
if (c.getType() != CellType.EMPTY) {
|
||||
Matcher m = pattern.matcher(c.getContents());
|
||||
if (m.matches()) {
|
||||
cell = c;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell whose contents match the string passed in.
|
||||
* If no match is found, then null is returned. The search is performed
|
||||
* on a row by row basis, so the lower the row number, the more
|
||||
* efficiently the algorithm will perform. This method differs
|
||||
* from the findCell methods in that only cells with labels are
|
||||
* queried - all numerical cells are ignored. This should therefore
|
||||
* improve performance.
|
||||
*
|
||||
* @param contents the string to match
|
||||
* @return the Cell whose contents match the paramter, null if not found
|
||||
*/
|
||||
public LabelCell findLabelCell(String contents) {
|
||||
LabelCell cell = null;
|
||||
boolean found = false;
|
||||
|
||||
for (int i = 0; i < sheet.getRows() && !found; i++) {
|
||||
Cell[] row = sheet.getRow(i);
|
||||
for (int j = 0; j < row.length && !found; j++) {
|
||||
if ((row[j].getType() == CellType.LABEL ||
|
||||
row[j].getType() == CellType.STRING_FORMULA) &&
|
||||
row[j].getContents().equals(contents)) {
|
||||
cell = (LabelCell) row[j];
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
}
|
313
datastructures-xslx/src/main/java/jxl/biff/CellReferenceHelper.java
Executable file
313
datastructures-xslx/src/main/java/jxl/biff/CellReferenceHelper.java
Executable file
|
@ -0,0 +1,313 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2002 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import jxl.biff.formula.ExternalSheet;
|
||||
import jxl.common.Logger;
|
||||
|
||||
/**
|
||||
* A helper to transform between excel cell references and
|
||||
* sheet:column:row notation
|
||||
* Because this function will be called when generating a string
|
||||
* representation of a formula, the cell reference will merely
|
||||
* be appened to the string buffer instead of returning a full
|
||||
* blooded string, for performance reasons
|
||||
*/
|
||||
public final class CellReferenceHelper {
|
||||
/**
|
||||
* The character which indicates whether a reference is fixed
|
||||
*/
|
||||
private static final char fixedInd = '$';
|
||||
/**
|
||||
* The character which indicates the sheet name terminator
|
||||
*/
|
||||
private static final char sheetInd = '!';
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(CellReferenceHelper.class);
|
||||
|
||||
/**
|
||||
* Constructor to prevent instantiation
|
||||
*/
|
||||
private CellReferenceHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell reference
|
||||
*
|
||||
* @param column
|
||||
* @param row
|
||||
* @param buf
|
||||
*/
|
||||
public static void getCellReference(int column, int row, StringBuffer buf) {
|
||||
// Put the column letter into the buffer
|
||||
getColumnReference(column, buf);
|
||||
|
||||
// Add the row into the buffer
|
||||
buf.append(row + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded method which prepends $ for absolute reference
|
||||
*
|
||||
* @param column
|
||||
* @param colabs TRUE if the column reference is absolute
|
||||
* @param row
|
||||
* @param rowabs TRUE if the row reference is absolute
|
||||
* @param buf
|
||||
*/
|
||||
public static void getCellReference(int column, boolean colabs,
|
||||
int row, boolean rowabs,
|
||||
StringBuffer buf) {
|
||||
if (colabs) {
|
||||
buf.append(fixedInd);
|
||||
}
|
||||
|
||||
// Put the column letter into the buffer
|
||||
getColumnReference(column, buf);
|
||||
|
||||
if (rowabs) {
|
||||
buf.append(fixedInd);
|
||||
}
|
||||
|
||||
// Add the row into the buffer
|
||||
buf.append(row + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the column letter corresponding to the 0-based column number
|
||||
*
|
||||
* @param column the column number
|
||||
* @return the letter for that column number
|
||||
*/
|
||||
public static String getColumnReference(int column) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
getColumnReference(column, buf);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the column letter corresponding to the 0-based column number
|
||||
*
|
||||
* @param column the column number
|
||||
* @param buf the string buffer in which to write the column letter
|
||||
*/
|
||||
public static void getColumnReference(int column, StringBuffer buf) {
|
||||
int v = column / 26;
|
||||
int r = column % 26;
|
||||
|
||||
StringBuffer tmp = new StringBuffer();
|
||||
while (v != 0) {
|
||||
char col = (char) ('A' + r);
|
||||
|
||||
tmp.append(col);
|
||||
|
||||
r = v % 26 - 1; // subtract one because only rows >26 preceded by A
|
||||
v = v / 26;
|
||||
}
|
||||
|
||||
char col = (char) ('A' + r);
|
||||
tmp.append(col);
|
||||
|
||||
// Insert into the proper string buffer in reverse order
|
||||
for (int i = tmp.length() - 1; i >= 0; i--) {
|
||||
buf.append(tmp.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully qualified cell reference given the column, row
|
||||
* external sheet reference etc
|
||||
*
|
||||
* @param sheet
|
||||
* @param column
|
||||
* @param row
|
||||
* @param workbook
|
||||
* @param buf
|
||||
*/
|
||||
public static void getCellReference
|
||||
(int sheet, int column, int row,
|
||||
ExternalSheet workbook, StringBuffer buf) {
|
||||
// Quotes are added by the WorkbookParser
|
||||
String name = workbook.getExternalSheetName(sheet);
|
||||
buf.append(StringHelper.replace(name, "'", "''"));
|
||||
buf.append(sheetInd);
|
||||
getCellReference(column, row, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully qualified cell reference given the column, row
|
||||
* external sheet reference etc
|
||||
*
|
||||
* @param sheet
|
||||
* @param column
|
||||
* @param colabs TRUE if the column is an absolute reference
|
||||
* @param row
|
||||
* @param rowabs TRUE if the row is an absolute reference
|
||||
* @param workbook
|
||||
* @param buf
|
||||
*/
|
||||
public static void getCellReference
|
||||
(int sheet, int column, boolean colabs,
|
||||
int row, boolean rowabs,
|
||||
ExternalSheet workbook, StringBuffer buf) {
|
||||
// WorkbookParser now appends quotes and escapes apostrophes
|
||||
String name = workbook.getExternalSheetName(sheet);
|
||||
buf.append(name);
|
||||
buf.append(sheetInd);
|
||||
getCellReference(column, colabs, row, rowabs, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully qualified cell reference given the column, row
|
||||
* external sheet reference etc
|
||||
*
|
||||
* @param sheet
|
||||
* @param column
|
||||
* @param row
|
||||
* @param workbook
|
||||
* @return the cell reference in the form 'Sheet 1'!A1
|
||||
*/
|
||||
public static String getCellReference
|
||||
(int sheet, int column, int row,
|
||||
ExternalSheet workbook) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
getCellReference(sheet, column, row, workbook, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the cell reference for the specified column and row
|
||||
*
|
||||
* @param column
|
||||
* @param row
|
||||
* @return
|
||||
*/
|
||||
public static String getCellReference(int column, int row) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
getCellReference(column, row, buf);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the columnn number of the string cell reference
|
||||
*
|
||||
* @param s the string to parse
|
||||
* @return the column portion of the cell reference
|
||||
*/
|
||||
public static int getColumn(String s) {
|
||||
int colnum = 0;
|
||||
int numindex = getNumberIndex(s);
|
||||
|
||||
String s2 = s.toUpperCase();
|
||||
|
||||
int startPos = s.lastIndexOf(sheetInd) + 1;
|
||||
if (s.charAt(startPos) == fixedInd) {
|
||||
startPos++;
|
||||
}
|
||||
|
||||
int endPos = numindex;
|
||||
if (s.charAt(numindex - 1) == fixedInd) {
|
||||
endPos--;
|
||||
}
|
||||
|
||||
for (int i = startPos; i < endPos; i++) {
|
||||
|
||||
if (i != startPos) {
|
||||
colnum = (colnum + 1) * 26;
|
||||
}
|
||||
colnum += (int) s2.charAt(i) - (int) 'A';
|
||||
}
|
||||
|
||||
return colnum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the row number of the cell reference
|
||||
*/
|
||||
public static int getRow(String s) {
|
||||
try {
|
||||
return (Integer.parseInt(s.substring(getNumberIndex(s))) - 1);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warn(e, e);
|
||||
return 0xffff;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the position where the first number occurs in the string
|
||||
*/
|
||||
private static int getNumberIndex(String s) {
|
||||
// Find the position of the first number
|
||||
boolean numberFound = false;
|
||||
int pos = s.lastIndexOf(sheetInd) + 1;
|
||||
char c = '\0';
|
||||
|
||||
while (!numberFound && pos < s.length()) {
|
||||
c = s.charAt(pos);
|
||||
|
||||
if (c >= '0' && c <= '9') {
|
||||
numberFound = true;
|
||||
} else {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sees if the column component is relative or not
|
||||
*
|
||||
* @param s
|
||||
* @return TRUE if the column is relative, FALSE otherwise
|
||||
*/
|
||||
public static boolean isColumnRelative(String s) {
|
||||
return s.charAt(0) != fixedInd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sees if the row component is relative or not
|
||||
*
|
||||
* @param s
|
||||
* @return TRUE if the row is relative, FALSE otherwise
|
||||
*/
|
||||
public static boolean isRowRelative(String s) {
|
||||
return s.charAt(getNumberIndex(s) - 1) != fixedInd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sheet name from the cell reference string
|
||||
*
|
||||
* @param ref
|
||||
* @return the sheet reference
|
||||
*/
|
||||
public static String getSheet(String ref) {
|
||||
int sheetPos = ref.lastIndexOf(sheetInd);
|
||||
if (sheetPos == -1) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return ref.substring(0, sheetPos);
|
||||
}
|
||||
|
||||
}
|
113
datastructures-xslx/src/main/java/jxl/biff/ConditionalFormat.java
Executable file
113
datastructures-xslx/src/main/java/jxl/biff/ConditionalFormat.java
Executable file
|
@ -0,0 +1,113 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2007 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import jxl.write.biff.File;
|
||||
|
||||
/**
|
||||
* Class containing the CONDFMT and CF records for conditionally formatting
|
||||
* a cell
|
||||
*/
|
||||
public class ConditionalFormat {
|
||||
/**
|
||||
* The range of the format
|
||||
*/
|
||||
private final ConditionalFormatRangeRecord range;
|
||||
|
||||
/**
|
||||
* The format conditions
|
||||
*/
|
||||
private final ArrayList conditions;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public ConditionalFormat(ConditionalFormatRangeRecord cfrr) {
|
||||
range = cfrr;
|
||||
conditions = new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a condition
|
||||
*
|
||||
* @param cond the condition
|
||||
*/
|
||||
public void addCondition(ConditionalFormatRecord cond) {
|
||||
conditions.add(cond);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a blank column into this spreadsheet. If the column is out of
|
||||
* range of the columns in the sheet, then no action is taken
|
||||
*
|
||||
* @param col the column to insert
|
||||
*/
|
||||
public void insertColumn(int col) {
|
||||
range.insertColumn(col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a column from this spreadsheet. If the column is out of range
|
||||
* of the columns in the sheet, then no action is taken
|
||||
*
|
||||
* @param col the column to remove
|
||||
*/
|
||||
public void removeColumn(int col) {
|
||||
range.removeColumn(col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a row from this spreadsheet. If the row is out of
|
||||
* range of the columns in the sheet, then no action is taken
|
||||
*
|
||||
* @param row the row to remove
|
||||
*/
|
||||
public void removeRow(int row) {
|
||||
range.removeRow(row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a blank row into this spreadsheet. If the row is out of range
|
||||
* of the rows in the sheet, then no action is taken
|
||||
*
|
||||
* @param row the row to insert
|
||||
*/
|
||||
public void insertRow(int row) {
|
||||
range.insertRow(row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes out the data validation
|
||||
*
|
||||
* @param outputFile the output file
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(File outputFile) throws IOException {
|
||||
outputFile.write(range);
|
||||
|
||||
for (Iterator i = conditions.iterator(); i.hasNext(); ) {
|
||||
ConditionalFormatRecord cfr = (ConditionalFormatRecord) i.next();
|
||||
outputFile.write(cfr);
|
||||
}
|
||||
}
|
||||
}
|
344
datastructures-xslx/src/main/java/jxl/biff/ConditionalFormatRangeRecord.java
Executable file
344
datastructures-xslx/src/main/java/jxl/biff/ConditionalFormatRangeRecord.java
Executable file
|
@ -0,0 +1,344 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2007 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import jxl.common.Logger;
|
||||
import jxl.read.biff.Record;
|
||||
|
||||
/**
|
||||
* Range information for conditional formatting
|
||||
*/
|
||||
public class ConditionalFormatRangeRecord extends WritableRecordData {
|
||||
// The logger
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(ConditionalFormatRangeRecord.class);
|
||||
|
||||
/**
|
||||
* The enclosing range
|
||||
*/
|
||||
private Range enclosingRange;
|
||||
|
||||
/**
|
||||
* The discrete ranges
|
||||
*/
|
||||
private Range[] ranges;
|
||||
|
||||
/**
|
||||
* The number of ranges
|
||||
*/
|
||||
private int numRanges;
|
||||
|
||||
/**
|
||||
* Initialized flag
|
||||
*/
|
||||
private boolean initialized;
|
||||
|
||||
/**
|
||||
* Modified flag
|
||||
*/
|
||||
private boolean modified;
|
||||
|
||||
/**
|
||||
* The data
|
||||
*/
|
||||
private final byte[] data;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public ConditionalFormatRangeRecord(Record t) {
|
||||
super(t);
|
||||
|
||||
initialized = false;
|
||||
modified = false;
|
||||
data = getRecord().getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization function
|
||||
*/
|
||||
private void initialize() {
|
||||
enclosingRange = new Range();
|
||||
enclosingRange.firstRow = IntegerHelper.getInt(data[4], data[5]);
|
||||
enclosingRange.lastRow = IntegerHelper.getInt(data[6], data[7]);
|
||||
enclosingRange.firstColumn = IntegerHelper.getInt(data[8], data[9]);
|
||||
enclosingRange.lastColumn = IntegerHelper.getInt(data[10], data[11]);
|
||||
numRanges = IntegerHelper.getInt(data[12], data[13]);
|
||||
ranges = new Range[numRanges];
|
||||
|
||||
int pos = 14;
|
||||
|
||||
for (int i = 0; i < numRanges; i++) {
|
||||
ranges[i] = new Range();
|
||||
ranges[i].firstRow = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
ranges[i].lastRow = IntegerHelper.getInt(data[pos + 2], data[pos + 3]);
|
||||
ranges[i].firstColumn = IntegerHelper.getInt(data[pos + 4], data[pos + 5]);
|
||||
ranges[i].lastColumn = IntegerHelper.getInt(data[pos + 6], data[pos + 7]);
|
||||
pos += 8;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a blank column into this spreadsheet. If the column is out of
|
||||
* range of the columns in the sheet, then no action is taken
|
||||
*
|
||||
* @param col the column to insert
|
||||
*/
|
||||
public void insertColumn(int col) {
|
||||
if (!initialized) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
enclosingRange.insertColumn(col);
|
||||
if (enclosingRange.modified) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
ranges[i].insertColumn(col);
|
||||
|
||||
if (ranges[i].modified) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a blank column into this spreadsheet. If the column is out of
|
||||
* range of the columns in the sheet, then no action is taken
|
||||
*
|
||||
* @param col the column to insert
|
||||
*/
|
||||
public void removeColumn(int col) {
|
||||
if (!initialized) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
enclosingRange.removeColumn(col);
|
||||
if (enclosingRange.modified) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
ranges[i].removeColumn(col);
|
||||
|
||||
if (ranges[i].modified) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a row from this spreadsheet. If the row is out of
|
||||
* range of the columns in the sheet, then no action is taken
|
||||
*
|
||||
* @param row the row to remove
|
||||
*/
|
||||
public void removeRow(int row) {
|
||||
if (!initialized) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
enclosingRange.removeRow(row);
|
||||
if (enclosingRange.modified) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
ranges[i].removeRow(row);
|
||||
|
||||
if (ranges[i].modified) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a blank row into this spreadsheet. If the row is out of range
|
||||
* of the rows in the sheet, then no action is taken
|
||||
*
|
||||
* @param row the row to insert
|
||||
*/
|
||||
public void insertRow(int row) {
|
||||
if (!initialized) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
enclosingRange.insertRow(row);
|
||||
if (enclosingRange.modified) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
ranges[i].insertRow(row);
|
||||
|
||||
if (ranges[i].modified) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the data for output to binary file
|
||||
*
|
||||
* @return the data to be written
|
||||
*/
|
||||
public byte[] getData() {
|
||||
if (!modified) {
|
||||
return data;
|
||||
}
|
||||
|
||||
byte[] d = new byte[14 + ranges.length * 8];
|
||||
|
||||
// Copy in the original information
|
||||
System.arraycopy(data, 0, d, 0, 4);
|
||||
|
||||
// Create the new range
|
||||
IntegerHelper.getTwoBytes(enclosingRange.firstRow, d, 4);
|
||||
IntegerHelper.getTwoBytes(enclosingRange.lastRow, d, 6);
|
||||
IntegerHelper.getTwoBytes(enclosingRange.firstColumn, d, 8);
|
||||
IntegerHelper.getTwoBytes(enclosingRange.lastColumn, d, 10);
|
||||
|
||||
IntegerHelper.getTwoBytes(numRanges, d, 12);
|
||||
|
||||
int pos = 14;
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
IntegerHelper.getTwoBytes(ranges[i].firstRow, d, pos);
|
||||
IntegerHelper.getTwoBytes(ranges[i].lastRow, d, pos + 2);
|
||||
IntegerHelper.getTwoBytes(ranges[i].firstColumn, d, pos + 4);
|
||||
IntegerHelper.getTwoBytes(ranges[i].lastColumn, d, pos + 6);
|
||||
pos += 8;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
private static class Range {
|
||||
public int firstRow;
|
||||
public int firstColumn;
|
||||
public int lastRow;
|
||||
public int lastColumn;
|
||||
public boolean modified;
|
||||
|
||||
public Range() {
|
||||
modified = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a blank column into this spreadsheet. If the column is out of
|
||||
* range of the columns in the sheet, then no action is taken
|
||||
*
|
||||
* @param col the column to insert
|
||||
*/
|
||||
public void insertColumn(int col) {
|
||||
if (col > lastColumn) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (col <= firstColumn) {
|
||||
firstColumn++;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (col <= lastColumn) {
|
||||
lastColumn++;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a column from this spreadsheet. If the column is out of range
|
||||
* of the columns in the sheet, then no action is taken
|
||||
*
|
||||
* @param col the column to remove
|
||||
*/
|
||||
public void removeColumn(int col) {
|
||||
if (col > lastColumn) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (col < firstColumn) {
|
||||
firstColumn--;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (col <= lastColumn) {
|
||||
lastColumn--;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a row from this spreadsheet. If the row is out of
|
||||
* range of the columns in the sheet, then no action is taken
|
||||
*
|
||||
* @param row the row to remove
|
||||
*/
|
||||
public void removeRow(int row) {
|
||||
if (row > lastRow) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (row < firstRow) {
|
||||
firstRow--;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (row <= lastRow) {
|
||||
lastRow--;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a blank row into this spreadsheet. If the row is out of range
|
||||
* of the rows in the sheet, then no action is taken
|
||||
*
|
||||
* @param row the row to insert
|
||||
*/
|
||||
public void insertRow(int row) {
|
||||
if (row > lastRow) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (row <= firstRow) {
|
||||
firstRow++;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (row <= lastRow) {
|
||||
lastRow++;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
56
datastructures-xslx/src/main/java/jxl/biff/ConditionalFormatRecord.java
Executable file
56
datastructures-xslx/src/main/java/jxl/biff/ConditionalFormatRecord.java
Executable file
|
@ -0,0 +1,56 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2007 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import jxl.common.Logger;
|
||||
import jxl.read.biff.Record;
|
||||
|
||||
/**
|
||||
* The conditional format conditions
|
||||
*/
|
||||
public class ConditionalFormatRecord extends WritableRecordData {
|
||||
// the logger
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(ConditionalFormatRecord.class);
|
||||
|
||||
/**
|
||||
* The data
|
||||
*/
|
||||
private final byte[] data;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public ConditionalFormatRecord(Record t) {
|
||||
super(t);
|
||||
|
||||
data = getRecord().getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the data for output to binary file
|
||||
*
|
||||
* @return the data to be written
|
||||
*/
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
74
datastructures-xslx/src/main/java/jxl/biff/ContinueRecord.java
Executable file
74
datastructures-xslx/src/main/java/jxl/biff/ContinueRecord.java
Executable file
|
@ -0,0 +1,74 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2004 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import jxl.read.biff.Record;
|
||||
|
||||
/**
|
||||
* A continue record - only used explicitly in special circumstances, as
|
||||
* the general continuation record is handled directly by the records
|
||||
*/
|
||||
public class ContinueRecord extends WritableRecordData {
|
||||
/**
|
||||
* The data
|
||||
*/
|
||||
private final byte[] data;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param t the raw bytes
|
||||
*/
|
||||
public ContinueRecord(Record t) {
|
||||
super(t);
|
||||
data = t.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor invoked when creating continue records
|
||||
*
|
||||
* @param d the data
|
||||
*/
|
||||
public ContinueRecord(byte[] d) {
|
||||
super(Type.CONTINUE);
|
||||
data = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the binary data - used when copying
|
||||
*
|
||||
* @return the binary data
|
||||
*/
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the record. Used when forcibly changing this record
|
||||
* into another type, notably a drawing record, as sometimes Excel appears
|
||||
* to switch to writing Continue records instead of MsoDrawing records
|
||||
*
|
||||
* @return the record
|
||||
*/
|
||||
public Record getRecord() {
|
||||
return super.getRecord();
|
||||
}
|
||||
|
||||
}
|
150
datastructures-xslx/src/main/java/jxl/biff/CountryCode.java
Executable file
150
datastructures-xslx/src/main/java/jxl/biff/CountryCode.java
Executable file
|
@ -0,0 +1,150 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2005 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import jxl.common.Logger;
|
||||
|
||||
/**
|
||||
* Enumeration type for the excel country codes
|
||||
*/
|
||||
public class CountryCode {
|
||||
// The country codes
|
||||
public final static CountryCode USA = new CountryCode(0x1, "US", "USA");
|
||||
public final static CountryCode CANADA =
|
||||
new CountryCode(0x2, "CA", "Canada");
|
||||
public final static CountryCode GREECE =
|
||||
new CountryCode(0x1e, "GR", "Greece");
|
||||
public final static CountryCode NETHERLANDS =
|
||||
new CountryCode(0x1f, "NE", "Netherlands");
|
||||
public final static CountryCode BELGIUM =
|
||||
new CountryCode(0x20, "BE", "Belgium");
|
||||
public final static CountryCode FRANCE =
|
||||
new CountryCode(0x21, "FR", "France");
|
||||
public final static CountryCode SPAIN = new CountryCode(0x22, "ES", "Spain");
|
||||
public final static CountryCode ITALY = new CountryCode(0x27, "IT", "Italy");
|
||||
public final static CountryCode SWITZERLAND =
|
||||
new CountryCode(0x29, "CH", "Switzerland");
|
||||
public final static CountryCode UK =
|
||||
new CountryCode(0x2c, "UK", "United Kingdowm");
|
||||
public final static CountryCode DENMARK =
|
||||
new CountryCode(0x2d, "DK", "Denmark");
|
||||
public final static CountryCode SWEDEN =
|
||||
new CountryCode(0x2e, "SE", "Sweden");
|
||||
public final static CountryCode NORWAY =
|
||||
new CountryCode(0x2f, "NO", "Norway");
|
||||
public final static CountryCode GERMANY =
|
||||
new CountryCode(0x31, "DE", "Germany");
|
||||
public final static CountryCode PHILIPPINES =
|
||||
new CountryCode(0x3f, "PH", "Philippines");
|
||||
public final static CountryCode CHINA =
|
||||
new CountryCode(0x56, "CN", "China");
|
||||
public final static CountryCode INDIA =
|
||||
new CountryCode(0x5b, "IN", "India");
|
||||
public final static CountryCode UNKNOWN =
|
||||
new CountryCode(0xffff, "??", "Unknown");
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(CountryCode.class);
|
||||
/**
|
||||
* The array of country codes
|
||||
*/
|
||||
private static CountryCode[] codes = new CountryCode[0];
|
||||
/**
|
||||
* The country code
|
||||
*/
|
||||
private final int value;
|
||||
/**
|
||||
* The ISO 3166 two letter country mnemonic (as used by the Locale class)
|
||||
*/
|
||||
private final String code;
|
||||
/**
|
||||
* The long description
|
||||
*/
|
||||
private final String description;
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
private CountryCode(int v, String c, String d) {
|
||||
value = v;
|
||||
code = c;
|
||||
description = d;
|
||||
|
||||
CountryCode[] newcodes = new CountryCode[codes.length + 1];
|
||||
System.arraycopy(codes, 0, newcodes, 0, codes.length);
|
||||
newcodes[codes.length] = this;
|
||||
codes = newcodes;
|
||||
}
|
||||
/**
|
||||
* Constructor used to create an arbitrary code with a specified value.
|
||||
* Doesn't add the latest value to the static array
|
||||
*/
|
||||
private CountryCode(int v) {
|
||||
value = v;
|
||||
description = "Arbitrary";
|
||||
code = "??";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the country code for the given two character mnemonic string
|
||||
*/
|
||||
public static CountryCode getCountryCode(String s) {
|
||||
if (s == null || s.length() != 2) {
|
||||
logger.warn("Please specify two character ISO 3166 country code");
|
||||
return USA;
|
||||
}
|
||||
|
||||
CountryCode code = UNKNOWN;
|
||||
for (int i = 0; i < codes.length && code == UNKNOWN; i++) {
|
||||
if (codes[i].code.equals(s)) {
|
||||
code = codes[i];
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an arbitrary country code with the specified value. Used
|
||||
* when copying sheets, and the country code isn't initialized as part
|
||||
* of the static data below
|
||||
*/
|
||||
public static CountryCode createArbitraryCode(int i) {
|
||||
return new CountryCode(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the excel value
|
||||
*
|
||||
* @return the excel value
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for the string
|
||||
*
|
||||
* @return the two character iso 3166 string
|
||||
*/
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
906
datastructures-xslx/src/main/java/jxl/biff/DVParser.java
Executable file
906
datastructures-xslx/src/main/java/jxl/biff/DVParser.java
Executable file
|
@ -0,0 +1,906 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Copyright (C) 2004 Andrew Khan
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
package jxl.biff;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import jxl.WorkbookSettings;
|
||||
import jxl.biff.formula.ExternalSheet;
|
||||
import jxl.biff.formula.FormulaException;
|
||||
import jxl.biff.formula.FormulaParser;
|
||||
import jxl.biff.formula.ParseContext;
|
||||
import jxl.common.Assert;
|
||||
import jxl.common.Logger;
|
||||
|
||||
/**
|
||||
* Class which parses the binary data associated with Data Validity (DV)
|
||||
* setting
|
||||
*/
|
||||
public class DVParser {
|
||||
// The values
|
||||
public static final DVType ANY = new DVType(0, "any");
|
||||
public static final DVType INTEGER = new DVType(1, "int");
|
||||
public static final DVType DECIMAL = new DVType(2, "dec");
|
||||
public static final DVType LIST = new DVType(3, "list");
|
||||
public static final DVType DATE = new DVType(4, "date");
|
||||
public static final DVType TIME = new DVType(5, "time");
|
||||
public static final DVType TEXT_LENGTH = new DVType(6, "strlen");
|
||||
public static final DVType FORMULA = new DVType(7, "form");
|
||||
// The error styles
|
||||
public static final ErrorStyle STOP = new ErrorStyle(0);
|
||||
public static final ErrorStyle WARNING = new ErrorStyle(1);
|
||||
public static final ErrorStyle INFO = new ErrorStyle(2);
|
||||
// The conditions
|
||||
public static final Condition BETWEEN = new Condition(0, "{0} <= x <= {1}");
|
||||
public static final Condition NOT_BETWEEN =
|
||||
new Condition(1, "!({0} <= x <= {1}");
|
||||
public static final Condition EQUAL = new Condition(2, "x == {0}");
|
||||
public static final Condition NOT_EQUAL = new Condition(3, "x != {0}");
|
||||
public static final Condition GREATER_THAN = new Condition(4, "x > {0}");
|
||||
public static final Condition LESS_THAN = new Condition(5, "x < {0}");
|
||||
public static final Condition GREATER_EQUAL = new Condition(6, "x >= {0}");
|
||||
public static final Condition LESS_EQUAL = new Condition(7, "x <= {0}");
|
||||
// The masks
|
||||
private static final int STRING_LIST_GIVEN_MASK = 0x80;
|
||||
private static final int EMPTY_CELLS_ALLOWED_MASK = 0x100;
|
||||
private static final int SUPPRESS_ARROW_MASK = 0x200;
|
||||
private static final int SHOW_PROMPT_MASK = 0x40000;
|
||||
private static final int SHOW_ERROR_MASK = 0x80000;
|
||||
// The maximum string length for a data validation list
|
||||
private static final int MAX_VALIDATION_LIST_LENGTH = 254;
|
||||
// The maximum number of rows and columns
|
||||
private static final int MAX_ROWS = 0xffff;
|
||||
private static final int MAX_COLUMNS = 0xff;
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(DVParser.class);
|
||||
// The decimal format
|
||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.#");
|
||||
/**
|
||||
* The type
|
||||
*/
|
||||
private final DVType type;
|
||||
/**
|
||||
* The error style
|
||||
*/
|
||||
private final ErrorStyle errorStyle;
|
||||
/**
|
||||
* The condition
|
||||
*/
|
||||
private final Condition condition;
|
||||
/**
|
||||
* String list option
|
||||
*/
|
||||
private final boolean stringListGiven;
|
||||
/**
|
||||
* Empty cells allowed
|
||||
*/
|
||||
private final boolean emptyCellsAllowed;
|
||||
/**
|
||||
* Suppress arrow
|
||||
*/
|
||||
private final boolean suppressArrow;
|
||||
/**
|
||||
* Show prompt
|
||||
*/
|
||||
private final boolean showPrompt;
|
||||
/**
|
||||
* Show error
|
||||
*/
|
||||
private final boolean showError;
|
||||
/**
|
||||
* The title of the prompt box
|
||||
*/
|
||||
private String promptTitle;
|
||||
/**
|
||||
* The title of the error box
|
||||
*/
|
||||
private String errorTitle;
|
||||
/**
|
||||
* The text of the prompt box
|
||||
*/
|
||||
private String promptText;
|
||||
/**
|
||||
* The text of the error box
|
||||
*/
|
||||
private String errorText;
|
||||
/**
|
||||
* The first formula
|
||||
*/
|
||||
private FormulaParser formula1;
|
||||
/**
|
||||
* The first formula string
|
||||
*/
|
||||
private String formula1String;
|
||||
/**
|
||||
* The second formula
|
||||
*/
|
||||
private FormulaParser formula2;
|
||||
/**
|
||||
* The second formula string
|
||||
*/
|
||||
private String formula2String;
|
||||
/**
|
||||
* The column number of the cell at the top left of the range
|
||||
*/
|
||||
private int column1;
|
||||
/**
|
||||
* The row number of the cell at the top left of the range
|
||||
*/
|
||||
private int row1;
|
||||
/**
|
||||
* The column index of the cell at the bottom right
|
||||
*/
|
||||
private int column2;
|
||||
/**
|
||||
* The row index of the cell at the bottom right
|
||||
*/
|
||||
private int row2;
|
||||
/**
|
||||
* Flag to indicate that this DV Parser is shared amongst a group
|
||||
* of cells
|
||||
*/
|
||||
private boolean extendedCellsValidation;
|
||||
/**
|
||||
* Flag indicated whether this has been copied
|
||||
*/
|
||||
private final boolean copied;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public DVParser(byte[] data,
|
||||
ExternalSheet es,
|
||||
WorkbookMethods nt,
|
||||
WorkbookSettings ws) {
|
||||
Assert.verify(nt != null);
|
||||
|
||||
copied = false;
|
||||
int options = IntegerHelper.getInt(data[0], data[1], data[2], data[3]);
|
||||
|
||||
int typeVal = options & 0xf;
|
||||
type = DVType.getType(typeVal);
|
||||
|
||||
int errorStyleVal = (options & 0x70) >> 4;
|
||||
errorStyle = ErrorStyle.getErrorStyle(errorStyleVal);
|
||||
|
||||
int conditionVal = (options & 0xf00000) >> 20;
|
||||
condition = Condition.getCondition(conditionVal);
|
||||
|
||||
stringListGiven = (options & STRING_LIST_GIVEN_MASK) != 0;
|
||||
emptyCellsAllowed = (options & EMPTY_CELLS_ALLOWED_MASK) != 0;
|
||||
suppressArrow = (options & SUPPRESS_ARROW_MASK) != 0;
|
||||
showPrompt = (options & SHOW_PROMPT_MASK) != 0;
|
||||
showError = (options & SHOW_ERROR_MASK) != 0;
|
||||
|
||||
int pos = 4;
|
||||
int length = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
if (length > 0 && data[pos + 2] == 0) {
|
||||
promptTitle = StringHelper.getString(data, length, pos + 3, ws);
|
||||
pos += length + 3;
|
||||
} else if (length > 0) {
|
||||
promptTitle = StringHelper.getUnicodeString(data, length, pos + 3);
|
||||
pos += length * 2 + 3;
|
||||
} else {
|
||||
pos += 3;
|
||||
}
|
||||
|
||||
length = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
if (length > 0 && data[pos + 2] == 0) {
|
||||
errorTitle = StringHelper.getString(data, length, pos + 3, ws);
|
||||
pos += length + 3;
|
||||
} else if (length > 0) {
|
||||
errorTitle = StringHelper.getUnicodeString(data, length, pos + 3);
|
||||
pos += length * 2 + 3;
|
||||
} else {
|
||||
pos += 3;
|
||||
}
|
||||
|
||||
length = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
if (length > 0 && data[pos + 2] == 0) {
|
||||
promptText = StringHelper.getString(data, length, pos + 3, ws);
|
||||
pos += length + 3;
|
||||
} else if (length > 0) {
|
||||
promptText = StringHelper.getUnicodeString(data, length, pos + 3);
|
||||
pos += length * 2 + 3;
|
||||
} else {
|
||||
pos += 3;
|
||||
}
|
||||
|
||||
length = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
if (length > 0 && data[pos + 2] == 0) {
|
||||
errorText = StringHelper.getString(data, length, pos + 3, ws);
|
||||
pos += length + 3;
|
||||
} else if (length > 0) {
|
||||
errorText = StringHelper.getUnicodeString(data, length, pos + 3);
|
||||
pos += length * 2 + 3;
|
||||
} else {
|
||||
pos += 3;
|
||||
}
|
||||
|
||||
int formula1Length = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
pos += 4;
|
||||
int formula1Pos = pos;
|
||||
pos += formula1Length;
|
||||
|
||||
int formula2Length = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
pos += 4;
|
||||
int formula2Pos = pos;
|
||||
pos += formula2Length;
|
||||
|
||||
pos += 2;
|
||||
|
||||
row1 = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
pos += 2;
|
||||
|
||||
row2 = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
pos += 2;
|
||||
|
||||
column1 = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
pos += 2;
|
||||
|
||||
column2 = IntegerHelper.getInt(data[pos], data[pos + 1]);
|
||||
pos += 2;
|
||||
|
||||
extendedCellsValidation = row1 != row2 || column1 != column2;
|
||||
|
||||
// Do the formulas
|
||||
try {
|
||||
// First, create a temporary blank cell for any formula relative
|
||||
// references
|
||||
EmptyCell tmprt = new EmptyCell(column1, row1);
|
||||
|
||||
if (formula1Length != 0) {
|
||||
byte[] tokens = new byte[formula1Length];
|
||||
System.arraycopy(data, formula1Pos, tokens, 0, formula1Length);
|
||||
formula1 = new FormulaParser(tokens, tmprt, es, nt, ws,
|
||||
ParseContext.DATA_VALIDATION);
|
||||
formula1.parse();
|
||||
}
|
||||
|
||||
if (formula2Length != 0) {
|
||||
byte[] tokens = new byte[formula2Length];
|
||||
System.arraycopy(data, formula2Pos, tokens, 0, formula2Length);
|
||||
formula2 = new FormulaParser(tokens, tmprt, es, nt, ws,
|
||||
ParseContext.DATA_VALIDATION);
|
||||
formula2.parse();
|
||||
}
|
||||
} catch (FormulaException e) {
|
||||
logger.warn(e.getMessage() + " for cells " +
|
||||
CellReferenceHelper.getCellReference(column1, row1) + "-" +
|
||||
CellReferenceHelper.getCellReference(column2, row2));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor called when creating a data validation from the API
|
||||
*/
|
||||
public DVParser(Collection strings) {
|
||||
copied = false;
|
||||
type = LIST;
|
||||
errorStyle = STOP;
|
||||
condition = BETWEEN;
|
||||
extendedCellsValidation = false;
|
||||
|
||||
// the options
|
||||
stringListGiven = true;
|
||||
emptyCellsAllowed = true;
|
||||
suppressArrow = false;
|
||||
showPrompt = true;
|
||||
showError = true;
|
||||
|
||||
promptTitle = "\0";
|
||||
errorTitle = "\0";
|
||||
promptText = "\0";
|
||||
errorText = "\0";
|
||||
if (strings.size() == 0) {
|
||||
logger.warn("no validation strings - ignoring");
|
||||
}
|
||||
|
||||
Iterator i = strings.iterator();
|
||||
StringBuffer formulaString = new StringBuffer();
|
||||
|
||||
formulaString.append(i.next().toString());
|
||||
while (i.hasNext()) {
|
||||
formulaString.append('\0');
|
||||
formulaString.append(' ');
|
||||
formulaString.append(i.next().toString());
|
||||
}
|
||||
|
||||
// If the formula string exceeds
|
||||
// the maximum validation list length, then truncate and stop there
|
||||
if (formulaString.length() > MAX_VALIDATION_LIST_LENGTH) {
|
||||
logger.warn("Validation list exceeds maximum number of characters - " +
|
||||
"truncating");
|
||||
formulaString.delete(MAX_VALIDATION_LIST_LENGTH,
|
||||
formulaString.length());
|
||||
}
|
||||
|
||||
// Put the string in quotes
|
||||
formulaString.insert(0, '\"');
|
||||
formulaString.append('\"');
|
||||
formula1String = formulaString.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor called when creating a data validation from the API
|
||||
*/
|
||||
public DVParser(String namedRange) {
|
||||
// Handle the case for an empty string
|
||||
if (namedRange.length() == 0) {
|
||||
copied = false;
|
||||
type = FORMULA;
|
||||
errorStyle = STOP;
|
||||
condition = EQUAL;
|
||||
extendedCellsValidation = false;
|
||||
// the options
|
||||
stringListGiven = false;
|
||||
emptyCellsAllowed = false;
|
||||
suppressArrow = false;
|
||||
showPrompt = true;
|
||||
showError = true;
|
||||
|
||||
promptTitle = "\0";
|
||||
errorTitle = "\0";
|
||||
promptText = "\0";
|
||||
errorText = "\0";
|
||||
formula1String = "\"\"";
|
||||
return;
|
||||
}
|
||||
|
||||
copied = false;
|
||||
type = LIST;
|
||||
errorStyle = STOP;
|
||||
condition = BETWEEN;
|
||||
extendedCellsValidation = false;
|
||||
|
||||
// the options
|
||||
stringListGiven = false;
|
||||
emptyCellsAllowed = true;
|
||||
suppressArrow = false;
|
||||
showPrompt = true;
|
||||
showError = true;
|
||||
|
||||
promptTitle = "\0";
|
||||
errorTitle = "\0";
|
||||
promptText = "\ |