diff --git a/src/java/org/apache/poi/ddf/EscherPictBlip.java b/src/java/org/apache/poi/ddf/EscherPictBlip.java
index 5920d97b9..8ab6d8c5c 100644
--- a/src/java/org/apache/poi/ddf/EscherPictBlip.java
+++ b/src/java/org/apache/poi/ddf/EscherPictBlip.java
@@ -1,276 +1,276 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.apache.poi.ddf;
-
-import org.apache.poi.util.HexDump;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
-
-import java.awt.Dimension;
-import java.awt.Rectangle;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.zip.InflaterInputStream;
-
-/**
- * @author Daniel Noll
- * @version $Id$
- */
-public class EscherPictBlip
- extends EscherBlipRecord
-{
- private static final POILogger log = POILogFactory.getLogger(EscherPictBlip.class);
-
- public static final short RECORD_ID_EMF = (short) 0xF018 + 2;
- public static final short RECORD_ID_WMF = (short) 0xF018 + 3;
- public static final short RECORD_ID_PICT = (short) 0xF018 + 4;
-
- private static final int HEADER_SIZE = 8;
-
- private byte[] field_1_UID;
- private int field_2_cb;
- private int field_3_rcBounds_x1;
- private int field_3_rcBounds_y1;
- private int field_3_rcBounds_x2;
- private int field_3_rcBounds_y2;
- private int field_4_ptSize_w;
- private int field_4_ptSize_h;
- private int field_5_cbSave;
- private byte field_6_fCompression;
- private byte field_7_fFilter;
-
- private byte[] raw_pictureData;
-
- /**
- * This method deserializes the record from a byte array.
- *
- * @param data The byte array containing the escher record information
- * @param offset The starting offset into data
.
- * @param recordFactory May be null since this is not a container record.
- * @return The number of bytes read from the byte array.
- */
- public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory )
- {
- int bytesAfterHeader = readHeader( data, offset );
- int pos = offset + HEADER_SIZE;
-
- field_1_UID = new byte[16];
- System.arraycopy( data, pos, field_1_UID, 0, 16 ); pos += 16;
- field_2_cb = LittleEndian.getInt( data, pos ); pos += 4;
- field_3_rcBounds_x1 = LittleEndian.getInt( data, pos ); pos += 4;
- field_3_rcBounds_y1 = LittleEndian.getInt( data, pos ); pos += 4;
- field_3_rcBounds_x2 = LittleEndian.getInt( data, pos ); pos += 4;
- field_3_rcBounds_y2 = LittleEndian.getInt( data, pos ); pos += 4;
- field_4_ptSize_w = LittleEndian.getInt( data, pos ); pos += 4;
- field_4_ptSize_h = LittleEndian.getInt( data, pos ); pos += 4;
- field_5_cbSave = LittleEndian.getInt( data, pos ); pos += 4;
- field_6_fCompression = data[pos]; pos++;
- field_7_fFilter = data[pos]; pos++;
-
- raw_pictureData = new byte[field_5_cbSave];
- System.arraycopy( data, pos, raw_pictureData, 0, field_5_cbSave );
-
- // 0 means DEFLATE compression
- // 0xFE means no compression
- if (field_6_fCompression == 0)
- {
- field_pictureData = inflatePictureData(raw_pictureData);
- }
- else
- {
- field_pictureData = raw_pictureData;
- }
-
- return bytesAfterHeader + HEADER_SIZE;
- }
-
- /**
- * Serializes the record to an existing byte array.
- *
- * @param offset the offset within the byte array
- * @param data the data array to serialize to
- * @param listener a listener for begin and end serialization events. This
- * is useful because the serialization is
- * hierarchical/recursive and sometimes you need to be able
- * break into that.
- * @return the number of bytes written.
- */
- public int serialize( int offset, byte[] data, EscherSerializationListener listener )
- {
- listener.beforeRecordSerialize(offset, getRecordId(), this);
-
- int pos = offset;
- LittleEndian.putShort( data, pos, getOptions() ); pos += 2;
- LittleEndian.putShort( data, pos, getRecordId() ); pos += 2;
- LittleEndian.putInt( data, getRecordSize() - HEADER_SIZE ); pos += 4;
-
- System.arraycopy( field_1_UID, 0, data, pos, 16 ); pos += 16;
- LittleEndian.putInt( data, pos, field_2_cb ); pos += 4;
- LittleEndian.putInt( data, pos, field_3_rcBounds_x1 ); pos += 4;
- LittleEndian.putInt( data, pos, field_3_rcBounds_y1 ); pos += 4;
- LittleEndian.putInt( data, pos, field_3_rcBounds_x2 ); pos += 4;
- LittleEndian.putInt( data, pos, field_3_rcBounds_y2 ); pos += 4;
- LittleEndian.putInt( data, pos, field_4_ptSize_w ); pos += 4;
- LittleEndian.putInt( data, pos, field_4_ptSize_h ); pos += 4;
- LittleEndian.putInt( data, pos, field_5_cbSave ); pos += 4;
- data[pos] = field_6_fCompression; pos++;
- data[pos] = field_7_fFilter; pos++;
-
- System.arraycopy( raw_pictureData, 0, data, pos, raw_pictureData.length );
-
- listener.afterRecordSerialize(offset + getRecordSize(), getRecordId(), getRecordSize(), this);
- return HEADER_SIZE + 16 + 1 + raw_pictureData.length;
- }
-
- /**
- * Decompresses the provided data, returning the inflated result.
- *
- * @param data the deflated picture data.
- * @return the inflated picture data.
- */
- private static byte[] inflatePictureData(byte[] data)
- {
- try
- {
- InflaterInputStream in = new InflaterInputStream(
- new ByteArrayInputStream( data ) );
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] buf = new byte[4096];
- int readBytes;
- while ((readBytes = in.read(buf)) > 0)
- {
- out.write(buf, 0, readBytes);
- }
- return out.toByteArray();
- }
- catch ( IOException e )
- {
- log.log(POILogger.INFO, "Possibly corrupt compression or non-compressed data", e);
- return data;
- }
- }
-
- /**
- * Returns the number of bytes that are required to serialize this record.
- *
- * @return Number of bytes
- */
- public int getRecordSize()
- {
- return 8 + 50 + raw_pictureData.length;
- }
-
- public byte[] getUID()
- {
- return field_1_UID;
- }
-
- public void setUID( byte[] field_1_UID )
- {
- this.field_1_UID = field_1_UID;
- }
-
- public int getUncompressedSize()
- {
- return field_2_cb;
- }
-
- public void setUncompressedSize(int uncompressedSize)
- {
- field_2_cb = uncompressedSize;
- }
-
- public Rectangle getBounds()
- {
- return new Rectangle(field_3_rcBounds_x1,
- field_3_rcBounds_y1,
- field_3_rcBounds_x2 - field_3_rcBounds_x1,
- field_3_rcBounds_y2 - field_3_rcBounds_y1);
- }
-
- public void setBounds(Rectangle bounds)
- {
- field_3_rcBounds_x1 = bounds.x;
- field_3_rcBounds_y1 = bounds.y;
- field_3_rcBounds_x2 = bounds.x + bounds.width;
- field_3_rcBounds_y2 = bounds.y + bounds.height;
- }
-
- public Dimension getSizeEMU()
- {
- return new Dimension(field_4_ptSize_w, field_4_ptSize_h);
- }
-
- public void setSizeEMU(Dimension sizeEMU)
- {
- field_4_ptSize_w = sizeEMU.width;
- field_4_ptSize_h = sizeEMU.height;
- }
-
- public int getCompressedSize()
- {
- return field_5_cbSave;
- }
-
- public void setCompressedSize(int compressedSize)
- {
- field_5_cbSave = compressedSize;
- }
-
- public boolean isCompressed()
- {
- return (field_6_fCompression == 0);
- }
-
- public void setCompressed(boolean compressed)
- {
- field_6_fCompression = compressed ? 0 : (byte)0xFE;
- }
-
- // filtering is always 254 according to available docs, so no point giving it a setter method.
-
- public String toString()
- {
- String nl = System.getProperty( "line.separator" );
-
- String extraData;
- ByteArrayOutputStream b = new ByteArrayOutputStream();
- try
- {
- HexDump.dump( this.field_pictureData, 0, b, 0 );
- extraData = b.toString();
- }
- catch ( Exception e )
- {
- extraData = e.toString();
- }
- return getClass().getName() + ":" + nl +
- " RecordId: 0x" + HexDump.toHex( getRecordId() ) + nl +
- " Options: 0x" + HexDump.toHex( getOptions() ) + nl +
- " UID: 0x" + HexDump.toHex( field_1_UID ) + nl +
- " Uncompressed Size: " + HexDump.toHex( field_2_cb ) + nl +
- " Bounds: " + getBounds() + nl +
- " Size in EMU: " + getSizeEMU() + nl +
- " Compressed Size: " + HexDump.toHex( field_5_cbSave ) + nl +
- " Compression: " + HexDump.toHex( field_6_fCompression ) + nl +
- " Filter: " + HexDump.toHex( field_7_fFilter ) + nl +
- " Extra Data:" + nl + extraData;
- }
-
-}
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.poi.ddf;
+
+import org.apache.poi.util.HexDump;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
+import java.awt.Dimension;
+import java.awt.Rectangle;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.InflaterInputStream;
+
+/**
+ * @author Daniel Noll
+ * @version $Id$
+ */
+public class EscherPictBlip
+ extends EscherBlipRecord
+{
+ private static final POILogger log = POILogFactory.getLogger(EscherPictBlip.class);
+
+ public static final short RECORD_ID_EMF = (short) 0xF018 + 2;
+ public static final short RECORD_ID_WMF = (short) 0xF018 + 3;
+ public static final short RECORD_ID_PICT = (short) 0xF018 + 4;
+
+ private static final int HEADER_SIZE = 8;
+
+ private byte[] field_1_UID;
+ private int field_2_cb;
+ private int field_3_rcBounds_x1;
+ private int field_3_rcBounds_y1;
+ private int field_3_rcBounds_x2;
+ private int field_3_rcBounds_y2;
+ private int field_4_ptSize_w;
+ private int field_4_ptSize_h;
+ private int field_5_cbSave;
+ private byte field_6_fCompression;
+ private byte field_7_fFilter;
+
+ private byte[] raw_pictureData;
+
+ /**
+ * This method deserializes the record from a byte array.
+ *
+ * @param data The byte array containing the escher record information
+ * @param offset The starting offset into data
.
+ * @param recordFactory May be null since this is not a container record.
+ * @return The number of bytes read from the byte array.
+ */
+ public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory )
+ {
+ int bytesAfterHeader = readHeader( data, offset );
+ int pos = offset + HEADER_SIZE;
+
+ field_1_UID = new byte[16];
+ System.arraycopy( data, pos, field_1_UID, 0, 16 ); pos += 16;
+ field_2_cb = LittleEndian.getInt( data, pos ); pos += 4;
+ field_3_rcBounds_x1 = LittleEndian.getInt( data, pos ); pos += 4;
+ field_3_rcBounds_y1 = LittleEndian.getInt( data, pos ); pos += 4;
+ field_3_rcBounds_x2 = LittleEndian.getInt( data, pos ); pos += 4;
+ field_3_rcBounds_y2 = LittleEndian.getInt( data, pos ); pos += 4;
+ field_4_ptSize_w = LittleEndian.getInt( data, pos ); pos += 4;
+ field_4_ptSize_h = LittleEndian.getInt( data, pos ); pos += 4;
+ field_5_cbSave = LittleEndian.getInt( data, pos ); pos += 4;
+ field_6_fCompression = data[pos]; pos++;
+ field_7_fFilter = data[pos]; pos++;
+
+ raw_pictureData = new byte[field_5_cbSave];
+ System.arraycopy( data, pos, raw_pictureData, 0, field_5_cbSave );
+
+ // 0 means DEFLATE compression
+ // 0xFE means no compression
+ if (field_6_fCompression == 0)
+ {
+ field_pictureData = inflatePictureData(raw_pictureData);
+ }
+ else
+ {
+ field_pictureData = raw_pictureData;
+ }
+
+ return bytesAfterHeader + HEADER_SIZE;
+ }
+
+ /**
+ * Serializes the record to an existing byte array.
+ *
+ * @param offset the offset within the byte array
+ * @param data the data array to serialize to
+ * @param listener a listener for begin and end serialization events. This
+ * is useful because the serialization is
+ * hierarchical/recursive and sometimes you need to be able
+ * break into that.
+ * @return the number of bytes written.
+ */
+ public int serialize( int offset, byte[] data, EscherSerializationListener listener )
+ {
+ listener.beforeRecordSerialize(offset, getRecordId(), this);
+
+ int pos = offset;
+ LittleEndian.putShort( data, pos, getOptions() ); pos += 2;
+ LittleEndian.putShort( data, pos, getRecordId() ); pos += 2;
+ LittleEndian.putInt( data, getRecordSize() - HEADER_SIZE ); pos += 4;
+
+ System.arraycopy( field_1_UID, 0, data, pos, 16 ); pos += 16;
+ LittleEndian.putInt( data, pos, field_2_cb ); pos += 4;
+ LittleEndian.putInt( data, pos, field_3_rcBounds_x1 ); pos += 4;
+ LittleEndian.putInt( data, pos, field_3_rcBounds_y1 ); pos += 4;
+ LittleEndian.putInt( data, pos, field_3_rcBounds_x2 ); pos += 4;
+ LittleEndian.putInt( data, pos, field_3_rcBounds_y2 ); pos += 4;
+ LittleEndian.putInt( data, pos, field_4_ptSize_w ); pos += 4;
+ LittleEndian.putInt( data, pos, field_4_ptSize_h ); pos += 4;
+ LittleEndian.putInt( data, pos, field_5_cbSave ); pos += 4;
+ data[pos] = field_6_fCompression; pos++;
+ data[pos] = field_7_fFilter; pos++;
+
+ System.arraycopy( raw_pictureData, 0, data, pos, raw_pictureData.length );
+
+ listener.afterRecordSerialize(offset + getRecordSize(), getRecordId(), getRecordSize(), this);
+ return HEADER_SIZE + 16 + 1 + raw_pictureData.length;
+ }
+
+ /**
+ * Decompresses the provided data, returning the inflated result.
+ *
+ * @param data the deflated picture data.
+ * @return the inflated picture data.
+ */
+ private static byte[] inflatePictureData(byte[] data)
+ {
+ try
+ {
+ InflaterInputStream in = new InflaterInputStream(
+ new ByteArrayInputStream( data ) );
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buf = new byte[4096];
+ int readBytes;
+ while ((readBytes = in.read(buf)) > 0)
+ {
+ out.write(buf, 0, readBytes);
+ }
+ return out.toByteArray();
+ }
+ catch ( IOException e )
+ {
+ log.log(POILogger.INFO, "Possibly corrupt compression or non-compressed data", e);
+ return data;
+ }
+ }
+
+ /**
+ * Returns the number of bytes that are required to serialize this record.
+ *
+ * @return Number of bytes
+ */
+ public int getRecordSize()
+ {
+ return 8 + 50 + raw_pictureData.length;
+ }
+
+ public byte[] getUID()
+ {
+ return field_1_UID;
+ }
+
+ public void setUID( byte[] field_1_UID )
+ {
+ this.field_1_UID = field_1_UID;
+ }
+
+ public int getUncompressedSize()
+ {
+ return field_2_cb;
+ }
+
+ public void setUncompressedSize(int uncompressedSize)
+ {
+ field_2_cb = uncompressedSize;
+ }
+
+ public Rectangle getBounds()
+ {
+ return new Rectangle(field_3_rcBounds_x1,
+ field_3_rcBounds_y1,
+ field_3_rcBounds_x2 - field_3_rcBounds_x1,
+ field_3_rcBounds_y2 - field_3_rcBounds_y1);
+ }
+
+ public void setBounds(Rectangle bounds)
+ {
+ field_3_rcBounds_x1 = bounds.x;
+ field_3_rcBounds_y1 = bounds.y;
+ field_3_rcBounds_x2 = bounds.x + bounds.width;
+ field_3_rcBounds_y2 = bounds.y + bounds.height;
+ }
+
+ public Dimension getSizeEMU()
+ {
+ return new Dimension(field_4_ptSize_w, field_4_ptSize_h);
+ }
+
+ public void setSizeEMU(Dimension sizeEMU)
+ {
+ field_4_ptSize_w = sizeEMU.width;
+ field_4_ptSize_h = sizeEMU.height;
+ }
+
+ public int getCompressedSize()
+ {
+ return field_5_cbSave;
+ }
+
+ public void setCompressedSize(int compressedSize)
+ {
+ field_5_cbSave = compressedSize;
+ }
+
+ public boolean isCompressed()
+ {
+ return (field_6_fCompression == 0);
+ }
+
+ public void setCompressed(boolean compressed)
+ {
+ field_6_fCompression = compressed ? 0 : (byte)0xFE;
+ }
+
+ // filtering is always 254 according to available docs, so no point giving it a setter method.
+
+ public String toString()
+ {
+ String nl = System.getProperty( "line.separator" );
+
+ String extraData;
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ try
+ {
+ HexDump.dump( this.field_pictureData, 0, b, 0 );
+ extraData = b.toString();
+ }
+ catch ( Exception e )
+ {
+ extraData = e.toString();
+ }
+ return getClass().getName() + ":" + nl +
+ " RecordId: 0x" + HexDump.toHex( getRecordId() ) + nl +
+ " Options: 0x" + HexDump.toHex( getOptions() ) + nl +
+ " UID: 0x" + HexDump.toHex( field_1_UID ) + nl +
+ " Uncompressed Size: " + HexDump.toHex( field_2_cb ) + nl +
+ " Bounds: " + getBounds() + nl +
+ " Size in EMU: " + getSizeEMU() + nl +
+ " Compressed Size: " + HexDump.toHex( field_5_cbSave ) + nl +
+ " Compression: " + HexDump.toHex( field_6_fCompression ) + nl +
+ " Filter: " + HexDump.toHex( field_7_fFilter ) + nl +
+ " Extra Data:" + nl + extraData;
+ }
+
+}
diff --git a/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java b/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java
index f24441841..026590d71 100644
--- a/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java
+++ b/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java
@@ -1,82 +1,82 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.model;
-
-import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.formula.FormulaParser;
-import org.apache.poi.ss.formula.FormulaParsingWorkbook;
-import org.apache.poi.ss.formula.FormulaRenderer;
-import org.apache.poi.ss.formula.FormulaType;
-
-/**
- * HSSF wrapper for the {@link FormulaParser} and {@link FormulaRenderer}
- *
- * @author Josh Micich
- */
-public final class HSSFFormulaParser {
-
- private static FormulaParsingWorkbook createParsingWorkbook(HSSFWorkbook book) {
- return HSSFEvaluationWorkbook.create(book);
- }
-
- private HSSFFormulaParser() {
- // no instances of this class
- }
-
- /**
- * Convenience method for parsing cell formulas. see {@link #parse(String, HSSFWorkbook, int)}
- */
- public static Ptg[] parse(String formula, HSSFWorkbook workbook) {
- return parse(formula, workbook, FormulaType.CELL);
- }
-
- /**
- * @param formulaType a constant from {@link FormulaType}
- * @return the parsed formula tokens
- */
- public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType) {
- return parse(formula, workbook, formulaType, -1);
- }
-
- /**
- * @param formula the formula to parse
- * @param workbook the parent workbook
- * @param formulaType a constant from {@link FormulaType}
- * @param sheetIndex the 0-based index of the sheet this formula belongs to.
- * The sheet index is required to resolve sheet-level names. -1
means that
- * the scope of the name will be ignored and the parser will match named ranges only by name
- *
- * @return the parsed formula tokens
- */
- public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType, int sheetIndex) {
- return FormulaParser.parse(formula, createParsingWorkbook(workbook), formulaType, sheetIndex);
- }
-
- /**
- * Static method to convert an array of {@link Ptg}s in RPN order
- * to a human readable string format in infix mode.
- * @param book used for defined names and 3D references
- * @param ptgs must not be null
- * @return a human readable String
- */
- public static String toFormulaString(HSSFWorkbook book, Ptg[] ptgs) {
- return FormulaRenderer.toFormulaString(HSSFEvaluationWorkbook.create(book), ptgs);
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.model;
+
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.FormulaParser;
+import org.apache.poi.ss.formula.FormulaParsingWorkbook;
+import org.apache.poi.ss.formula.FormulaRenderer;
+import org.apache.poi.ss.formula.FormulaType;
+
+/**
+ * HSSF wrapper for the {@link FormulaParser} and {@link FormulaRenderer}
+ *
+ * @author Josh Micich
+ */
+public final class HSSFFormulaParser {
+
+ private static FormulaParsingWorkbook createParsingWorkbook(HSSFWorkbook book) {
+ return HSSFEvaluationWorkbook.create(book);
+ }
+
+ private HSSFFormulaParser() {
+ // no instances of this class
+ }
+
+ /**
+ * Convenience method for parsing cell formulas. see {@link #parse(String, HSSFWorkbook, int)}
+ */
+ public static Ptg[] parse(String formula, HSSFWorkbook workbook) {
+ return parse(formula, workbook, FormulaType.CELL);
+ }
+
+ /**
+ * @param formulaType a constant from {@link FormulaType}
+ * @return the parsed formula tokens
+ */
+ public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType) {
+ return parse(formula, workbook, formulaType, -1);
+ }
+
+ /**
+ * @param formula the formula to parse
+ * @param workbook the parent workbook
+ * @param formulaType a constant from {@link FormulaType}
+ * @param sheetIndex the 0-based index of the sheet this formula belongs to.
+ * The sheet index is required to resolve sheet-level names. -1
means that
+ * the scope of the name will be ignored and the parser will match named ranges only by name
+ *
+ * @return the parsed formula tokens
+ */
+ public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType, int sheetIndex) {
+ return FormulaParser.parse(formula, createParsingWorkbook(workbook), formulaType, sheetIndex);
+ }
+
+ /**
+ * Static method to convert an array of {@link Ptg}s in RPN order
+ * to a human readable string format in infix mode.
+ * @param book used for defined names and 3D references
+ * @param ptgs must not be null
+ * @return a human readable String
+ */
+ public static String toFormulaString(HSSFWorkbook book, Ptg[] ptgs) {
+ return FormulaRenderer.toFormulaString(HSSFEvaluationWorkbook.create(book), ptgs);
+ }
+}
diff --git a/src/java/org/apache/poi/hssf/record/ArrayRecord.java b/src/java/org/apache/poi/hssf/record/ArrayRecord.java
index 35239bb23..0cf6f44e0 100644
--- a/src/java/org/apache/poi/hssf/record/ArrayRecord.java
+++ b/src/java/org/apache/poi/hssf/record/ArrayRecord.java
@@ -1,87 +1,87 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.record;
-
-import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.ss.formula.Formula;
-import org.apache.poi.util.HexDump;
-import org.apache.poi.util.LittleEndianOutput;
-
-/**
- * ARRAY (0x0221)
null
- */
- void visitRecord(Record r);
- }
-
- private static final class SerializingRecordVisitor implements RecordVisitor {
-
- private final byte[] _data;
- private final int _startOffset;
- private int _countBytesWritten;
-
- public SerializingRecordVisitor(byte[] data, int startOffset) {
- _data = data;
- _startOffset = startOffset;
- _countBytesWritten = 0;
- }
- public int countBytesWritten() {
- return _countBytesWritten;
- }
- public void visitRecord(Record r) {
- int currentOffset = _startOffset + _countBytesWritten;
- _countBytesWritten += r.serialize(currentOffset, _data);
- }
- }
- private static final class RecordSizingVisitor implements RecordVisitor {
-
- private int _totalSize;
-
- public RecordSizingVisitor() {
- _totalSize = 0;
- }
- public int getTotalSize() {
- return _totalSize;
- }
- public void visitRecord(Record r) {
- _totalSize += r.getRecordSize();
- }
- }
- /**
- * A wrapper for {@link RecordVisitor} which accumulates the sizes of all
- * records visited.
- */
- public static final class PositionTrackingVisitor implements RecordVisitor {
- private final RecordVisitor _rv;
- private int _position;
-
- public PositionTrackingVisitor(RecordVisitor rv, int initialPosition) {
- _rv = rv;
- _position = initialPosition;
- }
- public void visitRecord(Record r) {
- _position += r.getRecordSize();
- _rv.visitRecord(r);
- }
- public void setPosition(int position) {
- _position = position;
- }
- public int getPosition() {
- return _position;
- }
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.aggregates;
+
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordBase;
+
+/**
+ * RecordAggregates are groups of of BIFF Records that are typically stored
+ * together and/or updated together. Workbook / Sheet records are typically stored in a sequential
+ * list, which does not provide much structure to coordinate updates.
+ *
+ * @author Josh Micich
+ */
+public abstract class RecordAggregate extends RecordBase {
+
+ /**
+ * Visit each of the atomic BIFF records contained in this {@link RecordAggregate} in the order
+ * that they should be written to file. Implementors may or may not return the actual
+ * {@link Record}s being used to manage POI's internal implementation. Callers should not
+ * assume either way, and therefore only attempt to modify those {@link Record}s after cloning
+ */
+ public abstract void visitContainedRecords(RecordVisitor rv);
+
+ public final int serialize(int offset, byte[] data) {
+ SerializingRecordVisitor srv = new SerializingRecordVisitor(data, offset);
+ visitContainedRecords(srv);
+ return srv.countBytesWritten();
+ }
+ public int getRecordSize() {
+ RecordSizingVisitor rsv = new RecordSizingVisitor();
+ visitContainedRecords(rsv);
+ return rsv.getTotalSize();
+ }
+
+ public interface RecordVisitor {
+ /**
+ * Implementors may call non-mutating methods on Record r.
+ * @param r must not be null
+ */
+ void visitRecord(Record r);
+ }
+
+ private static final class SerializingRecordVisitor implements RecordVisitor {
+
+ private final byte[] _data;
+ private final int _startOffset;
+ private int _countBytesWritten;
+
+ public SerializingRecordVisitor(byte[] data, int startOffset) {
+ _data = data;
+ _startOffset = startOffset;
+ _countBytesWritten = 0;
+ }
+ public int countBytesWritten() {
+ return _countBytesWritten;
+ }
+ public void visitRecord(Record r) {
+ int currentOffset = _startOffset + _countBytesWritten;
+ _countBytesWritten += r.serialize(currentOffset, _data);
+ }
+ }
+ private static final class RecordSizingVisitor implements RecordVisitor {
+
+ private int _totalSize;
+
+ public RecordSizingVisitor() {
+ _totalSize = 0;
+ }
+ public int getTotalSize() {
+ return _totalSize;
+ }
+ public void visitRecord(Record r) {
+ _totalSize += r.getRecordSize();
+ }
+ }
+ /**
+ * A wrapper for {@link RecordVisitor} which accumulates the sizes of all
+ * records visited.
+ */
+ public static final class PositionTrackingVisitor implements RecordVisitor {
+ private final RecordVisitor _rv;
+ private int _position;
+
+ public PositionTrackingVisitor(RecordVisitor rv, int initialPosition) {
+ _rv = rv;
+ _position = initialPosition;
+ }
+ public void visitRecord(Record r) {
+ _position += r.getRecordSize();
+ _rv.visitRecord(r);
+ }
+ public void setPosition(int position) {
+ _position = position;
+ }
+ public int getPosition() {
+ return _position;
+ }
+ }
+}
diff --git a/src/java/org/apache/poi/hssf/record/cont/ContinuableRecord.java b/src/java/org/apache/poi/hssf/record/cont/ContinuableRecord.java
index 01fedd029..304805441 100644
--- a/src/java/org/apache/poi/hssf/record/cont/ContinuableRecord.java
+++ b/src/java/org/apache/poi/hssf/record/cont/ContinuableRecord.java
@@ -1,69 +1,69 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.record.cont;
-
-import org.apache.poi.hssf.record.ContinueRecord;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.util.LittleEndianByteArrayOutputStream;
-import org.apache.poi.util.LittleEndianOutput;
-
-/**
- * Common superclass of all records that can produce {@link ContinueRecord}s while being serialized.
- *
- * @author Josh Micich
- */
-public abstract class ContinuableRecord extends Record {
-
- protected ContinuableRecord() {
- // no fields to initialise
- }
- /**
- * Serializes this record's content to the supplied data output.Mask | Description |
---|---|
0x01 | is16bitEncoded |
0x04 | hasExtendedData |
0x08 | isRichText |
Mask | Description |
---|---|
0x01 | is16bitEncoded |
0x04 | hasExtendedData |
0x08 | isRichText |
-1
means workbook-global names
- */
- public EvaluationName getName(String name, int sheetIndex) {
- for(int i=0; i < _iBook.getNumNames(); i++) {
- NameRecord nr = _iBook.getNameRecord(i);
- if (nr.getSheetNumber() == sheetIndex+1 && name.equalsIgnoreCase(nr.getNameText())) {
- return new Name(nr, i);
- }
- }
- return sheetIndex == -1 ? null : getName(name, -1);
- }
-
- public int getSheetIndex(EvaluationSheet evalSheet) {
- HSSFSheet sheet = ((HSSFEvaluationSheet)evalSheet).getHSSFSheet();
- return _uBook.getSheetIndex(sheet);
- }
- public int getSheetIndex(String sheetName) {
- return _uBook.getSheetIndex(sheetName);
- }
-
- public String getSheetName(int sheetIndex) {
- return _uBook.getSheetName(sheetIndex);
- }
-
- public EvaluationSheet getSheet(int sheetIndex) {
- return new HSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex));
- }
- public int convertFromExternSheetIndex(int externSheetIndex) {
- return _iBook.getSheetIndexFromExternSheetIndex(externSheetIndex);
- }
-
- public ExternalSheet getExternalSheet(int externSheetIndex) {
- return _iBook.getExternalSheet(externSheetIndex);
- }
-
- public String resolveNameXText(NameXPtg n) {
- return _iBook.resolveNameXText(n.getSheetRefIndex(), n.getNameIndex());
- }
-
- public String getSheetNameByExternSheet(int externSheetIndex) {
- return _iBook.findSheetNameFromExternSheet(externSheetIndex);
- }
- public String getNameText(NamePtg namePtg) {
- return _iBook.getNameRecord(namePtg.getIndex()).getNameText();
- }
- public EvaluationName getName(NamePtg namePtg) {
- int ix = namePtg.getIndex();
- return new Name(_iBook.getNameRecord(ix), ix);
- }
- public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
- HSSFCell cell = ((HSSFEvaluationCell)evalCell).getHSSFCell();
- if (false) {
- // re-parsing the formula text also works, but is a waste of time
- // It is useful from time to time to run all unit tests with this code
- // to make sure that all formulas POI can evaluate can also be parsed.
- return HSSFFormulaParser.parse(cell.getCellFormula(), _uBook, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet()));
- }
- FormulaRecordAggregate fra = (FormulaRecordAggregate) cell.getCellValueRecord();
- return fra.getFormulaTokens();
- }
-
- private static final class Name implements EvaluationName {
-
- private final NameRecord _nameRecord;
- private final int _index;
-
- public Name(NameRecord nameRecord, int index) {
- _nameRecord = nameRecord;
- _index = index;
- }
- public Ptg[] getNameDefinition() {
- return _nameRecord.getNameDefinition();
- }
- public String getNameText() {
- return _nameRecord.getNameText();
- }
- public boolean hasFormula() {
- return _nameRecord.hasFormula();
- }
- public boolean isFunctionName() {
- return _nameRecord.isFunctionName();
- }
- public boolean isRange() {
- return _nameRecord.hasFormula(); // TODO - is this right?
- }
- public NamePtg createPtg() {
- return new NamePtg(_index);
- }
- }
-
- public SpreadsheetVersion getSpreadsheetVersion(){
- return SpreadsheetVersion.EXCEL97;
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.usermodel;
+
+import org.apache.poi.hssf.model.HSSFFormulaParser;
+import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.record.NameRecord;
+import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
+import org.apache.poi.hssf.record.formula.NamePtg;
+import org.apache.poi.hssf.record.formula.NameXPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.ss.formula.*;
+import org.apache.poi.ss.SpreadsheetVersion;
+
+/**
+ * Internal POI use only
+ *
+ * @author Josh Micich
+ */
+public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, EvaluationWorkbook, FormulaParsingWorkbook {
+
+ private final HSSFWorkbook _uBook;
+ private final Workbook _iBook;
+
+ public static HSSFEvaluationWorkbook create(HSSFWorkbook book) {
+ if (book == null) {
+ return null;
+ }
+ return new HSSFEvaluationWorkbook(book);
+ }
+
+ private HSSFEvaluationWorkbook(HSSFWorkbook book) {
+ _uBook = book;
+ _iBook = book.getWorkbook();
+ }
+
+ public int getExternalSheetIndex(String sheetName) {
+ int sheetIndex = _uBook.getSheetIndex(sheetName);
+ return _iBook.checkExternSheet(sheetIndex);
+ }
+ public int getExternalSheetIndex(String workbookName, String sheetName) {
+ return _iBook.getExternalSheetIndex(workbookName, sheetName);
+ }
+
+ public NameXPtg getNameXPtg(String name) {
+ return _iBook.getNameXPtg(name);
+ }
+
+ /**
+ * Lookup a named range by its name.
+ *
+ * @param name the name to search
+ * @param sheetIndex the 0-based index of the sheet this formula belongs to.
+ * The sheet index is required to resolve sheet-level names. -1
means workbook-global names
+ */
+ public EvaluationName getName(String name, int sheetIndex) {
+ for(int i=0; i < _iBook.getNumNames(); i++) {
+ NameRecord nr = _iBook.getNameRecord(i);
+ if (nr.getSheetNumber() == sheetIndex+1 && name.equalsIgnoreCase(nr.getNameText())) {
+ return new Name(nr, i);
+ }
+ }
+ return sheetIndex == -1 ? null : getName(name, -1);
+ }
+
+ public int getSheetIndex(EvaluationSheet evalSheet) {
+ HSSFSheet sheet = ((HSSFEvaluationSheet)evalSheet).getHSSFSheet();
+ return _uBook.getSheetIndex(sheet);
+ }
+ public int getSheetIndex(String sheetName) {
+ return _uBook.getSheetIndex(sheetName);
+ }
+
+ public String getSheetName(int sheetIndex) {
+ return _uBook.getSheetName(sheetIndex);
+ }
+
+ public EvaluationSheet getSheet(int sheetIndex) {
+ return new HSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex));
+ }
+ public int convertFromExternSheetIndex(int externSheetIndex) {
+ return _iBook.getSheetIndexFromExternSheetIndex(externSheetIndex);
+ }
+
+ public ExternalSheet getExternalSheet(int externSheetIndex) {
+ return _iBook.getExternalSheet(externSheetIndex);
+ }
+
+ public String resolveNameXText(NameXPtg n) {
+ return _iBook.resolveNameXText(n.getSheetRefIndex(), n.getNameIndex());
+ }
+
+ public String getSheetNameByExternSheet(int externSheetIndex) {
+ return _iBook.findSheetNameFromExternSheet(externSheetIndex);
+ }
+ public String getNameText(NamePtg namePtg) {
+ return _iBook.getNameRecord(namePtg.getIndex()).getNameText();
+ }
+ public EvaluationName getName(NamePtg namePtg) {
+ int ix = namePtg.getIndex();
+ return new Name(_iBook.getNameRecord(ix), ix);
+ }
+ public Ptg[] getFormulaTokens(EvaluationCell evalCell) {
+ HSSFCell cell = ((HSSFEvaluationCell)evalCell).getHSSFCell();
+ if (false) {
+ // re-parsing the formula text also works, but is a waste of time
+ // It is useful from time to time to run all unit tests with this code
+ // to make sure that all formulas POI can evaluate can also be parsed.
+ return HSSFFormulaParser.parse(cell.getCellFormula(), _uBook, FormulaType.CELL, _uBook.getSheetIndex(cell.getSheet()));
+ }
+ FormulaRecordAggregate fra = (FormulaRecordAggregate) cell.getCellValueRecord();
+ return fra.getFormulaTokens();
+ }
+
+ private static final class Name implements EvaluationName {
+
+ private final NameRecord _nameRecord;
+ private final int _index;
+
+ public Name(NameRecord nameRecord, int index) {
+ _nameRecord = nameRecord;
+ _index = index;
+ }
+ public Ptg[] getNameDefinition() {
+ return _nameRecord.getNameDefinition();
+ }
+ public String getNameText() {
+ return _nameRecord.getNameText();
+ }
+ public boolean hasFormula() {
+ return _nameRecord.hasFormula();
+ }
+ public boolean isFunctionName() {
+ return _nameRecord.isFunctionName();
+ }
+ public boolean isRange() {
+ return _nameRecord.hasFormula(); // TODO - is this right?
+ }
+ public NamePtg createPtg() {
+ return new NamePtg(_index);
+ }
+ }
+
+ public SpreadsheetVersion getSpreadsheetVersion(){
+ return SpreadsheetVersion.EXCEL97;
+ }
+}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
index aa1a0a5d0..a49fb9c68 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
@@ -1,315 +1,316 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.usermodel;
-
-import java.util.Iterator;
-
-import org.apache.poi.hssf.record.formula.eval.BoolEval;
-import org.apache.poi.hssf.record.formula.eval.ErrorEval;
-import org.apache.poi.hssf.record.formula.eval.NumberEval;
-import org.apache.poi.hssf.record.formula.eval.StringEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment;
-import org.apache.poi.ss.formula.IStabilityClassifier;
-import org.apache.poi.ss.formula.WorkbookEvaluator;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellValue;
-import org.apache.poi.ss.usermodel.FormulaEvaluator;
-
-/**
- * Evaluates formula cells.
- *
- * For performance reasons, this class keeps a cache of all previously calculated intermediate
- * cell values. Be sure to call {@link #clearAllCachedResultValues()} if any workbook cells are changed between
- * calls to evaluate~ methods on this class.
- *
- * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- * @author Josh Micich
- */
-public class HSSFFormulaEvaluator implements FormulaEvaluator {
-
- private WorkbookEvaluator _bookEvaluator;
-
- /**
- * @deprecated (Sep 2008) HSSFSheet parameter is ignored
- */
- public HSSFFormulaEvaluator(HSSFSheet sheet, HSSFWorkbook workbook) {
- this(workbook);
- if (false) {
- sheet.toString(); // suppress unused parameter compiler warning
- }
- }
- public HSSFFormulaEvaluator(HSSFWorkbook workbook) {
- this(workbook, null);
- }
- /**
- * @param stabilityClassifier used to optimise caching performance. Pass null
- * for the (conservative) assumption that any cell may have its definition changed after
- * evaluation begins.
- */
- public HSSFFormulaEvaluator(HSSFWorkbook workbook, IStabilityClassifier stabilityClassifier) {
- _bookEvaluator = new WorkbookEvaluator(HSSFEvaluationWorkbook.create(workbook), stabilityClassifier);
- }
-
- /**
- * Coordinates several formula evaluators together so that formulas that involve external
- * references can be evaluated.
- * @param workbookNames the simple file names used to identify the workbooks in formulas
- * with external links (for example "MyData.xls" as used in a formula "[MyData.xls]Sheet1!A1")
- * @param evaluators all evaluators for the full set of workbooks required by the formulas.
- */
- public static void setupEnvironment(String[] workbookNames, HSSFFormulaEvaluator[] evaluators) {
- WorkbookEvaluator[] wbEvals = new WorkbookEvaluator[evaluators.length];
- for (int i = 0; i < wbEvals.length; i++) {
- wbEvals[i] = evaluators[i]._bookEvaluator;
- }
- CollaboratingWorkbooksEnvironment.setup(workbookNames, wbEvals);
- }
-
- /**
- * Does nothing
- * @deprecated (Aug 2008) - not needed, since the current row can be derived from the cell
- */
- public void setCurrentRow(HSSFRow row) {
- // do nothing
- if (false) {
- row.getClass(); // suppress unused parameter compiler warning
- }
- }
-
- /**
- * Should be called whenever there are major changes (e.g. moving sheets) to input cells
- * in the evaluated workbook. If performance is not critical, a single call to this method
- * may be used instead of many specific calls to the notify~ methods.
- *
- * Failure to call this method after changing cell values will cause incorrect behaviour
- * of the evaluate~ methods of this class
- */
- public void clearAllCachedResultValues() {
- _bookEvaluator.clearAllCachedResultValues();
- }
- /**
- * Should be called to tell the cell value cache that the specified (value or formula) cell
- * has changed.
- * Failure to call this method after changing cell values will cause incorrect behaviour
- * of the evaluate~ methods of this class
- */
- public void notifyUpdateCell(HSSFCell cell) {
- _bookEvaluator.notifyUpdateCell(new HSSFEvaluationCell(cell));
- }
- /**
- * Should be called to tell the cell value cache that the specified cell has just been
- * deleted.
- * Failure to call this method after changing cell values will cause incorrect behaviour
- * of the evaluate~ methods of this class
- */
- public void notifyDeleteCell(HSSFCell cell) {
- _bookEvaluator.notifyDeleteCell(new HSSFEvaluationCell(cell));
- }
- public void notifyDeleteCell(Cell cell) {
- _bookEvaluator.notifyDeleteCell(new HSSFEvaluationCell((HSSFCell)cell));
- }
-
- /**
- * Should be called to tell the cell value cache that the specified (value or formula) cell
- * has changed.
- * Failure to call this method after changing cell values will cause incorrect behaviour
- * of the evaluate~ methods of this class
- */
- public void notifySetFormula(Cell cell) {
- _bookEvaluator.notifyUpdateCell(new HSSFEvaluationCell((HSSFCell)cell));
- }
-
- /**
- * If cell contains a formula, the formula is evaluated and returned,
- * else the CellValue simply copies the appropriate cell value from
- * the cell and also its cell type. This method should be preferred over
- * evaluateInCell() when the call should not modify the contents of the
- * original cell.
- *
- * @param cell may be null
signifying that the cell is not present (or blank)
- * @return null
if the supplied cell is null
or blank
- */
- public CellValue evaluate(Cell cell) {
- if (cell == null) {
- return null;
- }
-
- switch (cell.getCellType()) {
- case HSSFCell.CELL_TYPE_BOOLEAN:
- return CellValue.valueOf(cell.getBooleanCellValue());
- case HSSFCell.CELL_TYPE_ERROR:
- return CellValue.getError(cell.getErrorCellValue());
- case HSSFCell.CELL_TYPE_FORMULA:
- return evaluateFormulaCellValue(cell);
- case HSSFCell.CELL_TYPE_NUMERIC:
- return new CellValue(cell.getNumericCellValue());
- case HSSFCell.CELL_TYPE_STRING:
- return new CellValue(cell.getRichStringCellValue().getString());
- case HSSFCell.CELL_TYPE_BLANK:
- return null;
- }
- throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
- }
-
-
- /**
- * If cell contains formula, it evaluates the formula, and saves the result of the formula. The
- * cell remains as a formula cell. If the cell does not contain formula, this method returns -1
- * and leaves the cell unchanged.
- *
- * Note that the type of the formula result is returned, so you know what kind of
- * cached formula result is also stored with the formula.
- * - * int evaluatedCellType = evaluator.evaluateFormulaCell(cell); - *- * Be aware that your cell will hold both the formula, and the result. If you want the cell - * replaced with the result of the formula, use {@link #evaluateInCell(org.apache.poi.ss.usermodel.Cell)} - * @param cell The cell to evaluate - * @return -1 for non-formula cells, or the type of the formula result - */ - public int evaluateFormulaCell(Cell cell) { - if (cell == null || cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) { - return -1; - } - CellValue cv = evaluateFormulaCellValue(cell); - // cell remains a formula cell, but the cached value is changed - setCellValue(cell, cv); - return cv.getCellType(); - } - - /** - * If cell contains formula, it evaluates the formula, and - * puts the formula result back into the cell, in place - * of the old formula. - * Else if cell does not contain formula, this method leaves - * the cell unchanged. - * Note that the same instance of HSSFCell is returned to - * allow chained calls like: - *
- * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType(); - *- * Be aware that your cell value will be changed to hold the - * result of the formula. If you simply want the formula - * value computed for you, use {@link #evaluateFormulaCell(Cell)}} - */ - public HSSFCell evaluateInCell(Cell cell) { - if (cell == null) { - return null; - } - HSSFCell result = (HSSFCell) cell; - if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { - CellValue cv = evaluateFormulaCellValue(cell); - setCellValue(cell, cv); - setCellType(cell, cv); // cell will no longer be a formula cell - } - return result; - } - private static void setCellType(Cell cell, CellValue cv) { - int cellType = cv.getCellType(); - switch (cellType) { - case HSSFCell.CELL_TYPE_BOOLEAN: - case HSSFCell.CELL_TYPE_ERROR: - case HSSFCell.CELL_TYPE_NUMERIC: - case HSSFCell.CELL_TYPE_STRING: - cell.setCellType(cellType); - return; - case HSSFCell.CELL_TYPE_BLANK: - // never happens - blanks eventually get translated to zero - case HSSFCell.CELL_TYPE_FORMULA: - // this will never happen, we have already evaluated the formula - } - throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); - } - - private static void setCellValue(Cell cell, CellValue cv) { - int cellType = cv.getCellType(); - switch (cellType) { - case HSSFCell.CELL_TYPE_BOOLEAN: - cell.setCellValue(cv.getBooleanValue()); - break; - case HSSFCell.CELL_TYPE_ERROR: - cell.setCellErrorValue(cv.getErrorValue()); - break; - case HSSFCell.CELL_TYPE_NUMERIC: - cell.setCellValue(cv.getNumberValue()); - break; - case HSSFCell.CELL_TYPE_STRING: - cell.setCellValue(new HSSFRichTextString(cv.getStringValue())); - break; - case HSSFCell.CELL_TYPE_BLANK: - // never happens - blanks eventually get translated to zero - case HSSFCell.CELL_TYPE_FORMULA: - // this will never happen, we have already evaluated the formula - default: - throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); - } - } - - /** - * Loops over all cells in all sheets of the supplied - * workbook. - * For cells that contain formulas, their formulas are - * evaluated, and the results are saved. These cells - * remain as formula cells. - * For cells that do not contain formulas, no changes - * are made. - * This is a helpful wrapper around looping over all - * cells, and calling evaluateFormulaCell on each one. - */ - public static void evaluateAllFormulaCells(HSSFWorkbook wb) { - HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb); - for(int i=0; i
null
+ * for the (conservative) assumption that any cell may have its definition changed after
+ * evaluation begins.
+ */
+ public HSSFFormulaEvaluator(HSSFWorkbook workbook, IStabilityClassifier stabilityClassifier) {
+ _bookEvaluator = new WorkbookEvaluator(HSSFEvaluationWorkbook.create(workbook), stabilityClassifier);
+ }
+
+ /**
+ * Coordinates several formula evaluators together so that formulas that involve external
+ * references can be evaluated.
+ * @param workbookNames the simple file names used to identify the workbooks in formulas
+ * with external links (for example "MyData.xls" as used in a formula "[MyData.xls]Sheet1!A1")
+ * @param evaluators all evaluators for the full set of workbooks required by the formulas.
+ */
+ public static void setupEnvironment(String[] workbookNames, HSSFFormulaEvaluator[] evaluators) {
+ WorkbookEvaluator[] wbEvals = new WorkbookEvaluator[evaluators.length];
+ for (int i = 0; i < wbEvals.length; i++) {
+ wbEvals[i] = evaluators[i]._bookEvaluator;
+ }
+ CollaboratingWorkbooksEnvironment.setup(workbookNames, wbEvals);
+ }
+
+ /**
+ * Does nothing
+ * @deprecated (Aug 2008) - not needed, since the current row can be derived from the cell
+ */
+ public void setCurrentRow(HSSFRow row) {
+ // do nothing
+ if (false) {
+ row.getClass(); // suppress unused parameter compiler warning
+ }
+ }
+
+ /**
+ * Should be called whenever there are major changes (e.g. moving sheets) to input cells
+ * in the evaluated workbook. If performance is not critical, a single call to this method
+ * may be used instead of many specific calls to the notify~ methods.
+ *
+ * Failure to call this method after changing cell values will cause incorrect behaviour
+ * of the evaluate~ methods of this class
+ */
+ public void clearAllCachedResultValues() {
+ _bookEvaluator.clearAllCachedResultValues();
+ }
+ /**
+ * Should be called to tell the cell value cache that the specified (value or formula) cell
+ * has changed.
+ * Failure to call this method after changing cell values will cause incorrect behaviour
+ * of the evaluate~ methods of this class
+ */
+ public void notifyUpdateCell(HSSFCell cell) {
+ _bookEvaluator.notifyUpdateCell(new HSSFEvaluationCell(cell));
+ }
+ /**
+ * Should be called to tell the cell value cache that the specified cell has just been
+ * deleted.
+ * Failure to call this method after changing cell values will cause incorrect behaviour
+ * of the evaluate~ methods of this class
+ */
+ public void notifyDeleteCell(HSSFCell cell) {
+ _bookEvaluator.notifyDeleteCell(new HSSFEvaluationCell(cell));
+ }
+ public void notifyDeleteCell(Cell cell) {
+ _bookEvaluator.notifyDeleteCell(new HSSFEvaluationCell((HSSFCell)cell));
+ }
+
+ /**
+ * Should be called to tell the cell value cache that the specified (value or formula) cell
+ * has changed.
+ * Failure to call this method after changing cell values will cause incorrect behaviour
+ * of the evaluate~ methods of this class
+ */
+ public void notifySetFormula(Cell cell) {
+ _bookEvaluator.notifyUpdateCell(new HSSFEvaluationCell((HSSFCell)cell));
+ }
+
+ /**
+ * If cell contains a formula, the formula is evaluated and returned,
+ * else the CellValue simply copies the appropriate cell value from
+ * the cell and also its cell type. This method should be preferred over
+ * evaluateInCell() when the call should not modify the contents of the
+ * original cell.
+ *
+ * @param cell may be null
signifying that the cell is not present (or blank)
+ * @return null
if the supplied cell is null
or blank
+ */
+ public CellValue evaluate(Cell cell) {
+ if (cell == null) {
+ return null;
+ }
+
+ switch (cell.getCellType()) {
+ case HSSFCell.CELL_TYPE_BOOLEAN:
+ return CellValue.valueOf(cell.getBooleanCellValue());
+ case HSSFCell.CELL_TYPE_ERROR:
+ return CellValue.getError(cell.getErrorCellValue());
+ case HSSFCell.CELL_TYPE_FORMULA:
+ return evaluateFormulaCellValue(cell);
+ case HSSFCell.CELL_TYPE_NUMERIC:
+ return new CellValue(cell.getNumericCellValue());
+ case HSSFCell.CELL_TYPE_STRING:
+ return new CellValue(cell.getRichStringCellValue().getString());
+ case HSSFCell.CELL_TYPE_BLANK:
+ return null;
+ }
+ throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
+ }
+
+
+ /**
+ * If cell contains formula, it evaluates the formula, and saves the result of the formula. The
+ * cell remains as a formula cell. If the cell does not contain formula, this method returns -1
+ * and leaves the cell unchanged.
+ *
+ * Note that the type of the formula result is returned, so you know what kind of
+ * cached formula result is also stored with the formula.
+ * + * int evaluatedCellType = evaluator.evaluateFormulaCell(cell); + *+ * Be aware that your cell will hold both the formula, and the result. If you want the cell + * replaced with the result of the formula, use {@link #evaluateInCell(org.apache.poi.ss.usermodel.Cell)} + * @param cell The cell to evaluate + * @return -1 for non-formula cells, or the type of the formula result + */ + public int evaluateFormulaCell(Cell cell) { + if (cell == null || cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) { + return -1; + } + CellValue cv = evaluateFormulaCellValue(cell); + // cell remains a formula cell, but the cached value is changed + setCellValue(cell, cv); + return cv.getCellType(); + } + + /** + * If cell contains formula, it evaluates the formula, and + * puts the formula result back into the cell, in place + * of the old formula. + * Else if cell does not contain formula, this method leaves + * the cell unchanged. + * Note that the same instance of HSSFCell is returned to + * allow chained calls like: + *
+ * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType(); + *+ * Be aware that your cell value will be changed to hold the + * result of the formula. If you simply want the formula + * value computed for you, use {@link #evaluateFormulaCell(Cell)}} + */ + public HSSFCell evaluateInCell(Cell cell) { + if (cell == null) { + return null; + } + HSSFCell result = (HSSFCell) cell; + if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { + CellValue cv = evaluateFormulaCellValue(cell); + setCellValue(cell, cv); + setCellType(cell, cv); // cell will no longer be a formula cell + } + return result; + } + private static void setCellType(Cell cell, CellValue cv) { + int cellType = cv.getCellType(); + switch (cellType) { + case HSSFCell.CELL_TYPE_BOOLEAN: + case HSSFCell.CELL_TYPE_ERROR: + case HSSFCell.CELL_TYPE_NUMERIC: + case HSSFCell.CELL_TYPE_STRING: + cell.setCellType(cellType); + return; + case HSSFCell.CELL_TYPE_BLANK: + // never happens - blanks eventually get translated to zero + case HSSFCell.CELL_TYPE_FORMULA: + // this will never happen, we have already evaluated the formula + } + throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); + } + + private static void setCellValue(Cell cell, CellValue cv) { + int cellType = cv.getCellType(); + switch (cellType) { + case HSSFCell.CELL_TYPE_BOOLEAN: + cell.setCellValue(cv.getBooleanValue()); + break; + case HSSFCell.CELL_TYPE_ERROR: + cell.setCellErrorValue(cv.getErrorValue()); + break; + case HSSFCell.CELL_TYPE_NUMERIC: + cell.setCellValue(cv.getNumberValue()); + break; + case HSSFCell.CELL_TYPE_STRING: + cell.setCellValue(new HSSFRichTextString(cv.getStringValue())); + break; + case HSSFCell.CELL_TYPE_BLANK: + // never happens - blanks eventually get translated to zero + case HSSFCell.CELL_TYPE_FORMULA: + // this will never happen, we have already evaluated the formula + default: + throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); + } + } + + /** + * Loops over all cells in all sheets of the supplied + * workbook. + * For cells that contain formulas, their formulas are + * evaluated, and the results are saved. These cells + * remain as formula cells. + * For cells that do not contain formulas, no changes + * are made. + * This is a helpful wrapper around looping over all + * cells, and calling evaluateFormulaCell on each one. + */ + public static void evaluateAllFormulaCells(HSSFWorkbook wb) { + HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb); + for(int i=0; i
HyperlinkRecord
record
- *
- * @param record
- */
- protected HSSFHyperlink( HyperlinkRecord record )
- {
- this.record = record;
- }
-
- /**
- * Return the row of the first cell that contains the hyperlink
- *
- * @return the 0-based row of the cell that contains the hyperlink
- */
- public int getFirstRow(){
- return record.getFirstRow();
- }
-
- /**
- * Set the row of the first cell that contains the hyperlink
- *
- * @param row the 0-based row of the first cell that contains the hyperlink
- */
- public void setFirstRow(int row){
- record.setFirstRow(row);
- }
-
- /**
- * Return the row of the last cell that contains the hyperlink
- *
- * @return the 0-based row of the last cell that contains the hyperlink
- */
- public int getLastRow(){
- return record.getLastRow();
- }
-
- /**
- * Set the row of the last cell that contains the hyperlink
- *
- * @param row the 0-based row of the last cell that contains the hyperlink
- */
- public void setLastRow(int row){
- record.setLastRow(row);
- }
-
- /**
- * Return the column of the first cell that contains the hyperlink
- *
- * @return the 0-based column of the first cell that contains the hyperlink
- */
- public int getFirstColumn(){
- return record.getFirstColumn();
- }
-
- /**
- * Set the column of the first cell that contains the hyperlink
- *
- * @param col the 0-based column of the first cell that contains the hyperlink
- */
- public void setFirstColumn(int col){
- record.setFirstColumn((short)col);
- }
-
- /**
- * Return the column of the last cell that contains the hyperlink
- *
- * @return the 0-based column of the last cell that contains the hyperlink
- */
- public int getLastColumn(){
- return record.getLastColumn();
- }
-
- /**
- * Set the column of the last cell that contains the hyperlink
- *
- * @param col the 0-based column of the last cell that contains the hyperlink
- */
- public void setLastColumn(int col){
- record.setLastColumn((short)col);
- }
-
- /**
- * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.
- *
- * @return the address of this hyperlink
- */
- public String getAddress(){
- return record.getAddress();
- }
- public String getTextMark(){
- return record.getTextMark();
- }
- public void setTextMark(String textMark) {
- record.setTextMark(textMark);
- }
- public String getShortFilename(){
- return record.getShortFilename();
- }
- public void setShortFilename(String shortFilename) {
- record.setShortFilename(shortFilename);
- }
-
- /**
- * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.
- *
- * @param address the address of this hyperlink
- */
- public void setAddress(String address){
- record.setAddress(address);
- }
-
- /**
- * Return text label for this hyperlink
- *
- * @return text to display
- */
- public String getLabel(){
- return record.getLabel();
- }
-
- /**
- * Sets text label for this hyperlink
- *
- * @param label text label for this hyperlink
- */
- public void setLabel(String label){
- record.setLabel(label);
- }
-
- /**
- * Return the type of this hyperlink
- *
- * @return the type of this hyperlink
- */
- public int getType(){
- return link_type;
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.hssf.usermodel;
+
+import org.apache.poi.hssf.record.HyperlinkRecord;
+import org.apache.poi.ss.usermodel.Hyperlink;
+
+/**
+ * Represents an Excel hyperlink.
+ *
+ * @author Yegor Kozlov (yegor at apache dot org)
+ */
+public class HSSFHyperlink implements Hyperlink {
+
+ /**
+ * Link to a existing file or web page
+ */
+ public static final int LINK_URL = 1;
+
+ /**
+ * Link to a place in this document
+ */
+ public static final int LINK_DOCUMENT = 2;
+
+ /**
+ * Link to an E-mail address
+ */
+ public static final int LINK_EMAIL = 3;
+
+ /**
+ * Link to a file
+ */
+ public static final int LINK_FILE = 4;
+
+ /**
+ * Low-level record object that stores the actual hyperlink data
+ */
+ protected HyperlinkRecord record = null;
+
+ /**
+ * If we create a new hypelrink remember its type
+ */
+ protected int link_type;
+
+ /**
+ * Construct a new hyperlink
+ *
+ * @param type the type of hyperlink to create
+ */
+ public HSSFHyperlink( int type )
+ {
+ this.link_type = type;
+ record = new HyperlinkRecord();
+ switch(type){
+ case LINK_URL:
+ case LINK_EMAIL:
+ record.newUrlLink();
+ break;
+ case LINK_FILE:
+ record.newFileLink();
+ break;
+ case LINK_DOCUMENT:
+ record.newDocumentLink();
+ break;
+ }
+ }
+
+ /**
+ * Initialize the hyperlink by a HyperlinkRecord
record
+ *
+ * @param record
+ */
+ protected HSSFHyperlink( HyperlinkRecord record )
+ {
+ this.record = record;
+ }
+
+ /**
+ * Return the row of the first cell that contains the hyperlink
+ *
+ * @return the 0-based row of the cell that contains the hyperlink
+ */
+ public int getFirstRow(){
+ return record.getFirstRow();
+ }
+
+ /**
+ * Set the row of the first cell that contains the hyperlink
+ *
+ * @param row the 0-based row of the first cell that contains the hyperlink
+ */
+ public void setFirstRow(int row){
+ record.setFirstRow(row);
+ }
+
+ /**
+ * Return the row of the last cell that contains the hyperlink
+ *
+ * @return the 0-based row of the last cell that contains the hyperlink
+ */
+ public int getLastRow(){
+ return record.getLastRow();
+ }
+
+ /**
+ * Set the row of the last cell that contains the hyperlink
+ *
+ * @param row the 0-based row of the last cell that contains the hyperlink
+ */
+ public void setLastRow(int row){
+ record.setLastRow(row);
+ }
+
+ /**
+ * Return the column of the first cell that contains the hyperlink
+ *
+ * @return the 0-based column of the first cell that contains the hyperlink
+ */
+ public int getFirstColumn(){
+ return record.getFirstColumn();
+ }
+
+ /**
+ * Set the column of the first cell that contains the hyperlink
+ *
+ * @param col the 0-based column of the first cell that contains the hyperlink
+ */
+ public void setFirstColumn(int col){
+ record.setFirstColumn((short)col);
+ }
+
+ /**
+ * Return the column of the last cell that contains the hyperlink
+ *
+ * @return the 0-based column of the last cell that contains the hyperlink
+ */
+ public int getLastColumn(){
+ return record.getLastColumn();
+ }
+
+ /**
+ * Set the column of the last cell that contains the hyperlink
+ *
+ * @param col the 0-based column of the last cell that contains the hyperlink
+ */
+ public void setLastColumn(int col){
+ record.setLastColumn((short)col);
+ }
+
+ /**
+ * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.
+ *
+ * @return the address of this hyperlink
+ */
+ public String getAddress(){
+ return record.getAddress();
+ }
+ public String getTextMark(){
+ return record.getTextMark();
+ }
+ public void setTextMark(String textMark) {
+ record.setTextMark(textMark);
+ }
+ public String getShortFilename(){
+ return record.getShortFilename();
+ }
+ public void setShortFilename(String shortFilename) {
+ record.setShortFilename(shortFilename);
+ }
+
+ /**
+ * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.
+ *
+ * @param address the address of this hyperlink
+ */
+ public void setAddress(String address){
+ record.setAddress(address);
+ }
+
+ /**
+ * Return text label for this hyperlink
+ *
+ * @return text to display
+ */
+ public String getLabel(){
+ return record.getLabel();
+ }
+
+ /**
+ * Sets text label for this hyperlink
+ *
+ * @param label text label for this hyperlink
+ */
+ public void setLabel(String label){
+ record.setLabel(label);
+ }
+
+ /**
+ * Return the type of this hyperlink
+ *
+ * @return the type of this hyperlink
+ */
+ public int getType(){
+ return link_type;
+ }
+}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
index ce6235a1a..ab539c22d 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
@@ -1,194 +1,193 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.usermodel;
-
-import org.apache.poi.hssf.model.Sheet;
-import org.apache.poi.hssf.record.CFRuleRecord;
-import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
-import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
-import org.apache.poi.ss.util.Region;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.SpreadsheetVersion;
-
-/**
- * The 'Conditional Formatting' facet of HSSFSheet
- *
- * @author Dmitriy Kumshayev
- */
-public final class HSSFSheetConditionalFormatting {
-
- private final HSSFSheet _sheet;
- private final ConditionalFormattingTable _conditionalFormattingTable;
-
- /* package */ HSSFSheetConditionalFormatting(HSSFSheet sheet) {
- _sheet = sheet;
- _conditionalFormattingTable = sheet.getSheet().getConditionalFormattingTable();
- }
-
- /**
- * A factory method allowing to create a conditional formatting rule
- * with a cell comparison operator
- * TODO - formulas containing cell references are currently not parsed properly
- *
- * @param comparisonOperation - a constant value from
- * {@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator}: - *
This method could be used to copy HSSFConditionalFormatting object - * from one sheet to another. For example: - *
- * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index); - * newSheet.addConditionalFormatting(cf); - *- * - * @param cf HSSFConditionalFormatting object - * @return index of the new Conditional Formatting object - */ - public int addConditionalFormatting( HSSFConditionalFormatting cf ) { - CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate(); - - return _conditionalFormattingTable.add(cfraClone); - } - /** - * @deprecated use CellRangeAddress instead of Region - */ - public int addConditionalFormatting(Region[] regions, HSSFConditionalFormattingRule[] cfRules) { - return addConditionalFormatting(Region.convertRegionsToCellRanges(regions), cfRules); - } - /** - * Allows to add a new Conditional Formatting set to the sheet. - * - * @param regions - list of rectangular regions to apply conditional formatting rules - * @param cfRules - set of up to three conditional formatting rules - * - * @return index of the newly created Conditional Formatting object - */ - public int addConditionalFormatting(CellRangeAddress[] regions, HSSFConditionalFormattingRule[] cfRules) { - if (regions == null) { - throw new IllegalArgumentException("regions must not be null"); - } - for(CellRangeAddress range : regions) range.validate(SpreadsheetVersion.EXCEL97); - - if (cfRules == null) { - throw new IllegalArgumentException("cfRules must not be null"); - } - if (cfRules.length == 0) { - throw new IllegalArgumentException("cfRules must not be empty"); - } - if (cfRules.length > 3) { - throw new IllegalArgumentException("Number of rules must not exceed 3"); - } - - CFRuleRecord[] rules = new CFRuleRecord[cfRules.length]; - for (int i = 0; i != cfRules.length; i++) { - rules[i] = cfRules[i].getCfRuleRecord(); - } - CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules); - return _conditionalFormattingTable.add(cfra); - } - - public int addConditionalFormatting(CellRangeAddress[] regions, - HSSFConditionalFormattingRule rule1) - { - return addConditionalFormatting(regions, - new HSSFConditionalFormattingRule[] - { - rule1 - }); - } - - public int addConditionalFormatting(CellRangeAddress[] regions, - HSSFConditionalFormattingRule rule1, - HSSFConditionalFormattingRule rule2) - { - return addConditionalFormatting(regions, - new HSSFConditionalFormattingRule[] - { - rule1, rule2 - }); - } - - /** - * gets Conditional Formatting object at a particular index - * - * @param index - * of the Conditional Formatting object to fetch - * @return Conditional Formatting object - */ - public HSSFConditionalFormatting getConditionalFormattingAt(int index) { - CFRecordsAggregate cf = _conditionalFormattingTable.get(index); - if (cf == null) { - return null; - } - return new HSSFConditionalFormatting(_sheet.getWorkbook(), cf); - } - - /** - * @return number of Conditional Formatting objects of the sheet - */ - public int getNumConditionalFormattings() { - return _conditionalFormattingTable.size(); - } - - /** - * removes a Conditional Formatting object by index - * @param index of a Conditional Formatting object to remove - */ - public void removeConditionalFormatting(int index) { - _conditionalFormattingTable.remove(index); - } -} +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.hssf.usermodel; + +import org.apache.poi.hssf.record.CFRuleRecord; +import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate; +import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable; +import org.apache.poi.ss.util.Region; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.SpreadsheetVersion; + +/** + * The 'Conditional Formatting' facet of HSSFSheet + * + * @author Dmitriy Kumshayev + */ +public final class HSSFSheetConditionalFormatting { + + private final HSSFSheet _sheet; + private final ConditionalFormattingTable _conditionalFormattingTable; + + /* package */ HSSFSheetConditionalFormatting(HSSFSheet sheet) { + _sheet = sheet; + _conditionalFormattingTable = sheet.getSheet().getConditionalFormattingTable(); + } + + /** + * A factory method allowing to create a conditional formatting rule + * with a cell comparison operator + * TODO - formulas containing cell references are currently not parsed properly + * + * @param comparisonOperation - a constant value from + * {@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator}:
+ *
This method could be used to copy HSSFConditionalFormatting object + * from one sheet to another. For example: + *
+ * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index); + * newSheet.addConditionalFormatting(cf); + *+ * + * @param cf HSSFConditionalFormatting object + * @return index of the new Conditional Formatting object + */ + public int addConditionalFormatting( HSSFConditionalFormatting cf ) { + CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate(); + + return _conditionalFormattingTable.add(cfraClone); + } + /** + * @deprecated use CellRangeAddress instead of Region + */ + public int addConditionalFormatting(Region[] regions, HSSFConditionalFormattingRule[] cfRules) { + return addConditionalFormatting(Region.convertRegionsToCellRanges(regions), cfRules); + } + /** + * Allows to add a new Conditional Formatting set to the sheet. + * + * @param regions - list of rectangular regions to apply conditional formatting rules + * @param cfRules - set of up to three conditional formatting rules + * + * @return index of the newly created Conditional Formatting object + */ + public int addConditionalFormatting(CellRangeAddress[] regions, HSSFConditionalFormattingRule[] cfRules) { + if (regions == null) { + throw new IllegalArgumentException("regions must not be null"); + } + for(CellRangeAddress range : regions) range.validate(SpreadsheetVersion.EXCEL97); + + if (cfRules == null) { + throw new IllegalArgumentException("cfRules must not be null"); + } + if (cfRules.length == 0) { + throw new IllegalArgumentException("cfRules must not be empty"); + } + if (cfRules.length > 3) { + throw new IllegalArgumentException("Number of rules must not exceed 3"); + } + + CFRuleRecord[] rules = new CFRuleRecord[cfRules.length]; + for (int i = 0; i != cfRules.length; i++) { + rules[i] = cfRules[i].getCfRuleRecord(); + } + CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules); + return _conditionalFormattingTable.add(cfra); + } + + public int addConditionalFormatting(CellRangeAddress[] regions, + HSSFConditionalFormattingRule rule1) + { + return addConditionalFormatting(regions, + new HSSFConditionalFormattingRule[] + { + rule1 + }); + } + + public int addConditionalFormatting(CellRangeAddress[] regions, + HSSFConditionalFormattingRule rule1, + HSSFConditionalFormattingRule rule2) + { + return addConditionalFormatting(regions, + new HSSFConditionalFormattingRule[] + { + rule1, rule2 + }); + } + + /** + * gets Conditional Formatting object at a particular index + * + * @param index + * of the Conditional Formatting object to fetch + * @return Conditional Formatting object + */ + public HSSFConditionalFormatting getConditionalFormattingAt(int index) { + CFRecordsAggregate cf = _conditionalFormattingTable.get(index); + if (cf == null) { + return null; + } + return new HSSFConditionalFormatting(_sheet.getWorkbook(), cf); + } + + /** + * @return number of Conditional Formatting objects of the sheet + */ + public int getNumConditionalFormattings() { + return _conditionalFormattingTable.size(); + } + + /** + * removes a Conditional Formatting object by index + * @param index of a Conditional Formatting object to remove + */ + public void removeConditionalFormatting(int index) { + _conditionalFormattingTable.remove(index); + } +} diff --git a/src/java/org/apache/poi/hssf/util/CellRangeAddress.java b/src/java/org/apache/poi/hssf/util/CellRangeAddress.java index da8d56c09..d2316fe88 100644 --- a/src/java/org/apache/poi/hssf/util/CellRangeAddress.java +++ b/src/java/org/apache/poi/hssf/util/CellRangeAddress.java @@ -1,38 +1,38 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.util; - -import org.apache.poi.hssf.record.RecordInputStream; -import org.apache.poi.hssf.record.SelectionRecord; - -/** - * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address' - * - * Note - {@link SelectionRecord} uses the BIFF5 version of this structure - * @deprecated use {@link org.apache.poi.ss.util.CellRangeAddress} - * @author Dragos Buleandra (dragos.buleandra@trade2b.ro) - */ -public class CellRangeAddress extends org.apache.poi.ss.util.CellRangeAddress { - - public CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol) { - super(firstRow, lastRow, firstCol, lastCol); - } - public CellRangeAddress(RecordInputStream in) { - super(in); - } -} +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.hssf.util; + +import org.apache.poi.hssf.record.RecordInputStream; +import org.apache.poi.hssf.record.SelectionRecord; + +/** + * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address' + * + * Note - {@link SelectionRecord} uses the BIFF5 version of this structure + * @deprecated use {@link org.apache.poi.ss.util.CellRangeAddress} + * @author Dragos Buleandra (dragos.buleandra@trade2b.ro) + */ +public class CellRangeAddress extends org.apache.poi.ss.util.CellRangeAddress { + + public CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol) { + super(firstRow, lastRow, firstCol, lastCol); + } + public CellRangeAddress(RecordInputStream in) { + super(in); + } +} diff --git a/src/java/org/apache/poi/hssf/util/CellRangeAddress8Bit.java b/src/java/org/apache/poi/hssf/util/CellRangeAddress8Bit.java index 43de0cf28..cada8bfe5 100644 --- a/src/java/org/apache/poi/hssf/util/CellRangeAddress8Bit.java +++ b/src/java/org/apache/poi/hssf/util/CellRangeAddress8Bit.java @@ -1,73 +1,73 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.util; - -import org.apache.poi.ss.util.CellRangeAddressBase; -import org.apache.poi.util.LittleEndianByteArrayOutputStream; -import org.apache.poi.util.LittleEndianInput; -import org.apache.poi.util.LittleEndianOutput; - -/** - * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address' - * - * Like {@link CellRangeAddress} except column fields are 8-bit. - * - * @author Josh Micich - */ -public final class CellRangeAddress8Bit extends CellRangeAddressBase { - - public static final int ENCODED_SIZE = 6; - - public CellRangeAddress8Bit(int firstRow, int lastRow, int firstCol, int lastCol) { - super(firstRow, lastRow, firstCol, lastCol); - } - - public CellRangeAddress8Bit(LittleEndianInput in) { - super(readUShortAndCheck(in), in.readUShort(), in.readUByte(), in.readUByte()); - } - - private static int readUShortAndCheck(LittleEndianInput in) { - if (in.available() < ENCODED_SIZE) { - // Ran out of data - throw new RuntimeException("Ran out of data reading CellRangeAddress"); - } - return in.readUShort(); - } - - /** - * @deprecated use {@link #serialize(LittleEndianOutput)} - */ - public int serialize(int offset, byte[] data) { - serialize(new LittleEndianByteArrayOutputStream(data, offset, ENCODED_SIZE)); - return ENCODED_SIZE; - } - public void serialize(LittleEndianOutput out) { - out.writeShort(getFirstRow()); - out.writeShort(getLastRow()); - out.writeByte(getFirstColumn()); - out.writeByte(getLastColumn()); - } - - public CellRangeAddress8Bit copy() { - return new CellRangeAddress8Bit(getFirstRow(), getLastRow(), getFirstColumn(), getLastColumn()); - } - - public static int getEncodedSize(int numberOfItems) { - return numberOfItems * ENCODED_SIZE; - } -} +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.hssf.util; + +import org.apache.poi.ss.util.CellRangeAddressBase; +import org.apache.poi.util.LittleEndianByteArrayOutputStream; +import org.apache.poi.util.LittleEndianInput; +import org.apache.poi.util.LittleEndianOutput; + +/** + * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address' + * + * Like {@link CellRangeAddress} except column fields are 8-bit. + * + * @author Josh Micich + */ +public final class CellRangeAddress8Bit extends CellRangeAddressBase { + + public static final int ENCODED_SIZE = 6; + + public CellRangeAddress8Bit(int firstRow, int lastRow, int firstCol, int lastCol) { + super(firstRow, lastRow, firstCol, lastCol); + } + + public CellRangeAddress8Bit(LittleEndianInput in) { + super(readUShortAndCheck(in), in.readUShort(), in.readUByte(), in.readUByte()); + } + + private static int readUShortAndCheck(LittleEndianInput in) { + if (in.available() < ENCODED_SIZE) { + // Ran out of data + throw new RuntimeException("Ran out of data reading CellRangeAddress"); + } + return in.readUShort(); + } + + /** + * @deprecated use {@link #serialize(LittleEndianOutput)} + */ + public int serialize(int offset, byte[] data) { + serialize(new LittleEndianByteArrayOutputStream(data, offset, ENCODED_SIZE)); + return ENCODED_SIZE; + } + public void serialize(LittleEndianOutput out) { + out.writeShort(getFirstRow()); + out.writeShort(getLastRow()); + out.writeByte(getFirstColumn()); + out.writeByte(getLastColumn()); + } + + public CellRangeAddress8Bit copy() { + return new CellRangeAddress8Bit(getFirstRow(), getLastRow(), getFirstColumn(), getLastColumn()); + } + + public static int getEncodedSize(int numberOfItems) { + return numberOfItems * ENCODED_SIZE; + } +} diff --git a/src/java/org/apache/poi/poifs/dev/POIFSDump.java b/src/java/org/apache/poi/poifs/dev/POIFSDump.java index 5028bab72..ace19d8d1 100755 --- a/src/java/org/apache/poi/poifs/dev/POIFSDump.java +++ b/src/java/org/apache/poi/poifs/dev/POIFSDump.java @@ -1,74 +1,74 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.poifs.dev; - -import org.apache.poi.poifs.filesystem.*; - -import java.io.FileInputStream; -import java.io.File; -import java.io.IOException; -import java.io.FileOutputStream; -import java.util.Iterator; - -/** - * - * Dump internal structure of a OLE2 file into file system - * - * @author Yegor Kozlov - */ -public class POIFSDump { - - public static void main(String[] args) throws Exception { - for (int i = 0; i < args.length; i++) { - System.out.println("Dumping " + args[i]); - FileInputStream is = new FileInputStream(args[i]); - POIFSFileSystem fs = new POIFSFileSystem(is); - is.close(); - - DirectoryEntry root = fs.getRoot(); - File file = new File(root.getName()); - file.mkdir(); - - dump(root, file); - } - } - - - public static void dump(DirectoryEntry root, File parent) throws IOException { - for(Iterator it = root.getEntries(); it.hasNext();){ - Entry entry = (Entry)it.next(); - if(entry instanceof DocumentNode){ - DocumentNode node = (DocumentNode)entry; - DocumentInputStream is = new DocumentInputStream(node); - byte[] bytes = new byte[node.getSize()]; - is.read(bytes); - is.close(); - - FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim())); - out.write(bytes); - out.close(); - } else if (entry instanceof DirectoryEntry){ - DirectoryEntry dir = (DirectoryEntry)entry; - File file = new File(parent, entry.getName()); - file.mkdir(); - dump(dir, file); - } else { - System.err.println("Skipping unsupported POIFS entry: " + entry); - } - } - } -} +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.poifs.dev; + +import org.apache.poi.poifs.filesystem.*; + +import java.io.FileInputStream; +import java.io.File; +import java.io.IOException; +import java.io.FileOutputStream; +import java.util.Iterator; + +/** + * + * Dump internal structure of a OLE2 file into file system + * + * @author Yegor Kozlov + */ +public class POIFSDump { + + public static void main(String[] args) throws Exception { + for (int i = 0; i < args.length; i++) { + System.out.println("Dumping " + args[i]); + FileInputStream is = new FileInputStream(args[i]); + POIFSFileSystem fs = new POIFSFileSystem(is); + is.close(); + + DirectoryEntry root = fs.getRoot(); + File file = new File(root.getName()); + file.mkdir(); + + dump(root, file); + } + } + + + public static void dump(DirectoryEntry root, File parent) throws IOException { + for(Iterator it = root.getEntries(); it.hasNext();){ + Entry entry = (Entry)it.next(); + if(entry instanceof DocumentNode){ + DocumentNode node = (DocumentNode)entry; + DocumentInputStream is = new DocumentInputStream(node); + byte[] bytes = new byte[node.getSize()]; + is.read(bytes); + is.close(); + + FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim())); + out.write(bytes); + out.close(); + } else if (entry instanceof DirectoryEntry){ + DirectoryEntry dir = (DirectoryEntry)entry; + File file = new File(parent, entry.getName()); + file.mkdir(); + dump(dir, file); + } else { + System.err.println("Skipping unsupported POIFS entry: " + entry); + } + } + } +} diff --git a/src/java/org/apache/poi/ss/SpreadsheetVersion.java b/src/java/org/apache/poi/ss/SpreadsheetVersion.java index 4a7b2bbe4..316e5af06 100755 --- a/src/java/org/apache/poi/ss/SpreadsheetVersion.java +++ b/src/java/org/apache/poi/ss/SpreadsheetVersion.java @@ -1,120 +1,119 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss; - -import org.apache.poi.ss.util.CellReference; - -/** - * This enum allows spreadsheets from multiple Excel versions to be handled by the common code. - * Properties of this enum correspond to attributes of the spreadsheet that are easily - * discernable to the user. It is not intended to deal with low-level issues like file formats. - * - * - * @author Josh Micich - * @author Yegor Kozlov - */ -public enum SpreadsheetVersion { - /** - * Excel97 format aka BIFF8 - *
getMaxRows() - 1
- */
- public int getLastRowIndex() {
- return _maxRows - 1;
- }
-
- /**
- * @return the maximum number of usable columns in each spreadsheet
- */
- public int getMaxColumns() {
- return _maxColumns;
- }
-
- /**
- * @return the last (maximum) valid column index, equals to getMaxColumns() - 1
- */
- public int getLastColumnIndex() {
- return _maxColumns - 1;
- }
-
- /**
- * @return the maximum number arguments that can be passed to a multi-arg
- * function (e.g. COUNTIF)
- */
- public int getMaxFunctionArgs() {
- return _maxFunctionArgs;
- }
-
- /**
- *
- * @return the maximum number of conditional format conditions on a cell
- */
- public int getMaxConditionalFormats() {
- return _maxCondFormats;
- }
-
- /**
- *
- * @return the last valid column index in a ALPHA-26 representation
- * ( IV
or XFD
).
- */
- public String getLastColumnName() {
- return CellReference.convertNumToColString(getLastColumnIndex());
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss;
+
+import org.apache.poi.ss.util.CellReference;
+
+/**
+ * This enum allows spreadsheets from multiple Excel versions to be handled by the common code.
+ * Properties of this enum correspond to attributes of the spreadsheet that are easily
+ * discernable to the user. It is not intended to deal with low-level issues like file formats.
+ *
+ *
+ * @author Josh Micich
+ * @author Yegor Kozlov
+ */
+public enum SpreadsheetVersion {
+ /**
+ * Excel97 format aka BIFF8
+ * getMaxRows() - 1
+ */
+ public int getLastRowIndex() {
+ return _maxRows - 1;
+ }
+
+ /**
+ * @return the maximum number of usable columns in each spreadsheet
+ */
+ public int getMaxColumns() {
+ return _maxColumns;
+ }
+
+ /**
+ * @return the last (maximum) valid column index, equals to getMaxColumns() - 1
+ */
+ public int getLastColumnIndex() {
+ return _maxColumns - 1;
+ }
+
+ /**
+ * @return the maximum number arguments that can be passed to a multi-arg function (e.g. COUNTIF)
+ */
+ public int getMaxFunctionArgs() {
+ return _maxFunctionArgs;
+ }
+
+ /**
+ *
+ * @return the maximum number of conditional format conditions on a cell
+ */
+ public int getMaxConditionalFormats() {
+ return _maxCondFormats;
+ }
+
+ /**
+ *
+ * @return the last valid column index in a ALPHA-26 representation
+ * (IV
or XFD
).
+ */
+ public String getLastColumnName() {
+ return CellReference.convertNumToColString(getLastColumnIndex());
+ }
+}
diff --git a/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java b/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java
index a9f79e9e6..186fe6e1c 100644
--- a/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java
+++ b/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java
@@ -1,77 +1,77 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.poi.hssf.record.formula.eval.ValueEval;
-
-/**
- * Stores details about the current evaluation of a cell.null
, (possibly empty) array of all cells directly used while
- * evaluating the formula of this frame.
- */
- private CellCacheEntry[] getSensitiveInputCells() {
- int nItems = _sensitiveInputCells.size();
- if (nItems < 1) {
- return CellCacheEntry.EMPTY_ARRAY;
- }
- CellCacheEntry[] result = new CellCacheEntry[nItems];
- _sensitiveInputCells.toArray(result);
- return result;
- }
- public void addUsedBlankCell(int bookIndex, int sheetIndex, int rowIndex, int columnIndex) {
- if (_usedBlankCellGroup == null) {
- _usedBlankCellGroup = new FormulaUsedBlankCellSet();
- }
- _usedBlankCellGroup.addCell(bookIndex, sheetIndex, rowIndex, columnIndex);
- }
-
- public void updateFormulaResult(ValueEval result) {
- _cce.updateFormulaResult(result, getSensitiveInputCells(), _usedBlankCellGroup);
- }
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
+/**
+ * Stores details about the current evaluation of a cell.null
, (possibly empty) array of all cells directly used while
+ * evaluating the formula of this frame.
+ */
+ private CellCacheEntry[] getSensitiveInputCells() {
+ int nItems = _sensitiveInputCells.size();
+ if (nItems < 1) {
+ return CellCacheEntry.EMPTY_ARRAY;
+ }
+ CellCacheEntry[] result = new CellCacheEntry[nItems];
+ _sensitiveInputCells.toArray(result);
+ return result;
+ }
+ public void addUsedBlankCell(int bookIndex, int sheetIndex, int rowIndex, int columnIndex) {
+ if (_usedBlankCellGroup == null) {
+ _usedBlankCellGroup = new FormulaUsedBlankCellSet();
+ }
+ _usedBlankCellGroup.addCell(bookIndex, sheetIndex, rowIndex, columnIndex);
+ }
+
+ public void updateFormulaResult(ValueEval result) {
+ _cce.updateFormulaResult(result, getSensitiveInputCells(), _usedBlankCellGroup);
+ }
+}
diff --git a/src/java/org/apache/poi/ss/formula/EvaluationName.java b/src/java/org/apache/poi/ss/formula/EvaluationName.java
index ae8624c7b..7d6688bb8 100644
--- a/src/java/org/apache/poi/ss/formula/EvaluationName.java
+++ b/src/java/org/apache/poi/ss/formula/EvaluationName.java
@@ -1,41 +1,41 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-import org.apache.poi.hssf.record.formula.NamePtg;
-import org.apache.poi.hssf.record.formula.Ptg;
-/**
- * Abstracts a name record for formula evaluation.null
if externSheetIndex refers to a sheet inside the current workbook
- */
- ExternalSheet getExternalSheet(int externSheetIndex);
- int convertFromExternSheetIndex(int externSheetIndex);
- EvaluationName getName(NamePtg namePtg);
- String resolveNameXText(NameXPtg ptg);
- Ptg[] getFormulaTokens(EvaluationCell cell);
-
- class ExternalSheet {
- private final String _workbookName;
- private final String _sheetName;
-
- public ExternalSheet(String workbookName, String sheetName) {
- _workbookName = workbookName;
- _sheetName = sheetName;
- }
- public String getWorkbookName() {
- return _workbookName;
- }
- public String getSheetName() {
- return _sheetName;
- }
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula;
+
+import org.apache.poi.hssf.record.formula.NamePtg;
+import org.apache.poi.hssf.record.formula.NameXPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * Abstracts a workbook for the purpose of formula evaluation.null
if externSheetIndex refers to a sheet inside the current workbook
+ */
+ ExternalSheet getExternalSheet(int externSheetIndex);
+ int convertFromExternSheetIndex(int externSheetIndex);
+ EvaluationName getName(NamePtg namePtg);
+ String resolveNameXText(NameXPtg ptg);
+ Ptg[] getFormulaTokens(EvaluationCell cell);
+
+ class ExternalSheet {
+ private final String _workbookName;
+ private final String _sheetName;
+
+ public ExternalSheet(String workbookName, String sheetName) {
+ _workbookName = workbookName;
+ _sheetName = sheetName;
+ }
+ public String getWorkbookName() {
+ return _workbookName;
+ }
+ public String getSheetName() {
+ return _sheetName;
+ }
+ }
+}
diff --git a/src/java/org/apache/poi/ss/formula/Formula.java b/src/java/org/apache/poi/ss/formula/Formula.java
index f2cef2cb4..0eb8a7f6d 100644
--- a/src/java/org/apache/poi/ss/formula/Formula.java
+++ b/src/java/org/apache/poi/ss/formula/Formula.java
@@ -1,197 +1,197 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-import java.util.Arrays;
-
-import org.apache.poi.hssf.record.ArrayRecord;
-import org.apache.poi.hssf.record.SharedFormulaRecord;
-import org.apache.poi.hssf.record.TableRecord;
-import org.apache.poi.hssf.record.formula.ExpPtg;
-import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.hssf.record.formula.TblPtg;
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.LittleEndianByteArrayInputStream;
-import org.apache.poi.util.LittleEndianInput;
-import org.apache.poi.util.LittleEndianOutput;
-
-/**
- * Encapsulates an encoded formula token array.
- *
- * @author Josh Micich
- */
-public class Formula {
-
- private static final Formula EMPTY = new Formula(new byte[0], 0);
-
- /** immutable */
- private final byte[] _byteEncoding;
- private final int _encodedTokenLen;
-
- private Formula(byte[] byteEncoding, int encodedTokenLen) {
- _byteEncoding = byteEncoding;
- _encodedTokenLen = encodedTokenLen;
- if (false) { // set to true to eagerly check Ptg decoding
- LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);
- Ptg.readTokens(encodedTokenLen, in);
- int nUnusedBytes = _byteEncoding.length - in.getReadIndex();
- if (nUnusedBytes > 0) {
- // TODO - this seems to occur when IntersectionPtg is present
- // This example file "IntersectionPtg.xls"
- // used by test: TestIntersectionPtg.testReading()
- // has 10 bytes unused at the end of the formula
- // 10 extra bytes are just 0x01 and 0x00
- System.out.println(nUnusedBytes + " unused bytes at end of formula");
- }
- }
- }
- /**
- * Convenience method for {@link #read(int, LittleEndianInput, int)}
- */
- public static Formula read(int encodedTokenLen, LittleEndianInput in) {
- return read(encodedTokenLen, in, encodedTokenLen);
- }
- /**
- * When there are no array constants present, encodedTokenLen==totalEncodedLen
- * @param encodedTokenLen number of bytes in the stream taken by the plain formula tokens
- * @param totalEncodedLen the total number of bytes in the formula (includes trailing encoding
- * for array constants, but does not include 2 bytes for initial ushort encodedTokenLen field.
- * @return A new formula object as read from the stream. Possibly empty, never null
.
- */
- public static Formula read(int encodedTokenLen, LittleEndianInput in, int totalEncodedLen) {
- byte[] byteEncoding = new byte[totalEncodedLen];
- in.readFully(byteEncoding);
- return new Formula(byteEncoding, encodedTokenLen);
- }
-
- public Ptg[] getTokens() {
- LittleEndianInput in = new LittleEndianByteArrayInputStream(_byteEncoding);
- return Ptg.readTokens(_encodedTokenLen, in);
- }
- /**
- * Writes The formula encoding is includes:
- * null
s OK.
- * @param ptgs may be null
- * @return Never null
(Possibly empty if the supplied ptgs is null
)
- */
- public static Formula create(Ptg[] ptgs) {
- if (ptgs == null || ptgs.length < 1) {
- return EMPTY;
- }
- int totalSize = Ptg.getEncodedSize(ptgs);
- byte[] encodedData = new byte[totalSize];
- Ptg.serializePtgs(ptgs, encodedData, 0);
- int encodedTokenLen = Ptg.getEncodedSizeWithoutArrayData(ptgs);
- return new Formula(encodedData, encodedTokenLen);
- }
- /**
- * Gets the {@link Ptg} array from the supplied {@link Formula}.
- * Handles null
s OK.
- *
- * @param formula may be null
- * @return possibly null
(if the supplied formula is null
)
- */
- public static Ptg[] getTokens(Formula formula) {
- if (formula == null) {
- return null;
- }
- return formula.getTokens();
- }
-
- public Formula copy() {
- // OK to return this because immutable
- return this;
- }
-
- /**
- * Gets the locator for the corresponding {@link SharedFormulaRecord}, {@link ArrayRecord} or
- * {@link TableRecord} if this formula belongs to such a grouping. The {@link CellReference}
- * returned by this method will match the top left corner of the range of that grouping.
- * The return value is usually not the same as the location of the cell containing this formula.
- *
- * @return the firstRow & firstColumn of an array formula or shared formula that this formula
- * belongs to. null
if this formula is not part of an array or shared formula.
- */
- public CellReference getExpReference() {
- byte[] data = _byteEncoding;
- if (data.length != 5) {
- // tExp and tTbl are always 5 bytes long, and the only ptg in the formula
- return null;
- }
- switch (data[0]) {
- case ExpPtg.sid:
- break;
- case TblPtg.sid:
- break;
- default:
- return null;
- }
- int firstRow = LittleEndian.getUShort(data, 1);
- int firstColumn = LittleEndian.getUShort(data, 3);
- return new CellReference(firstRow, firstColumn);
- }
- public boolean isSame(Formula other) {
- return Arrays.equals(_byteEncoding, other._byteEncoding);
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula;
+
+import java.util.Arrays;
+
+import org.apache.poi.hssf.record.ArrayRecord;
+import org.apache.poi.hssf.record.SharedFormulaRecord;
+import org.apache.poi.hssf.record.TableRecord;
+import org.apache.poi.hssf.record.formula.ExpPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.TblPtg;
+import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianByteArrayInputStream;
+import org.apache.poi.util.LittleEndianInput;
+import org.apache.poi.util.LittleEndianOutput;
+
+/**
+ * Encapsulates an encoded formula token array.
+ *
+ * @author Josh Micich
+ */
+public class Formula {
+
+ private static final Formula EMPTY = new Formula(new byte[0], 0);
+
+ /** immutable */
+ private final byte[] _byteEncoding;
+ private final int _encodedTokenLen;
+
+ private Formula(byte[] byteEncoding, int encodedTokenLen) {
+ _byteEncoding = byteEncoding;
+ _encodedTokenLen = encodedTokenLen;
+ if (false) { // set to true to eagerly check Ptg decoding
+ LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);
+ Ptg.readTokens(encodedTokenLen, in);
+ int nUnusedBytes = _byteEncoding.length - in.getReadIndex();
+ if (nUnusedBytes > 0) {
+ // TODO - this seems to occur when IntersectionPtg is present
+ // This example file "IntersectionPtg.xls"
+ // used by test: TestIntersectionPtg.testReading()
+ // has 10 bytes unused at the end of the formula
+ // 10 extra bytes are just 0x01 and 0x00
+ System.out.println(nUnusedBytes + " unused bytes at end of formula");
+ }
+ }
+ }
+ /**
+ * Convenience method for {@link #read(int, LittleEndianInput, int)}
+ */
+ public static Formula read(int encodedTokenLen, LittleEndianInput in) {
+ return read(encodedTokenLen, in, encodedTokenLen);
+ }
+ /**
+ * When there are no array constants present, encodedTokenLen==totalEncodedLen
+ * @param encodedTokenLen number of bytes in the stream taken by the plain formula tokens
+ * @param totalEncodedLen the total number of bytes in the formula (includes trailing encoding
+ * for array constants, but does not include 2 bytes for initial ushort encodedTokenLen field.
+ * @return A new formula object as read from the stream. Possibly empty, never null
.
+ */
+ public static Formula read(int encodedTokenLen, LittleEndianInput in, int totalEncodedLen) {
+ byte[] byteEncoding = new byte[totalEncodedLen];
+ in.readFully(byteEncoding);
+ return new Formula(byteEncoding, encodedTokenLen);
+ }
+
+ public Ptg[] getTokens() {
+ LittleEndianInput in = new LittleEndianByteArrayInputStream(_byteEncoding);
+ return Ptg.readTokens(_encodedTokenLen, in);
+ }
+ /**
+ * Writes The formula encoding is includes:
+ * null
s OK.
+ * @param ptgs may be null
+ * @return Never null
(Possibly empty if the supplied ptgs is null
)
+ */
+ public static Formula create(Ptg[] ptgs) {
+ if (ptgs == null || ptgs.length < 1) {
+ return EMPTY;
+ }
+ int totalSize = Ptg.getEncodedSize(ptgs);
+ byte[] encodedData = new byte[totalSize];
+ Ptg.serializePtgs(ptgs, encodedData, 0);
+ int encodedTokenLen = Ptg.getEncodedSizeWithoutArrayData(ptgs);
+ return new Formula(encodedData, encodedTokenLen);
+ }
+ /**
+ * Gets the {@link Ptg} array from the supplied {@link Formula}.
+ * Handles null
s OK.
+ *
+ * @param formula may be null
+ * @return possibly null
(if the supplied formula is null
)
+ */
+ public static Ptg[] getTokens(Formula formula) {
+ if (formula == null) {
+ return null;
+ }
+ return formula.getTokens();
+ }
+
+ public Formula copy() {
+ // OK to return this because immutable
+ return this;
+ }
+
+ /**
+ * Gets the locator for the corresponding {@link SharedFormulaRecord}, {@link ArrayRecord} or
+ * {@link TableRecord} if this formula belongs to such a grouping. The {@link CellReference}
+ * returned by this method will match the top left corner of the range of that grouping.
+ * The return value is usually not the same as the location of the cell containing this formula.
+ *
+ * @return the firstRow & firstColumn of an array formula or shared formula that this formula
+ * belongs to. null
if this formula is not part of an array or shared formula.
+ */
+ public CellReference getExpReference() {
+ byte[] data = _byteEncoding;
+ if (data.length != 5) {
+ // tExp and tTbl are always 5 bytes long, and the only ptg in the formula
+ return null;
+ }
+ switch (data[0]) {
+ case ExpPtg.sid:
+ break;
+ case TblPtg.sid:
+ break;
+ default:
+ return null;
+ }
+ int firstRow = LittleEndian.getUShort(data, 1);
+ int firstColumn = LittleEndian.getUShort(data, 3);
+ return new CellReference(firstRow, firstColumn);
+ }
+ public boolean isSame(Formula other) {
+ return Arrays.equals(_byteEncoding, other._byteEncoding);
+ }
+}
diff --git a/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java b/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java
index 2ecd69be9..83f7c99a9 100644
--- a/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java
+++ b/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java
@@ -1,55 +1,55 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-import org.apache.poi.hssf.record.formula.NameXPtg;
-import org.apache.poi.ss.SpreadsheetVersion;
-
-/**
- * Abstracts a workbook for the purpose of formula parsing.null
- * @return a human readable String
- */
- public static String toFormulaString(FormulaRenderingWorkbook book, Ptg[] ptgs) {
- if (ptgs == null || ptgs.length == 0) {
- throw new IllegalArgumentException("ptgs must not be null");
- }
- Stacknull
+ * @return a human readable String
+ */
+ public static String toFormulaString(FormulaRenderingWorkbook book, Ptg[] ptgs) {
+ if (ptgs == null || ptgs.length == 0) {
+ throw new IllegalArgumentException("ptgs must not be null");
+ }
+ Stacknull
if externSheetIndex refers to a sheet inside the current workbook
- */
- ExternalSheet getExternalSheet(int externSheetIndex);
- String getSheetNameByExternSheet(int externSheetIndex);
- String resolveNameXText(NameXPtg nameXPtg);
- String getNameText(NamePtg namePtg);
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula;
+
+import org.apache.poi.hssf.record.formula.NamePtg;
+import org.apache.poi.hssf.record.formula.NameXPtg;
+import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalSheet;
+
+/**
+ * Abstracts a workbook for the purpose of converting formula to text.null
if externSheetIndex refers to a sheet inside the current workbook
+ */
+ ExternalSheet getExternalSheet(int externSheetIndex);
+ String getSheetNameByExternSheet(int externSheetIndex);
+ String resolveNameXText(NameXPtg nameXPtg);
+ String getNameText(NamePtg namePtg);
+}
diff --git a/src/java/org/apache/poi/ss/formula/FormulaType.java b/src/java/org/apache/poi/ss/formula/FormulaType.java
index 3b47030d4..b77001990 100644
--- a/src/java/org/apache/poi/ss/formula/FormulaType.java
+++ b/src/java/org/apache/poi/ss/formula/FormulaType.java
@@ -1,40 +1,40 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-/**
- * Enumeration of various formula types.null
signifying that the cell is not present (or blank)
- * @return null
if the supplied cell is null
or blank
- */
- public ValueEval evaluate(String sheetName, int rowIndex, int columnIndex) {
- EvaluationCell cell = _sewb.getEvaluationCell(sheetName, rowIndex, columnIndex);
-
- switch (cell.getCellType()) {
- case HSSFCell.CELL_TYPE_BOOLEAN:
- return BoolEval.valueOf(cell.getBooleanCellValue());
- case HSSFCell.CELL_TYPE_ERROR:
- return ErrorEval.valueOf(cell.getErrorCellValue());
- case HSSFCell.CELL_TYPE_FORMULA:
- return _evaluator.evaluate(cell);
- case HSSFCell.CELL_TYPE_NUMERIC:
- return new NumberEval(cell.getNumericCellValue());
- case HSSFCell.CELL_TYPE_STRING:
- return new StringEval(cell.getStringCellValue());
- case HSSFCell.CELL_TYPE_BLANK:
- return null;
- }
- throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
- }
- /**
- * Coordinates several formula evaluators together so that formulas that involve external
- * references can be evaluated.
- * @param workbookNames the simple file names used to identify the workbooks in formulas
- * with external links (for example "MyData.xls" as used in a formula "[MyData.xls]Sheet1!A1")
- * @param evaluators all evaluators for the full set of workbooks required by the formulas.
- */
- public static void setupEnvironment(String[] workbookNames, ForkedEvaluator[] evaluators) {
- WorkbookEvaluator[] wbEvals = new WorkbookEvaluator[evaluators.length];
- for (int i = 0; i < wbEvals.length; i++) {
- wbEvals[i] = evaluators[i]._evaluator;
- }
- CollaboratingWorkbooksEnvironment.setup(workbookNames, wbEvals);
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula.eval.forked;
+
+import org.apache.poi.hssf.record.formula.eval.BoolEval;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.StringEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment;
+import org.apache.poi.ss.formula.EvaluationCell;
+import org.apache.poi.ss.formula.EvaluationWorkbook;
+import org.apache.poi.ss.formula.IStabilityClassifier;
+import org.apache.poi.ss.formula.WorkbookEvaluator;
+import org.apache.poi.ss.usermodel.Workbook;
+
+/**
+ * An alternative workbook evaluator that saves memory in situations where a single workbook is
+ * concurrently and independently evaluated many times. With standard formula evaluation, around
+ * 90% of memory consumption is due to loading of the {@link HSSFWorkbook} or {@link org.apache.poi.xssf.usermodel.XSSFWorkbook}.
+ * This class enables a 'master workbook' to be loaded just once and shared between many evaluation
+ * clients. Each evaluation client creates its own {@link ForkedEvaluator} and can set cell values
+ * that will be used for local evaluations (and don't disturb evaluations on other evaluators).
+ *
+ * @author Josh Micich
+ */
+public final class ForkedEvaluator {
+
+ private WorkbookEvaluator _evaluator;
+ private ForkedEvaluationWorkbook _sewb;
+
+ private ForkedEvaluator(EvaluationWorkbook masterWorkbook, IStabilityClassifier stabilityClassifier) {
+ _sewb = new ForkedEvaluationWorkbook(masterWorkbook);
+ _evaluator = new WorkbookEvaluator(_sewb, stabilityClassifier);
+ }
+ private static EvaluationWorkbook createEvaluationWorkbook(Workbook wb) {
+ if (wb instanceof HSSFWorkbook) {
+ return HSSFEvaluationWorkbook.create((HSSFWorkbook) wb);
+ }
+// TODO rearrange POI build to allow this
+// if (wb instanceof XSSFWorkbook) {
+// return XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
+// }
+ throw new IllegalArgumentException("Unexpected workbook type (" + wb.getClass().getName() + ")");
+ }
+ public static ForkedEvaluator create(Workbook wb, IStabilityClassifier stabilityClassifier) {
+ return new ForkedEvaluator(createEvaluationWorkbook(wb), stabilityClassifier);
+ }
+
+ /**
+ * Sets the specified cell to the supplied value
+ * @param sheetName the name of the sheet containing the cell
+ * @param rowIndex zero based
+ * @param columnIndex zero based
+ */
+ public void updateCell(String sheetName, int rowIndex, int columnIndex, ValueEval value) {
+
+ ForkedEvaluationCell cell = _sewb.getOrCreateUpdatableCell(sheetName, rowIndex, columnIndex);
+ cell.setValue(value);
+ _evaluator.notifyUpdateCell(cell);
+ }
+ /**
+ * Copies the values of all updated cells (modified by calls to {@link
+ * #updateCell(String, int, int, ValueEval)}) to the supplied workbook.null
signifying that the cell is not present (or blank)
+ * @return null
if the supplied cell is null
or blank
+ */
+ public ValueEval evaluate(String sheetName, int rowIndex, int columnIndex) {
+ EvaluationCell cell = _sewb.getEvaluationCell(sheetName, rowIndex, columnIndex);
+
+ switch (cell.getCellType()) {
+ case HSSFCell.CELL_TYPE_BOOLEAN:
+ return BoolEval.valueOf(cell.getBooleanCellValue());
+ case HSSFCell.CELL_TYPE_ERROR:
+ return ErrorEval.valueOf(cell.getErrorCellValue());
+ case HSSFCell.CELL_TYPE_FORMULA:
+ return _evaluator.evaluate(cell);
+ case HSSFCell.CELL_TYPE_NUMERIC:
+ return new NumberEval(cell.getNumericCellValue());
+ case HSSFCell.CELL_TYPE_STRING:
+ return new StringEval(cell.getStringCellValue());
+ case HSSFCell.CELL_TYPE_BLANK:
+ return null;
+ }
+ throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
+ }
+ /**
+ * Coordinates several formula evaluators together so that formulas that involve external
+ * references can be evaluated.
+ * @param workbookNames the simple file names used to identify the workbooks in formulas
+ * with external links (for example "MyData.xls" as used in a formula "[MyData.xls]Sheet1!A1")
+ * @param evaluators all evaluators for the full set of workbooks required by the formulas.
+ */
+ public static void setupEnvironment(String[] workbookNames, ForkedEvaluator[] evaluators) {
+ WorkbookEvaluator[] wbEvals = new WorkbookEvaluator[evaluators.length];
+ for (int i = 0; i < wbEvals.length; i++) {
+ wbEvals[i] = evaluators[i]._evaluator;
+ }
+ CollaboratingWorkbooksEnvironment.setup(workbookNames, wbEvals);
+ }
+}
diff --git a/src/java/org/apache/poi/ss/usermodel/CellValue.java b/src/java/org/apache/poi/ss/usermodel/CellValue.java
index 705f55710..664f10056 100644
--- a/src/java/org/apache/poi/ss/usermodel/CellValue.java
+++ b/src/java/org/apache/poi/ss/usermodel/CellValue.java
@@ -1,114 +1,114 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.usermodel;
-
-import org.apache.poi.hssf.record.formula.eval.ErrorEval;
-import org.apache.poi.ss.usermodel.Cell;
-
-/**
- * Mimics the 'data view' of a cell. This allows formula evaluator
- * to return a CellValue instead of precasting the value to String
- * or Number or boolean type.
- * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- */
-public final class CellValue {
- public static final CellValue TRUE = new CellValue(Cell.CELL_TYPE_BOOLEAN, 0.0, true, null, 0);
- public static final CellValue FALSE= new CellValue(Cell.CELL_TYPE_BOOLEAN, 0.0, false, null, 0);
-
- private final int _cellType;
- private final double _numberValue;
- private final boolean _booleanValue;
- private final String _textValue;
- private final int _errorCode;
-
- private CellValue(int cellType, double numberValue, boolean booleanValue,
- String textValue, int errorCode) {
- _cellType = cellType;
- _numberValue = numberValue;
- _booleanValue = booleanValue;
- _textValue = textValue;
- _errorCode = errorCode;
- }
-
-
- public CellValue(double numberValue) {
- this(Cell.CELL_TYPE_NUMERIC, numberValue, false, null, 0);
- }
- public static CellValue valueOf(boolean booleanValue) {
- return booleanValue ? TRUE : FALSE;
- }
- public CellValue(String stringValue) {
- this(Cell.CELL_TYPE_STRING, 0.0, false, stringValue, 0);
- }
- public static CellValue getError(int errorCode) {
- return new CellValue(Cell.CELL_TYPE_ERROR, 0.0, false, null, errorCode);
- }
-
-
- /**
- * @return Returns the booleanValue.
- */
- public boolean getBooleanValue() {
- return _booleanValue;
- }
- /**
- * @return Returns the numberValue.
- */
- public double getNumberValue() {
- return _numberValue;
- }
- /**
- * @return Returns the stringValue.
- */
- public String getStringValue() {
- return _textValue;
- }
- /**
- * @return Returns the cellType.
- */
- public int getCellType() {
- return _cellType;
- }
- /**
- * @return Returns the errorValue.
- */
- public byte getErrorValue() {
- return (byte) _errorCode;
- }
- public String toString() {
- StringBuffer sb = new StringBuffer(64);
- sb.append(getClass().getName()).append(" [");
- sb.append(formatAsString());
- sb.append("]");
- return sb.toString();
- }
-
- public String formatAsString() {
- switch (_cellType) {
- case Cell.CELL_TYPE_NUMERIC:
- return String.valueOf(_numberValue);
- case Cell.CELL_TYPE_STRING:
- return '"' + _textValue + '"';
- case Cell.CELL_TYPE_BOOLEAN:
- return _booleanValue ? "TRUE" : "FALSE";
- case Cell.CELL_TYPE_ERROR:
- return ErrorEval.getText(_errorCode);
- }
- return "- * Specifies that the current drawing shall move and - * resize to maintain its row and column anchors (i.e. the - * object is anchored to the actual from and to row and column) - *
- */ - public static final int MOVE_AND_RESIZE = 0; - - /** - * Move With Cells but Do Not Resize - *- * Specifies that the current drawing shall move with its - * row and column (i.e. the object is anchored to the - * actual from row and column), but that the size shall remain absolute. - *
- *- * If additional rows/columns are added between the from and to locations of the drawing, - * the drawing shall move its to anchors as needed to maintain this same absolute size. - *
- */ - public static final int MOVE_DONT_RESIZE = 2; - - /** - * Do Not Move or Resize With Underlying Rows/Columns - *- * Specifies that the current start and end positions shall - * be maintained with respect to the distances from the - * absolute start point of the worksheet. - *
- *- * If additional rows/columns are added before the - * drawing, the drawing shall move its anchors as needed - * to maintain this same absolute position. - *
- */ - public static final int DONT_MOVE_AND_RESIZE = 3; - - /** - * Returns the column (0 based) of the first cell. - * - * @return 0-based column of the first cell. - */ - public short getCol1(); - - /** - * Sets the column (0 based) of the first cell. - * - * @param col1 0-based column of the first cell. - */ - public void setCol1(int col1); - - /** - * Returns the column (0 based) of the second cell. - * - * @return 0-based column of the second cell. - */ - public short getCol2(); - - /** - * Returns the column (0 based) of the second cell. - * - * @param col2 0-based column of the second cell. - */ - public void setCol2(int col2); - - /** - * Returns the row (0 based) of the first cell. - * - * @return 0-based row of the first cell. - */ - public int getRow1(); - - /** - * Returns the row (0 based) of the first cell. - * - * @param row1 0-based row of the first cell. - */ - public void setRow1(int row1); - - /** - * Returns the row (0 based) of the second cell. - * - * @return 0-based row of the second cell. - */ - public int getRow2(); - - /** - * Returns the row (0 based) of the first cell. - * - * @param row2 0-based row of the first cell. - */ - public void setRow2(int row2); - - /** - * Returns the x coordinate within the first cell - * - * @return the x coordinate within the first cell - */ - public int getDx1(); - - /** - * Sets the x coordinate within the first cell - * - * @param dx1 the x coordinate within the first cell - */ - public void setDx1(int dx1); - - /** - * Returns the y coordinate within the first cell - * - * @return the y coordinate within the first cell - */ - public int getDy1(); - - /** - * Sets the y coordinate within the first cell - * - * @param dy1 the y coordinate within the first cell - */ - public void setDy1(int dy1); - - /** - * Sets the y coordinate within the second cell - * - * @return the y coordinate within the second cell - */ - public int getDy2(); - - /** - * Sets the y coordinate within the second cell - * - * @param dy2 the y coordinate within the second cell - */ - public void setDy2(int dy2); - - /** - * Returns the x coordinate within the second cell - * - * @return the x coordinate within the second cell - */ - public int getDx2(); - - /** - * Sets the x coordinate within the second cell - * - * @param dx2 the x coordinate within the second cell - */ - public void setDx2(int dx2); - - - /** - * Sets the anchor type - *- * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. - *
- * @param anchorType the anchor type - * @see #MOVE_AND_RESIZE - * @see #MOVE_DONT_RESIZE - * @see #DONT_MOVE_AND_RESIZE - */ - public void setAnchorType( int anchorType ); - - /** - * Gets the anchor type - *- * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. - *
- * @return the anchor type - * @see #MOVE_AND_RESIZE - * @see #MOVE_DONT_RESIZE - * @see #DONT_MOVE_AND_RESIZE - */ - public int getAnchorType(); - -} +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.ss.usermodel; + +/** + * A client anchor is attached to an excel worksheet. It anchors against a + * top-left and bottom-right cell. + * + * @author Yegor Kozlov + */ +public interface ClientAnchor { + /** + * Move and Resize With Anchor Cells + *+ * Specifies that the current drawing shall move and + * resize to maintain its row and column anchors (i.e. the + * object is anchored to the actual from and to row and column) + *
+ */ + public static final int MOVE_AND_RESIZE = 0; + + /** + * Move With Cells but Do Not Resize + *+ * Specifies that the current drawing shall move with its + * row and column (i.e. the object is anchored to the + * actual from row and column), but that the size shall remain absolute. + *
+ *+ * If additional rows/columns are added between the from and to locations of the drawing, + * the drawing shall move its to anchors as needed to maintain this same absolute size. + *
+ */ + public static final int MOVE_DONT_RESIZE = 2; + + /** + * Do Not Move or Resize With Underlying Rows/Columns + *+ * Specifies that the current start and end positions shall + * be maintained with respect to the distances from the + * absolute start point of the worksheet. + *
+ *+ * If additional rows/columns are added before the + * drawing, the drawing shall move its anchors as needed + * to maintain this same absolute position. + *
+ */ + public static final int DONT_MOVE_AND_RESIZE = 3; + + /** + * Returns the column (0 based) of the first cell. + * + * @return 0-based column of the first cell. + */ + public short getCol1(); + + /** + * Sets the column (0 based) of the first cell. + * + * @param col1 0-based column of the first cell. + */ + public void setCol1(int col1); + + /** + * Returns the column (0 based) of the second cell. + * + * @return 0-based column of the second cell. + */ + public short getCol2(); + + /** + * Returns the column (0 based) of the second cell. + * + * @param col2 0-based column of the second cell. + */ + public void setCol2(int col2); + + /** + * Returns the row (0 based) of the first cell. + * + * @return 0-based row of the first cell. + */ + public int getRow1(); + + /** + * Returns the row (0 based) of the first cell. + * + * @param row1 0-based row of the first cell. + */ + public void setRow1(int row1); + + /** + * Returns the row (0 based) of the second cell. + * + * @return 0-based row of the second cell. + */ + public int getRow2(); + + /** + * Returns the row (0 based) of the first cell. + * + * @param row2 0-based row of the first cell. + */ + public void setRow2(int row2); + + /** + * Returns the x coordinate within the first cell + * + * @return the x coordinate within the first cell + */ + public int getDx1(); + + /** + * Sets the x coordinate within the first cell + * + * @param dx1 the x coordinate within the first cell + */ + public void setDx1(int dx1); + + /** + * Returns the y coordinate within the first cell + * + * @return the y coordinate within the first cell + */ + public int getDy1(); + + /** + * Sets the y coordinate within the first cell + * + * @param dy1 the y coordinate within the first cell + */ + public void setDy1(int dy1); + + /** + * Sets the y coordinate within the second cell + * + * @return the y coordinate within the second cell + */ + public int getDy2(); + + /** + * Sets the y coordinate within the second cell + * + * @param dy2 the y coordinate within the second cell + */ + public void setDy2(int dy2); + + /** + * Returns the x coordinate within the second cell + * + * @return the x coordinate within the second cell + */ + public int getDx2(); + + /** + * Sets the x coordinate within the second cell + * + * @param dx2 the x coordinate within the second cell + */ + public void setDx2(int dx2); + + + /** + * Sets the anchor type + *+ * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. + *
+ * @param anchorType the anchor type + * @see #MOVE_AND_RESIZE + * @see #MOVE_DONT_RESIZE + * @see #DONT_MOVE_AND_RESIZE + */ + public void setAnchorType( int anchorType ); + + /** + * Gets the anchor type + *+ * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. + *
+ * @return the anchor type + * @see #MOVE_AND_RESIZE + * @see #MOVE_DONT_RESIZE + * @see #DONT_MOVE_AND_RESIZE + */ + public int getAnchorType(); + +} diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java index 50e3690f7..f402a0cfa 100755 --- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java +++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java @@ -1,665 +1,665 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.ss.usermodel; - -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import java.util.*; -import java.text.*; - -/** - * DataFormatter contains methods for formatting the value stored in an - * Cell. This can be useful for reports and GUI presentations when you - * need to display data exactly as it appears in Excel. Supported formats - * include currency, SSN, percentages, decimals, dates, phone numbers, zip - * codes, etc. - *- * Internally, formats will be implemented using subclasses of {@link Format} - * such as {@link DecimalFormat} and {@link SimpleDateFormat}. Therefore the - * formats used by this class must obey the same pattern rules as these Format - * subclasses. This means that only legal number pattern characters ("0", "#", - * ".", "," etc.) may appear in number formats. Other characters can be - * inserted before or after the number pattern to form a - * prefix or suffix. - *
- *
- * For example the Excel pattern "$#,##0.00 "USD"_);($#,##0.00 "USD")"
- *
will be correctly formatted as "$1,000.00 USD" or "($1,000.00 USD)".
- * However the pattern "00-00-00"
is incorrectly formatted by
- * DecimalFormat as "000000--". For Excel formats that are not compatible with
- * DecimalFormat, you can provide your own custom {@link Format} implementation
- * via DataFormatter.addFormat(String,Format)
. The following
- * custom formats are already provided by this class:
- *
- *
- * If the Excel format pattern cannot be parsed successfully, then a default
- * format will be used. The default number format will mimic the Excel General
- * format: "#" for whole numbers and "#.##########" for decimal numbers. You
- * can override the default format pattern with
- * Returns the formatted value of a cell as a String regardless
- * of the cell type. If the Excel format pattern cannot be parsed then the
- * cell value will be formatted using a default format.
- * When passed a null or blank cell, this method will return an empty
- * String (""). Formulas in formula type cells will not be evaluated.
- *
- * Returns the formatted value of a cell as a String regardless
- * of the cell type. If the Excel format pattern cannot be parsed then the
- * cell value will be formatted using a default format.
- * When passed a null or blank cell, this method will return an empty
- * String (""). Formula cells will be evaluated using the given
- * {@link FormulaEvaluator} if the evaluator is non-null. If the
- * evaluator is null, then the formula String will be returned. The caller
- * is responsible for setting the currentRow on the evaluator
- *
- * Sets a default number format to be used when the Excel format cannot be
- * parsed successfully. Note: This is a fall back for when an error
- * occurs while parsing an Excel number format pattern. This will not
- * affect cells with the General format.
- *
- * The value that will be passed to the Format's format method (specified
- * by
- * The value that will be passed to the Format's format method (specified
- * by
+ * Internally, formats will be implemented using subclasses of {@link Format}
+ * such as {@link DecimalFormat} and {@link SimpleDateFormat}. Therefore the
+ * formats used by this class must obey the same pattern rules as these Format
+ * subclasses. This means that only legal number pattern characters ("0", "#",
+ * ".", "," etc.) may appear in number formats. Other characters can be
+ * inserted before or after the number pattern to form a
+ * prefix or suffix.
+ *
+ * For example the Excel pattern
+ * If the Excel format pattern cannot be parsed successfully, then a default
+ * format will be used. The default number format will mimic the Excel General
+ * format: "#" for whole numbers and "#.##########" for decimal numbers. You
+ * can override the default format pattern with
+ * Returns the formatted value of a cell as a String regardless
+ * of the cell type. If the Excel format pattern cannot be parsed then the
+ * cell value will be formatted using a default format.
+ * When passed a null or blank cell, this method will return an empty
+ * String (""). Formulas in formula type cells will not be evaluated.
+ *
+ * Returns the formatted value of a cell as a String regardless
+ * of the cell type. If the Excel format pattern cannot be parsed then the
+ * cell value will be formatted using a default format.
+ * When passed a null or blank cell, this method will return an empty
+ * String (""). Formula cells will be evaluated using the given
+ * {@link FormulaEvaluator} if the evaluator is non-null. If the
+ * evaluator is null, then the formula String will be returned. The caller
+ * is responsible for setting the currentRow on the evaluator
+ *
+ * Sets a default number format to be used when the Excel format cannot be
+ * parsed successfully. Note: This is a fall back for when an error
+ * occurs while parsing an Excel number format pattern. This will not
+ * affect cells with the General format.
+ *
+ * The value that will be passed to the Format's format method (specified
+ * by
+ * The value that will be passed to the Format's format method (specified
+ * by Example:
- * In the case of SUM(B1 C1), the space between B1 and C1 is treated as the binary
- * intersection operator, when a comma was intended. end example]
- * Example:
- * In the case of a function argument, text was expected, but a number was provided
- * Example:
- * If a formula contains a reference to a cell, and then the row or column containing that cell is deleted,
- * a #REF! error results. If a worksheet does not support 20,001 columns,
- * OFFSET(A1,0,20000) will result in a #REF! error.
- * Example:
- * XYZ/3, where XYZ is not a defined name. Total is & A10,
- * where neither Total nor is is a defined name. Presumably, "Total is " & A10
- * was intended. SUM(A1C10), where the range A1:C10 was intended.
- * Example:
- * Certain calls to ASIN, ATANH, FACT, and SQRT might result in domain errors.
- * Example: FACT(1000) might result in a range error. Example:
- * Some functions, such as SUMX2MY2, perform a series of operations on corresponding
- * elements in two arrays. If those arrays do not have the same number of elements, then
- * for some elements in the longer array, there are no corresponding elements in the
- * shorter one; that is, one or more values in the shorter array are not available.
- * Example:
+ * In the case of SUM(B1 C1), the space between B1 and C1 is treated as the binary
+ * intersection operator, when a comma was intended. end example]
+ * Example:
+ * In the case of a function argument, text was expected, but a number was provided
+ * Example:
+ * If a formula contains a reference to a cell, and then the row or column containing that cell is deleted,
+ * a #REF! error results. If a worksheet does not support 20,001 columns,
+ * OFFSET(A1,0,20000) will result in a #REF! error.
+ * Example:
+ * XYZ/3, where XYZ is not a defined name. Total is & A10,
+ * where neither Total nor is is a defined name. Presumably, "Total is " & A10
+ * was intended. SUM(A1C10), where the range A1:C10 was intended.
+ * Example:
+ * Certain calls to ASIN, ATANH, FACT, and SQRT might result in domain errors.
+ * Example: FACT(1000) might result in a range error. Example:
+ * Some functions, such as SUMX2MY2, perform a series of operations on corresponding
+ * elements in two arrays. If those arrays do not have the same number of elements, then
+ * for some elements in the longer array, there are no corresponding elements in the
+ * shorter one; that is, one or more values in the shorter array are not available.
+ *
- * Additional rules:
- *
- * When there is also an indent value to apply, both the left and right side of the cell
- * are padded by the indent value.
- * A 'word' is a set of characters with no space character in them. Two lines inside a cell are separated by a carriage return.
+ * Additional rules:
+ *
- * DataFormatter.setDefaultNumberFormat(Format)
. Note: the
- * default format will only be used when a Format cannot be created from the
- * cell's data format string.
- *
- * @author James May (james dot may at fmr dot com)
- *
- */
-public class DataFormatter {
-
- /** Pattern to find a number format: "0" or "#" */
- private static final Pattern numPattern = Pattern.compile("[0#]+");
-
- /** Pattern to find days of week as text "ddd...." */
- private static final Pattern daysAsText = Pattern.compile("([d]{3,})", Pattern.CASE_INSENSITIVE);
-
- /** Pattern to find "AM/PM" marker */
- private static final Pattern amPmPattern = Pattern.compile("((A|P)[M/P]*)", Pattern.CASE_INSENSITIVE);
-
- /** A regex to find patterns like [$$-1009] and [$?-452]. */
- private static final Pattern specialPatternGroup = Pattern.compile("(\\[\\$[^-\\]]*-[0-9A-Z]+\\])");
-
- /** General format for whole numbers. */
- private static final Format generalWholeNumFormat = new DecimalFormat("#");
-
- /** General format for decimal numbers. */
- private static final Format generalDecimalNumFormat = new DecimalFormat("#.##########");
-
- /** A default format to use when a number pattern cannot be parsed. */
- private Format defaultNumFormat;
-
- /**
- * A map to cache formats.
- * Mapnull
if the any of the
- * following is true:
- *
- *
- *
- * @param cell The cell to retrieve a Format for
- * @return A Format for the format String
- */
- private Format getFormat(Cell cell) {
- if ( cell.getCellStyle() == null) {
- return null;
- }
-
- int formatIndex = cell.getCellStyle().getDataFormat();
- String formatStr = cell.getCellStyle().getDataFormatString();
- if(formatStr == null || formatStr.trim().length() == 0) {
- return null;
- }
- return getFormat(cell.getNumericCellValue(), formatIndex, formatStr);
- }
-
- private Format getFormat(double cellValue, int formatIndex, String formatStr) {
- Format format = (Format)formats.get(formatStr);
- if (format != null) {
- return format;
- }
- if (formatStr.equals("General") || formatStr.equals("@")) {
- if (DataFormatter.isWholeNumber(cellValue)) {
- return generalWholeNumFormat;
- }
- return generalDecimalNumFormat;
- }
- format = createFormat(cellValue, formatIndex, formatStr);
- formats.put(formatStr, format);
- return format;
- }
-
- /**
- * Create and return a Format based on the format string from a cell's
- * style. If the pattern cannot be parsed, return a default pattern.
- *
- * @param cell The Excel cell
- * @return A Format representing the excel format. May return null.
- */
- public Format createFormat(Cell cell) {
-
- int formatIndex = cell.getCellStyle().getDataFormat();
- String formatStr = cell.getCellStyle().getDataFormatString();
- return createFormat(cell.getNumericCellValue(), formatIndex, formatStr);
- }
-
- private Format createFormat(double cellValue, int formatIndex, String sFormat) {
- // remove color formatting if present
- String formatStr = sFormat.replaceAll("\\[[a-zA-Z]*\\]", "");
-
- // try to extract special characters like currency
- Matcher m = specialPatternGroup.matcher(formatStr);
- while(m.find()) {
- String match = m.group();
- String symbol = match.substring(match.indexOf('$') + 1, match.indexOf('-'));
- if (symbol.indexOf('$') > -1) {
- StringBuffer sb = new StringBuffer();
- sb.append(symbol.substring(0, symbol.indexOf('$')));
- sb.append('\\');
- sb.append(symbol.substring(symbol.indexOf('$'), symbol.length()));
- symbol = sb.toString();
- }
- formatStr = m.replaceAll(symbol);
- m = specialPatternGroup.matcher(formatStr);
- }
-
- if(formatStr == null || formatStr.trim().length() == 0) {
- return getDefaultFormat(cellValue);
- }
-
-
- if(DateUtil.isADateFormat(formatIndex,formatStr) &&
- DateUtil.isValidExcelDate(cellValue)) {
- return createDateFormat(formatStr, cellValue);
- }
- if (numPattern.matcher(formatStr).find()) {
- return createNumberFormat(formatStr, cellValue);
- }
- // TODO - when does this occur?
- return null;
- }
-
- private Format createDateFormat(String pFormatStr, double cellValue) {
- String formatStr = pFormatStr;
- formatStr = formatStr.replaceAll("\\\\-","-");
- formatStr = formatStr.replaceAll("\\\\,",",");
- formatStr = formatStr.replaceAll("\\\\ "," ");
- formatStr = formatStr.replaceAll(";@", "");
- boolean hasAmPm = false;
- Matcher amPmMatcher = amPmPattern.matcher(formatStr);
- while (amPmMatcher.find()) {
- formatStr = amPmMatcher.replaceAll("@");
- hasAmPm = true;
- amPmMatcher = amPmPattern.matcher(formatStr);
- }
- formatStr = formatStr.replaceAll("@", "a");
-
-
- Matcher dateMatcher = daysAsText.matcher(formatStr);
- if (dateMatcher.find()) {
- String match = dateMatcher.group(0);
- formatStr = dateMatcher.replaceAll(match.toUpperCase().replaceAll("D", "E"));
- }
-
- // Convert excel date format to SimpleDateFormat.
- // Excel uses lower case 'm' for both minutes and months.
- // From Excel help:
- /*
- The "m" or "mm" code must appear immediately after the "h" or"hh"
- code or immediately before the "ss" code; otherwise, Microsoft
- Excel displays the month instead of minutes."
- */
-
- StringBuffer sb = new StringBuffer();
- char[] chars = formatStr.toCharArray();
- boolean mIsMonth = true;
- List ms = new ArrayList();
- for(int j=0; jtrue
if d is a whole number
- */
- private static boolean isWholeNumber(double d) {
- return d == Math.floor(d);
- }
-
- /**
- * Returns a default format for a cell.
- * @param cell The cell
- * @return a default format
- */
- public Format getDefaultFormat(Cell cell) {
- return getDefaultFormat(cell.getNumericCellValue());
- }
- private Format getDefaultFormat(double cellValue) {
- // for numeric cells try user supplied default
- if (defaultNumFormat != null) {
- return defaultNumFormat;
-
- // otherwise use general format
- }
- if (isWholeNumber(cellValue)){
- return generalWholeNumFormat;
- }
- return generalDecimalNumFormat;
- }
-
- /**
- * Returns the formatted value of an Excel date as a String based
- * on the cell's DataFormat
. i.e. "Thursday, January 02, 2003"
- * , "01/02/2003" , "02-Jan" , etc.
- *
- * @param cell The cell
- * @return a formatted date string
- */
- private String getFormattedDateString(Cell cell) {
- Format dateFormat = getFormat(cell);
- Date d = cell.getDateCellValue();
- if (dateFormat != null) {
- return dateFormat.format(d);
- }
- return d.toString();
- }
-
- /**
- * Returns the formatted value of an Excel number as a String
- * based on the cell's DataFormat
. Supported formats include
- * currency, percents, decimals, phone number, SSN, etc.:
- * "61.54%", "$100.00", "(800) 555-1234".
- *
- * @param cell The cell
- * @return a formatted number string
- */
- private String getFormattedNumberString(Cell cell) {
-
- Format numberFormat = getFormat(cell);
- double d = cell.getNumericCellValue();
- if (numberFormat == null) {
- return String.valueOf(d);
- }
- return numberFormat.format(new Double(d));
- }
-
- /**
- * Formats the given raw cell value, based on the supplied
- * format index and string, according to excel style rules.
- * @see #formatCellValue(Cell)
- */
- public String formatRawCellContents(double value, int formatIndex, String formatString) {
- // Is it a date?
- if(DateUtil.isADateFormat(formatIndex,formatString) &&
- DateUtil.isValidExcelDate(value)) {
-
- Format dateFormat = getFormat(value, formatIndex, formatString);
- Date d = DateUtil.getJavaDate(value);
- if (dateFormat == null) {
- return d.toString();
- }
- return dateFormat.format(d);
- }
- // else Number
- Format numberFormat = getFormat(value, formatIndex, formatString);
- if (numberFormat == null) {
- return String.valueOf(value);
- }
- return numberFormat.format(new Double(value));
- }
-
- /**
- * java.text.Format#format
) will be a double value from a
- * numeric cell. Therefore the code in the format method should expect a
- * Number
value.
- * java.text.Format#format
) will be a double value from a
- * numeric cell. Therefore the code in the format method should expect a
- * Number
value.
- * true
- */
- /* package */ static DecimalFormat createIntegerOnlyFormat(String fmt) {
- DecimalFormat result = new DecimalFormat(fmt);
- result.setParseIntegerOnly(true);
- return result;
- }
- /**
- * Format class for Excel's SSN format. This class mimics Excel's built-in
- * SSN formatting.
- *
- * @author James May
- */
- private static final class SSNFormat extends Format {
- public static final Format instance = new SSNFormat();
- private static final DecimalFormat df = createIntegerOnlyFormat("000000000");
- private SSNFormat() {
- // enforce singleton
- }
-
- /** Format a number as an SSN */
- public static String format(Number num) {
- String result = df.format(num);
- StringBuffer sb = new StringBuffer();
- sb.append(result.substring(0, 3)).append('-');
- sb.append(result.substring(3, 5)).append('-');
- sb.append(result.substring(5, 9));
- return sb.toString();
- }
-
- public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
- return toAppendTo.append(format((Number)obj));
- }
-
- public Object parseObject(String source, ParsePosition pos) {
- return df.parseObject(source, pos);
- }
- }
-
- /**
- * Format class for Excel Zip + 4 format. This class mimics Excel's
- * built-in formatting for Zip + 4.
- * @author James May
- */
- private static final class ZipPlusFourFormat extends Format {
- public static final Format instance = new ZipPlusFourFormat();
- private static final DecimalFormat df = createIntegerOnlyFormat("000000000");
- private ZipPlusFourFormat() {
- // enforce singleton
- }
-
- /** Format a number as Zip + 4 */
- public static String format(Number num) {
- String result = df.format(num);
- StringBuffer sb = new StringBuffer();
- sb.append(result.substring(0, 5)).append('-');
- sb.append(result.substring(5, 9));
- return sb.toString();
- }
-
- public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
- return toAppendTo.append(format((Number)obj));
- }
-
- public Object parseObject(String source, ParsePosition pos) {
- return df.parseObject(source, pos);
- }
- }
-
- /**
- * Format class for Excel phone number format. This class mimics Excel's
- * built-in phone number formatting.
- * @author James May
- */
- private static final class PhoneFormat extends Format {
- public static final Format instance = new PhoneFormat();
- private static final DecimalFormat df = createIntegerOnlyFormat("##########");
- private PhoneFormat() {
- // enforce singleton
- }
-
- /** Format a number as a phone number */
- public static String format(Number num) {
- String result = df.format(num);
- StringBuffer sb = new StringBuffer();
- String seg1, seg2, seg3;
- int len = result.length();
- if (len <= 4) {
- return result;
- }
-
- seg3 = result.substring(len - 4, len);
- seg2 = result.substring(Math.max(0, len - 7), len - 4);
- seg1 = result.substring(Math.max(0, len - 10), Math.max(0, len - 7));
-
- if(seg1 != null && seg1.trim().length() > 0) {
- sb.append('(').append(seg1).append(") ");
- }
- if(seg2 != null && seg2.trim().length() > 0) {
- sb.append(seg2).append('-');
- }
- sb.append(seg3);
- return sb.toString();
- }
-
- public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
- return toAppendTo.append(format((Number)obj));
- }
-
- public Object parseObject(String source, ParsePosition pos) {
- return df.parseObject(source, pos);
- }
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.ss.usermodel;
+
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import java.util.*;
+import java.text.*;
+
+/**
+ * DataFormatter contains methods for formatting the value stored in an
+ * Cell. This can be useful for reports and GUI presentations when you
+ * need to display data exactly as it appears in Excel. Supported formats
+ * include currency, SSN, percentages, decimals, dates, phone numbers, zip
+ * codes, etc.
+ * "$#,##0.00 "USD"_);($#,##0.00 "USD")"
+ *
will be correctly formatted as "$1,000.00 USD" or "($1,000.00 USD)".
+ * However the pattern "00-00-00"
is incorrectly formatted by
+ * DecimalFormat as "000000--". For Excel formats that are not compatible with
+ * DecimalFormat, you can provide your own custom {@link Format} implementation
+ * via DataFormatter.addFormat(String,Format)
. The following
+ * custom formats are already provided by this class:
+ *
+ *
+ *
+ *
+ * DataFormatter.setDefaultNumberFormat(Format)
. Note: the
+ * default format will only be used when a Format cannot be created from the
+ * cell's data format string.
+ *
+ * @author James May (james dot may at fmr dot com)
+ *
+ */
+public class DataFormatter {
+
+ /** Pattern to find a number format: "0" or "#" */
+ private static final Pattern numPattern = Pattern.compile("[0#]+");
+
+ /** Pattern to find days of week as text "ddd...." */
+ private static final Pattern daysAsText = Pattern.compile("([d]{3,})", Pattern.CASE_INSENSITIVE);
+
+ /** Pattern to find "AM/PM" marker */
+ private static final Pattern amPmPattern = Pattern.compile("((A|P)[M/P]*)", Pattern.CASE_INSENSITIVE);
+
+ /** A regex to find patterns like [$$-1009] and [$?-452]. */
+ private static final Pattern specialPatternGroup = Pattern.compile("(\\[\\$[^-\\]]*-[0-9A-Z]+\\])");
+
+ /** General format for whole numbers. */
+ private static final Format generalWholeNumFormat = new DecimalFormat("#");
+
+ /** General format for decimal numbers. */
+ private static final Format generalDecimalNumFormat = new DecimalFormat("#.##########");
+
+ /** A default format to use when a number pattern cannot be parsed. */
+ private Format defaultNumFormat;
+
+ /**
+ * A map to cache formats.
+ * Mapnull
if the any of the
+ * following is true:
+ *
+ *
+ *
+ * @param cell The cell to retrieve a Format for
+ * @return A Format for the format String
+ */
+ private Format getFormat(Cell cell) {
+ if ( cell.getCellStyle() == null) {
+ return null;
+ }
+
+ int formatIndex = cell.getCellStyle().getDataFormat();
+ String formatStr = cell.getCellStyle().getDataFormatString();
+ if(formatStr == null || formatStr.trim().length() == 0) {
+ return null;
+ }
+ return getFormat(cell.getNumericCellValue(), formatIndex, formatStr);
+ }
+
+ private Format getFormat(double cellValue, int formatIndex, String formatStr) {
+ Format format = (Format)formats.get(formatStr);
+ if (format != null) {
+ return format;
+ }
+ if (formatStr.equals("General") || formatStr.equals("@")) {
+ if (DataFormatter.isWholeNumber(cellValue)) {
+ return generalWholeNumFormat;
+ }
+ return generalDecimalNumFormat;
+ }
+ format = createFormat(cellValue, formatIndex, formatStr);
+ formats.put(formatStr, format);
+ return format;
+ }
+
+ /**
+ * Create and return a Format based on the format string from a cell's
+ * style. If the pattern cannot be parsed, return a default pattern.
+ *
+ * @param cell The Excel cell
+ * @return A Format representing the excel format. May return null.
+ */
+ public Format createFormat(Cell cell) {
+
+ int formatIndex = cell.getCellStyle().getDataFormat();
+ String formatStr = cell.getCellStyle().getDataFormatString();
+ return createFormat(cell.getNumericCellValue(), formatIndex, formatStr);
+ }
+
+ private Format createFormat(double cellValue, int formatIndex, String sFormat) {
+ // remove color formatting if present
+ String formatStr = sFormat.replaceAll("\\[[a-zA-Z]*\\]", "");
+
+ // try to extract special characters like currency
+ Matcher m = specialPatternGroup.matcher(formatStr);
+ while(m.find()) {
+ String match = m.group();
+ String symbol = match.substring(match.indexOf('$') + 1, match.indexOf('-'));
+ if (symbol.indexOf('$') > -1) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(symbol.substring(0, symbol.indexOf('$')));
+ sb.append('\\');
+ sb.append(symbol.substring(symbol.indexOf('$'), symbol.length()));
+ symbol = sb.toString();
+ }
+ formatStr = m.replaceAll(symbol);
+ m = specialPatternGroup.matcher(formatStr);
+ }
+
+ if(formatStr == null || formatStr.trim().length() == 0) {
+ return getDefaultFormat(cellValue);
+ }
+
+
+ if(DateUtil.isADateFormat(formatIndex,formatStr) &&
+ DateUtil.isValidExcelDate(cellValue)) {
+ return createDateFormat(formatStr, cellValue);
+ }
+ if (numPattern.matcher(formatStr).find()) {
+ return createNumberFormat(formatStr, cellValue);
+ }
+ // TODO - when does this occur?
+ return null;
+ }
+
+ private Format createDateFormat(String pFormatStr, double cellValue) {
+ String formatStr = pFormatStr;
+ formatStr = formatStr.replaceAll("\\\\-","-");
+ formatStr = formatStr.replaceAll("\\\\,",",");
+ formatStr = formatStr.replaceAll("\\\\ "," ");
+ formatStr = formatStr.replaceAll(";@", "");
+ boolean hasAmPm = false;
+ Matcher amPmMatcher = amPmPattern.matcher(formatStr);
+ while (amPmMatcher.find()) {
+ formatStr = amPmMatcher.replaceAll("@");
+ hasAmPm = true;
+ amPmMatcher = amPmPattern.matcher(formatStr);
+ }
+ formatStr = formatStr.replaceAll("@", "a");
+
+
+ Matcher dateMatcher = daysAsText.matcher(formatStr);
+ if (dateMatcher.find()) {
+ String match = dateMatcher.group(0);
+ formatStr = dateMatcher.replaceAll(match.toUpperCase().replaceAll("D", "E"));
+ }
+
+ // Convert excel date format to SimpleDateFormat.
+ // Excel uses lower case 'm' for both minutes and months.
+ // From Excel help:
+ /*
+ The "m" or "mm" code must appear immediately after the "h" or"hh"
+ code or immediately before the "ss" code; otherwise, Microsoft
+ Excel displays the month instead of minutes."
+ */
+
+ StringBuffer sb = new StringBuffer();
+ char[] chars = formatStr.toCharArray();
+ boolean mIsMonth = true;
+ List ms = new ArrayList();
+ for(int j=0; jtrue
if d is a whole number
+ */
+ private static boolean isWholeNumber(double d) {
+ return d == Math.floor(d);
+ }
+
+ /**
+ * Returns a default format for a cell.
+ * @param cell The cell
+ * @return a default format
+ */
+ public Format getDefaultFormat(Cell cell) {
+ return getDefaultFormat(cell.getNumericCellValue());
+ }
+ private Format getDefaultFormat(double cellValue) {
+ // for numeric cells try user supplied default
+ if (defaultNumFormat != null) {
+ return defaultNumFormat;
+
+ // otherwise use general format
+ }
+ if (isWholeNumber(cellValue)){
+ return generalWholeNumFormat;
+ }
+ return generalDecimalNumFormat;
+ }
+
+ /**
+ * Returns the formatted value of an Excel date as a String based
+ * on the cell's DataFormat
. i.e. "Thursday, January 02, 2003"
+ * , "01/02/2003" , "02-Jan" , etc.
+ *
+ * @param cell The cell
+ * @return a formatted date string
+ */
+ private String getFormattedDateString(Cell cell) {
+ Format dateFormat = getFormat(cell);
+ Date d = cell.getDateCellValue();
+ if (dateFormat != null) {
+ return dateFormat.format(d);
+ }
+ return d.toString();
+ }
+
+ /**
+ * Returns the formatted value of an Excel number as a String
+ * based on the cell's DataFormat
. Supported formats include
+ * currency, percents, decimals, phone number, SSN, etc.:
+ * "61.54%", "$100.00", "(800) 555-1234".
+ *
+ * @param cell The cell
+ * @return a formatted number string
+ */
+ private String getFormattedNumberString(Cell cell) {
+
+ Format numberFormat = getFormat(cell);
+ double d = cell.getNumericCellValue();
+ if (numberFormat == null) {
+ return String.valueOf(d);
+ }
+ return numberFormat.format(new Double(d));
+ }
+
+ /**
+ * Formats the given raw cell value, based on the supplied
+ * format index and string, according to excel style rules.
+ * @see #formatCellValue(Cell)
+ */
+ public String formatRawCellContents(double value, int formatIndex, String formatString) {
+ // Is it a date?
+ if(DateUtil.isADateFormat(formatIndex,formatString) &&
+ DateUtil.isValidExcelDate(value)) {
+
+ Format dateFormat = getFormat(value, formatIndex, formatString);
+ Date d = DateUtil.getJavaDate(value);
+ if (dateFormat == null) {
+ return d.toString();
+ }
+ return dateFormat.format(d);
+ }
+ // else Number
+ Format numberFormat = getFormat(value, formatIndex, formatString);
+ if (numberFormat == null) {
+ return String.valueOf(value);
+ }
+ return numberFormat.format(new Double(value));
+ }
+
+ /**
+ * java.text.Format#format
) will be a double value from a
+ * numeric cell. Therefore the code in the format method should expect a
+ * Number
value.
+ * java.text.Format#format
) will be a double value from a
+ * numeric cell. Therefore the code in the format method should expect a
+ * Number
value.
+ * true
+ */
+ /* package */ static DecimalFormat createIntegerOnlyFormat(String fmt) {
+ DecimalFormat result = new DecimalFormat(fmt);
+ result.setParseIntegerOnly(true);
+ return result;
+ }
+ /**
+ * Format class for Excel's SSN format. This class mimics Excel's built-in
+ * SSN formatting.
+ *
+ * @author James May
+ */
+ private static final class SSNFormat extends Format {
+ public static final Format instance = new SSNFormat();
+ private static final DecimalFormat df = createIntegerOnlyFormat("000000000");
+ private SSNFormat() {
+ // enforce singleton
+ }
+
+ /** Format a number as an SSN */
+ public static String format(Number num) {
+ String result = df.format(num);
+ StringBuffer sb = new StringBuffer();
+ sb.append(result.substring(0, 3)).append('-');
+ sb.append(result.substring(3, 5)).append('-');
+ sb.append(result.substring(5, 9));
+ return sb.toString();
+ }
+
+ public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
+ return toAppendTo.append(format((Number)obj));
+ }
+
+ public Object parseObject(String source, ParsePosition pos) {
+ return df.parseObject(source, pos);
+ }
+ }
+
+ /**
+ * Format class for Excel Zip + 4 format. This class mimics Excel's
+ * built-in formatting for Zip + 4.
+ * @author James May
+ */
+ private static final class ZipPlusFourFormat extends Format {
+ public static final Format instance = new ZipPlusFourFormat();
+ private static final DecimalFormat df = createIntegerOnlyFormat("000000000");
+ private ZipPlusFourFormat() {
+ // enforce singleton
+ }
+
+ /** Format a number as Zip + 4 */
+ public static String format(Number num) {
+ String result = df.format(num);
+ StringBuffer sb = new StringBuffer();
+ sb.append(result.substring(0, 5)).append('-');
+ sb.append(result.substring(5, 9));
+ return sb.toString();
+ }
+
+ public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
+ return toAppendTo.append(format((Number)obj));
+ }
+
+ public Object parseObject(String source, ParsePosition pos) {
+ return df.parseObject(source, pos);
+ }
+ }
+
+ /**
+ * Format class for Excel phone number format. This class mimics Excel's
+ * built-in phone number formatting.
+ * @author James May
+ */
+ private static final class PhoneFormat extends Format {
+ public static final Format instance = new PhoneFormat();
+ private static final DecimalFormat df = createIntegerOnlyFormat("##########");
+ private PhoneFormat() {
+ // enforce singleton
+ }
+
+ /** Format a number as a phone number */
+ public static String format(Number num) {
+ String result = df.format(num);
+ StringBuffer sb = new StringBuffer();
+ String seg1, seg2, seg3;
+ int len = result.length();
+ if (len <= 4) {
+ return result;
+ }
+
+ seg3 = result.substring(len - 4, len);
+ seg2 = result.substring(Math.max(0, len - 7), len - 4);
+ seg1 = result.substring(Math.max(0, len - 10), Math.max(0, len - 7));
+
+ if(seg1 != null && seg1.trim().length() > 0) {
+ sb.append('(').append(seg1).append(") ");
+ }
+ if(seg2 != null && seg2.trim().length() > 0) {
+ sb.append(seg2).append('-');
+ }
+ sb.append(seg3);
+ return sb.toString();
+ }
+
+ public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
+ return toAppendTo.append(format((Number)obj));
+ }
+
+ public Object parseObject(String source, ParsePosition pos) {
+ return df.parseObject(source, pos);
+ }
+ }
+}
diff --git a/src/java/org/apache/poi/ss/usermodel/Drawing.java b/src/java/org/apache/poi/ss/usermodel/Drawing.java
index c7b8dc0e8..b27c3098c 100755
--- a/src/java/org/apache/poi/ss/usermodel/Drawing.java
+++ b/src/java/org/apache/poi/ss/usermodel/Drawing.java
@@ -1,24 +1,24 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.ss.usermodel;
-
-/**
- * @author Yegor Kozlov
- */
-public interface Drawing {
- Picture createPicture(ClientAnchor anchor, int pictureIndex);
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.ss.usermodel;
+
+/**
+ * @author Yegor Kozlov
+ */
+public interface Drawing {
+ Picture createPicture(ClientAnchor anchor, int pictureIndex);
+}
diff --git a/src/java/org/apache/poi/ss/usermodel/FormulaError.java b/src/java/org/apache/poi/ss/usermodel/FormulaError.java
index 4f631c6ee..c3c43301e 100755
--- a/src/java/org/apache/poi/ss/usermodel/FormulaError.java
+++ b/src/java/org/apache/poi/ss/usermodel/FormulaError.java
@@ -1,140 +1,140 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.ss.usermodel;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * Enumerates error values in SpreadsheetML formula calculations.
- *
- * @author Yegor Kozlov
- */
-public enum FormulaError {
- /**
- * Intended to indicate when two areas are required to intersect, but do not.
- *
- *
- *
+ *
+ *
+ * When there is also an indent value to apply, both the left and right side of the cell + * are padded by the indent value. + *
+ *A 'word' is a set of characters with no space character in them.
+ *Two lines inside a cell are separated by a carriage return.
+ */ + DISTRIBUTED +} diff --git a/src/java/org/apache/poi/ss/usermodel/Picture.java b/src/java/org/apache/poi/ss/usermodel/Picture.java index dd6a8e7d3..e816c9ac1 100755 --- a/src/java/org/apache/poi/ss/usermodel/Picture.java +++ b/src/java/org/apache/poi/ss/usermodel/Picture.java @@ -1,42 +1,42 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.ss.usermodel; - -/** - * Repersents a picture in a SpreadsheetML document - * - * @author Yegor Kozlov - */ -public interface Picture { - - /** - * Reset the image to the original size. - */ - void resize(); - - /** - * Reset the image to the original size. - * - * @param scale the amount by which image dimensions are multiplied relative to the original size. - *resize(1.0)
sets the original size, resize(0.5)
resize to 50% of the original,
- * resize(2.0)
resizes to 200% of the original.
- */
- void resize(double scale);
-
- ClientAnchor getPreferredSize();
-
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.ss.usermodel;
+
+/**
+ * Repersents a picture in a SpreadsheetML document
+ *
+ * @author Yegor Kozlov
+ */
+public interface Picture {
+
+ /**
+ * Reset the image to the original size.
+ */
+ void resize();
+
+ /**
+ * Reset the image to the original size.
+ *
+ * @param scale the amount by which image dimensions are multiplied relative to the original size.
+ * resize(1.0)
sets the original size, resize(0.5)
resize to 50% of the original,
+ * resize(2.0)
resizes to 200% of the original.
+ */
+ void resize(double scale);
+
+ ClientAnchor getPreferredSize();
+
+}
diff --git a/src/java/org/apache/poi/ss/usermodel/ShapeTypes.java b/src/java/org/apache/poi/ss/usermodel/ShapeTypes.java
index ef8409340..3c5747ee5 100755
--- a/src/java/org/apache/poi/ss/usermodel/ShapeTypes.java
+++ b/src/java/org/apache/poi/ss/usermodel/ShapeTypes.java
@@ -1,212 +1,212 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.ss.usermodel;
-
-/**
- * All known types of automatic shapes in DrawingML
- *
- * @author Yegor Kozlov
- */
-public class ShapeTypes {
- public static final int LINE = 1;
- public static final int LINE_INV = 2;
- public static final int TRIANGLE = 3;
- public static final int RT_TRIANGLE = 4;
- public static final int RECT = 5;
- public static final int DIAMOND = 6;
- public static final int PARALLELOGRAM = 7;
- public static final int TRAPEZOID = 8;
- public static final int NON_ISOSCELES_TRAPEZOID = 9;
- public static final int PENTAGON = 10;
- public static final int HEXAGON = 11;
- public static final int HEPTAGON = 12;
- public static final int OCTAGON = 13;
- public static final int DECAGON = 14;
- public static final int DODECAGON = 15;
- public static final int STAR_4 = 16;
- public static final int STAR_5 = 17;
- public static final int STAR_6 = 18;
- public static final int STAR_7 = 19;
- public static final int STAR_8 = 20;
- public static final int STAR_10 = 21;
- public static final int STAR_12 = 22;
- public static final int STAR_16 = 23;
- public static final int STAR_24 = 24;
- public static final int STAR_32 = 25;
- public static final int ROUND_RECT = 26;
- public static final int ROUND_1_RECT = 27;
- public static final int ROUND_2_SAME_RECT = 28;
- public static final int ROUND_2_DIAG_RECT = 29;
- public static final int SNIP_ROUND_RECT = 30;
- public static final int SNIP_1_RECT = 31;
- public static final int SNIP_2_SAME_RECT = 32;
- public static final int SNIP_2_DIAG_RECT = 33;
- public static final int PLAQUE = 34;
- public static final int ELLIPSE = 35;
- public static final int TEARDROP = 36;
- public static final int HOME_PLATE = 37;
- public static final int CHEVRON = 38;
- public static final int PIE_WEDGE = 39;
- public static final int PIE = 40;
- public static final int BLOCK_ARC = 41;
- public static final int DONUT = 42;
- public static final int NO_SMOKING = 43;
- public static final int RIGHT_ARROW = 44;
- public static final int LEFT_ARROW = 45;
- public static final int UP_ARROW = 46;
- public static final int DOWN_ARROW = 47;
- public static final int STRIPED_RIGHT_ARROW = 48;
- public static final int NOTCHED_RIGHT_ARROW = 49;
- public static final int BENT_UP_ARROW = 50;
- public static final int LEFT_RIGHT_ARROW = 51;
- public static final int UP_DOWN_ARROW = 52;
- public static final int LEFT_UP_ARROW = 53;
- public static final int LEFT_RIGHT_UP_ARROW = 54;
- public static final int QUAD_ARROW = 55;
- public static final int LEFT_ARROW_CALLOUT = 56;
- public static final int RIGHT_ARROW_CALLOUT = 57;
- public static final int UP_ARROW_CALLOUT = 58;
- public static final int DOWN_ARROW_CALLOUT = 59;
- public static final int LEFT_RIGHT_ARROW_CALLOUT = 60;
- public static final int UP_DOWN_ARROW_CALLOUT = 61;
- public static final int QUAD_ARROW_CALLOUT = 62;
- public static final int BENT_ARROW = 63;
- public static final int UTURN_ARROW = 64;
- public static final int CIRCULAR_ARROW = 65;
- public static final int LEFT_CIRCULAR_ARROW = 66;
- public static final int LEFT_RIGHT_CIRCULAR_ARROW = 67;
- public static final int CURVED_RIGHT_ARROW = 68;
- public static final int CURVED_LEFT_ARROW = 69;
- public static final int CURVED_UP_ARROW = 70;
- public static final int CURVED_DOWN_ARROW = 71;
- public static final int SWOOSH_ARROW = 72;
- public static final int CUBE = 73;
- public static final int CAN = 74;
- public static final int LIGHTNING_BOLT = 75;
- public static final int HEART = 76;
- public static final int SUN = 77;
- public static final int MOON = 78;
- public static final int SMILEY_FACE = 79;
- public static final int IRREGULAR_SEAL_1 = 80;
- public static final int IRREGULAR_SEAL_2 = 81;
- public static final int FOLDED_CORNER = 82;
- public static final int BEVEL = 83;
- public static final int FRAME = 84;
- public static final int HALF_FRAME = 85;
- public static final int CORNER = 86;
- public static final int DIAG_STRIPE = 87;
- public static final int CHORD = 88;
- public static final int ARC = 89;
- public static final int LEFT_BRACKET = 90;
- public static final int RIGHT_BRACKET = 91;
- public static final int LEFT_BRACE = 92;
- public static final int RIGHT_BRACE = 93;
- public static final int BRACKET_PAIR = 94;
- public static final int BRACE_PAIR = 95;
- public static final int STRAIGHT_CONNECTOR_1 = 96;
- public static final int BENT_CONNECTOR_2 = 97;
- public static final int BENT_CONNECTOR_3 = 98;
- public static final int BENT_CONNECTOR_4 = 99;
- public static final int BENT_CONNECTOR_5 = 100;
- public static final int CURVED_CONNECTOR_2 = 101;
- public static final int CURVED_CONNECTOR_3 = 102;
- public static final int CURVED_CONNECTOR_4 = 103;
- public static final int CURVED_CONNECTOR_5 = 104;
- public static final int CALLOUT_1 = 105;
- public static final int CALLOUT_2 = 106;
- public static final int CALLOUT_3 = 107;
- public static final int ACCENT_CALLOUT_1 = 108;
- public static final int ACCENT_CALLOUT_2 = 109;
- public static final int ACCENT_CALLOUT_3 = 110;
- public static final int BORDER_CALLOUT_1 = 111;
- public static final int BORDER_CALLOUT_2 = 112;
- public static final int BORDER_CALLOUT_3 = 113;
- public static final int ACCENT_BORDER_CALLOUT_1 = 114;
- public static final int ACCENT_BORDER_CALLOUT_2 = 115;
- public static final int ACCENT_BORDER_CALLOUT_3 = 116;
- public static final int WEDGE_RECT_CALLOUT = 117;
- public static final int WEDGE_ROUND_RECT_CALLOUT = 118;
- public static final int WEDGE_ELLIPSE_CALLOUT = 119;
- public static final int CLOUD_CALLOUT = 120;
- public static final int CLOUD = 121;
- public static final int RIBBON = 122;
- public static final int RIBBON_2 = 123;
- public static final int ELLIPSE_RIBBON = 124;
- public static final int ELLIPSE_RIBBON_2 = 125;
- public static final int LEFT_RIGHT_RIBBON = 126;
- public static final int VERTICAL_SCROLL = 127;
- public static final int HORIZONTAL_SCROLL = 128;
- public static final int WAVE = 129;
- public static final int DOUBLE_WAVE = 130;
- public static final int PLUS = 131;
- public static final int FLOW_CHART_PROCESS = 132;
- public static final int FLOW_CHART_DECISION = 133;
- public static final int FLOW_CHART_INPUT_OUTPUT = 134;
- public static final int FLOW_CHART_PREDEFINED_PROCESS = 135;
- public static final int FLOW_CHART_INTERNAL_STORAGE = 136;
- public static final int FLOW_CHART_DOCUMENT = 137;
- public static final int FLOW_CHART_MULTIDOCUMENT = 138;
- public static final int FLOW_CHART_TERMINATOR = 139;
- public static final int FLOW_CHART_PREPARATION = 140;
- public static final int FLOW_CHART_MANUAL_INPUT = 141;
- public static final int FLOW_CHART_MANUAL_OPERATION = 142;
- public static final int FLOW_CHART_CONNECTOR = 143;
- public static final int FLOW_CHART_PUNCHED_CARD = 144;
- public static final int FLOW_CHART_PUNCHED_TAPE = 145;
- public static final int FLOW_CHART_SUMMING_JUNCTION = 146;
- public static final int FLOW_CHART_OR = 147;
- public static final int FLOW_CHART_COLLATE = 148;
- public static final int FLOW_CHART_SORT = 149;
- public static final int FLOW_CHART_EXTRACT = 150;
- public static final int FLOW_CHART_MERGE = 151;
- public static final int FLOW_CHART_OFFLINE_STORAGE = 152;
- public static final int FLOW_CHART_ONLINE_STORAGE = 153;
- public static final int FLOW_CHART_MAGNETIC_TAPE = 154;
- public static final int FLOW_CHART_MAGNETIC_DISK = 155;
- public static final int FLOW_CHART_MAGNETIC_DRUM = 156;
- public static final int FLOW_CHART_DISPLAY = 157;
- public static final int FLOW_CHART_DELAY = 158;
- public static final int FLOW_CHART_ALTERNATE_PROCESS = 159;
- public static final int FLOW_CHART_OFFPAGE_CONNECTOR = 160;
- public static final int ACTION_BUTTON_BLANK = 161;
- public static final int ACTION_BUTTON_HOME = 162;
- public static final int ACTION_BUTTON_HELP = 163;
- public static final int ACTION_BUTTON_INFORMATION = 164;
- public static final int ACTION_BUTTON_FORWARD_NEXT = 165;
- public static final int ACTION_BUTTON_BACK_PREVIOUS = 166;
- public static final int ACTION_BUTTON_END = 167;
- public static final int ACTION_BUTTON_BEGINNING = 168;
- public static final int ACTION_BUTTON_RETURN = 169;
- public static final int ACTION_BUTTON_DOCUMENT = 170;
- public static final int ACTION_BUTTON_SOUND = 171;
- public static final int ACTION_BUTTON_MOVIE = 172;
- public static final int GEAR_6 = 173;
- public static final int GEAR_9 = 174;
- public static final int FUNNEL = 175;
- public static final int MATH_PLUS = 176;
- public static final int MATH_MINUS = 177;
- public static final int MATH_MULTIPLY = 178;
- public static final int MATH_DIVIDE = 179;
- public static final int MATH_EQUAL = 180;
- public static final int MATH_NOT_EQUAL = 181;
- public static final int CORNER_TABS = 182;
- public static final int SQUARE_TABS = 183;
- public static final int PLAQUE_TABS = 184;
- public static final int CHART_X = 185;
- public static final int CHART_STAR = 186;
- public static final int CHART_PLUS = 187;
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.ss.usermodel;
+
+/**
+ * All known types of automatic shapes in DrawingML
+ *
+ * @author Yegor Kozlov
+ */
+public class ShapeTypes {
+ public static final int LINE = 1;
+ public static final int LINE_INV = 2;
+ public static final int TRIANGLE = 3;
+ public static final int RT_TRIANGLE = 4;
+ public static final int RECT = 5;
+ public static final int DIAMOND = 6;
+ public static final int PARALLELOGRAM = 7;
+ public static final int TRAPEZOID = 8;
+ public static final int NON_ISOSCELES_TRAPEZOID = 9;
+ public static final int PENTAGON = 10;
+ public static final int HEXAGON = 11;
+ public static final int HEPTAGON = 12;
+ public static final int OCTAGON = 13;
+ public static final int DECAGON = 14;
+ public static final int DODECAGON = 15;
+ public static final int STAR_4 = 16;
+ public static final int STAR_5 = 17;
+ public static final int STAR_6 = 18;
+ public static final int STAR_7 = 19;
+ public static final int STAR_8 = 20;
+ public static final int STAR_10 = 21;
+ public static final int STAR_12 = 22;
+ public static final int STAR_16 = 23;
+ public static final int STAR_24 = 24;
+ public static final int STAR_32 = 25;
+ public static final int ROUND_RECT = 26;
+ public static final int ROUND_1_RECT = 27;
+ public static final int ROUND_2_SAME_RECT = 28;
+ public static final int ROUND_2_DIAG_RECT = 29;
+ public static final int SNIP_ROUND_RECT = 30;
+ public static final int SNIP_1_RECT = 31;
+ public static final int SNIP_2_SAME_RECT = 32;
+ public static final int SNIP_2_DIAG_RECT = 33;
+ public static final int PLAQUE = 34;
+ public static final int ELLIPSE = 35;
+ public static final int TEARDROP = 36;
+ public static final int HOME_PLATE = 37;
+ public static final int CHEVRON = 38;
+ public static final int PIE_WEDGE = 39;
+ public static final int PIE = 40;
+ public static final int BLOCK_ARC = 41;
+ public static final int DONUT = 42;
+ public static final int NO_SMOKING = 43;
+ public static final int RIGHT_ARROW = 44;
+ public static final int LEFT_ARROW = 45;
+ public static final int UP_ARROW = 46;
+ public static final int DOWN_ARROW = 47;
+ public static final int STRIPED_RIGHT_ARROW = 48;
+ public static final int NOTCHED_RIGHT_ARROW = 49;
+ public static final int BENT_UP_ARROW = 50;
+ public static final int LEFT_RIGHT_ARROW = 51;
+ public static final int UP_DOWN_ARROW = 52;
+ public static final int LEFT_UP_ARROW = 53;
+ public static final int LEFT_RIGHT_UP_ARROW = 54;
+ public static final int QUAD_ARROW = 55;
+ public static final int LEFT_ARROW_CALLOUT = 56;
+ public static final int RIGHT_ARROW_CALLOUT = 57;
+ public static final int UP_ARROW_CALLOUT = 58;
+ public static final int DOWN_ARROW_CALLOUT = 59;
+ public static final int LEFT_RIGHT_ARROW_CALLOUT = 60;
+ public static final int UP_DOWN_ARROW_CALLOUT = 61;
+ public static final int QUAD_ARROW_CALLOUT = 62;
+ public static final int BENT_ARROW = 63;
+ public static final int UTURN_ARROW = 64;
+ public static final int CIRCULAR_ARROW = 65;
+ public static final int LEFT_CIRCULAR_ARROW = 66;
+ public static final int LEFT_RIGHT_CIRCULAR_ARROW = 67;
+ public static final int CURVED_RIGHT_ARROW = 68;
+ public static final int CURVED_LEFT_ARROW = 69;
+ public static final int CURVED_UP_ARROW = 70;
+ public static final int CURVED_DOWN_ARROW = 71;
+ public static final int SWOOSH_ARROW = 72;
+ public static final int CUBE = 73;
+ public static final int CAN = 74;
+ public static final int LIGHTNING_BOLT = 75;
+ public static final int HEART = 76;
+ public static final int SUN = 77;
+ public static final int MOON = 78;
+ public static final int SMILEY_FACE = 79;
+ public static final int IRREGULAR_SEAL_1 = 80;
+ public static final int IRREGULAR_SEAL_2 = 81;
+ public static final int FOLDED_CORNER = 82;
+ public static final int BEVEL = 83;
+ public static final int FRAME = 84;
+ public static final int HALF_FRAME = 85;
+ public static final int CORNER = 86;
+ public static final int DIAG_STRIPE = 87;
+ public static final int CHORD = 88;
+ public static final int ARC = 89;
+ public static final int LEFT_BRACKET = 90;
+ public static final int RIGHT_BRACKET = 91;
+ public static final int LEFT_BRACE = 92;
+ public static final int RIGHT_BRACE = 93;
+ public static final int BRACKET_PAIR = 94;
+ public static final int BRACE_PAIR = 95;
+ public static final int STRAIGHT_CONNECTOR_1 = 96;
+ public static final int BENT_CONNECTOR_2 = 97;
+ public static final int BENT_CONNECTOR_3 = 98;
+ public static final int BENT_CONNECTOR_4 = 99;
+ public static final int BENT_CONNECTOR_5 = 100;
+ public static final int CURVED_CONNECTOR_2 = 101;
+ public static final int CURVED_CONNECTOR_3 = 102;
+ public static final int CURVED_CONNECTOR_4 = 103;
+ public static final int CURVED_CONNECTOR_5 = 104;
+ public static final int CALLOUT_1 = 105;
+ public static final int CALLOUT_2 = 106;
+ public static final int CALLOUT_3 = 107;
+ public static final int ACCENT_CALLOUT_1 = 108;
+ public static final int ACCENT_CALLOUT_2 = 109;
+ public static final int ACCENT_CALLOUT_3 = 110;
+ public static final int BORDER_CALLOUT_1 = 111;
+ public static final int BORDER_CALLOUT_2 = 112;
+ public static final int BORDER_CALLOUT_3 = 113;
+ public static final int ACCENT_BORDER_CALLOUT_1 = 114;
+ public static final int ACCENT_BORDER_CALLOUT_2 = 115;
+ public static final int ACCENT_BORDER_CALLOUT_3 = 116;
+ public static final int WEDGE_RECT_CALLOUT = 117;
+ public static final int WEDGE_ROUND_RECT_CALLOUT = 118;
+ public static final int WEDGE_ELLIPSE_CALLOUT = 119;
+ public static final int CLOUD_CALLOUT = 120;
+ public static final int CLOUD = 121;
+ public static final int RIBBON = 122;
+ public static final int RIBBON_2 = 123;
+ public static final int ELLIPSE_RIBBON = 124;
+ public static final int ELLIPSE_RIBBON_2 = 125;
+ public static final int LEFT_RIGHT_RIBBON = 126;
+ public static final int VERTICAL_SCROLL = 127;
+ public static final int HORIZONTAL_SCROLL = 128;
+ public static final int WAVE = 129;
+ public static final int DOUBLE_WAVE = 130;
+ public static final int PLUS = 131;
+ public static final int FLOW_CHART_PROCESS = 132;
+ public static final int FLOW_CHART_DECISION = 133;
+ public static final int FLOW_CHART_INPUT_OUTPUT = 134;
+ public static final int FLOW_CHART_PREDEFINED_PROCESS = 135;
+ public static final int FLOW_CHART_INTERNAL_STORAGE = 136;
+ public static final int FLOW_CHART_DOCUMENT = 137;
+ public static final int FLOW_CHART_MULTIDOCUMENT = 138;
+ public static final int FLOW_CHART_TERMINATOR = 139;
+ public static final int FLOW_CHART_PREPARATION = 140;
+ public static final int FLOW_CHART_MANUAL_INPUT = 141;
+ public static final int FLOW_CHART_MANUAL_OPERATION = 142;
+ public static final int FLOW_CHART_CONNECTOR = 143;
+ public static final int FLOW_CHART_PUNCHED_CARD = 144;
+ public static final int FLOW_CHART_PUNCHED_TAPE = 145;
+ public static final int FLOW_CHART_SUMMING_JUNCTION = 146;
+ public static final int FLOW_CHART_OR = 147;
+ public static final int FLOW_CHART_COLLATE = 148;
+ public static final int FLOW_CHART_SORT = 149;
+ public static final int FLOW_CHART_EXTRACT = 150;
+ public static final int FLOW_CHART_MERGE = 151;
+ public static final int FLOW_CHART_OFFLINE_STORAGE = 152;
+ public static final int FLOW_CHART_ONLINE_STORAGE = 153;
+ public static final int FLOW_CHART_MAGNETIC_TAPE = 154;
+ public static final int FLOW_CHART_MAGNETIC_DISK = 155;
+ public static final int FLOW_CHART_MAGNETIC_DRUM = 156;
+ public static final int FLOW_CHART_DISPLAY = 157;
+ public static final int FLOW_CHART_DELAY = 158;
+ public static final int FLOW_CHART_ALTERNATE_PROCESS = 159;
+ public static final int FLOW_CHART_OFFPAGE_CONNECTOR = 160;
+ public static final int ACTION_BUTTON_BLANK = 161;
+ public static final int ACTION_BUTTON_HOME = 162;
+ public static final int ACTION_BUTTON_HELP = 163;
+ public static final int ACTION_BUTTON_INFORMATION = 164;
+ public static final int ACTION_BUTTON_FORWARD_NEXT = 165;
+ public static final int ACTION_BUTTON_BACK_PREVIOUS = 166;
+ public static final int ACTION_BUTTON_END = 167;
+ public static final int ACTION_BUTTON_BEGINNING = 168;
+ public static final int ACTION_BUTTON_RETURN = 169;
+ public static final int ACTION_BUTTON_DOCUMENT = 170;
+ public static final int ACTION_BUTTON_SOUND = 171;
+ public static final int ACTION_BUTTON_MOVIE = 172;
+ public static final int GEAR_6 = 173;
+ public static final int GEAR_9 = 174;
+ public static final int FUNNEL = 175;
+ public static final int MATH_PLUS = 176;
+ public static final int MATH_MINUS = 177;
+ public static final int MATH_MULTIPLY = 178;
+ public static final int MATH_DIVIDE = 179;
+ public static final int MATH_EQUAL = 180;
+ public static final int MATH_NOT_EQUAL = 181;
+ public static final int CORNER_TABS = 182;
+ public static final int SQUARE_TABS = 183;
+ public static final int PLAQUE_TABS = 184;
+ public static final int CHART_X = 185;
+ public static final int CHART_STAR = 186;
+ public static final int CHART_PLUS = 187;
+}
diff --git a/src/java/org/apache/poi/ss/usermodel/VerticalAlignment.java b/src/java/org/apache/poi/ss/usermodel/VerticalAlignment.java
index 2f9327328..398565d04 100755
--- a/src/java/org/apache/poi/ss/usermodel/VerticalAlignment.java
+++ b/src/java/org/apache/poi/ss/usermodel/VerticalAlignment.java
@@ -1,69 +1,69 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.usermodel;
-
-/**
- * This enumeration value indicates the type of vertical alignment for a cell, i.e.,
- * whether it is aligned top, bottom, vertically centered, justified or distributed.
- */
-public enum VerticalAlignment {
- /**
- * The vertical alignment is aligned-to-top.
- */
- TOP,
-
- /**
- * The vertical alignment is centered across the height of the cell.
- */
- CENTER,
-
- /**
- * The vertical alignment is aligned-to-bottom.
- */
- BOTTOM,
-
- /**
- * - * When text direction is horizontal: the vertical alignment of lines of text is distributed vertically, - * where each line of text inside the cell is evenly distributed across the height of the cell, - * with flush top and bottom margins. - *
- *- * When text direction is vertical: similar behavior as horizontal justification. - * The alignment is justified (flush top and bottom in this case). For each line of text, each - * line of the wrapped text in a cell is aligned to the top and bottom (except the last line). - * If no single line of text wraps in the cell, then the text is not justified. - *
- */ - JUSTIFY, - - /** - *- * When text direction is horizontal: the vertical alignment of lines of text is distributed vertically, - * where each line of text inside the cell is evenly distributed across the height of the cell, - * with flush top - *
- *- * When text direction is vertical: behaves exactly as distributed horizontal alignment. - * The first words in a line of text (appearing at the top of the cell) are flush - * with the top edge of the cell, and the last words of a line of text are flush with the bottom edge of the cell, - * and the line of text is distributed evenly from top to bottom. - *
- */ - DISTRIBUTED -} +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ss.usermodel; + +/** + * This enumeration value indicates the type of vertical alignment for a cell, i.e., + * whether it is aligned top, bottom, vertically centered, justified or distributed. + */ +public enum VerticalAlignment { + /** + * The vertical alignment is aligned-to-top. + */ + TOP, + + /** + * The vertical alignment is centered across the height of the cell. + */ + CENTER, + + /** + * The vertical alignment is aligned-to-bottom. + */ + BOTTOM, + + /** + *+ * When text direction is horizontal: the vertical alignment of lines of text is distributed vertically, + * where each line of text inside the cell is evenly distributed across the height of the cell, + * with flush top and bottom margins. + *
+ *+ * When text direction is vertical: similar behavior as horizontal justification. + * The alignment is justified (flush top and bottom in this case). For each line of text, each + * line of the wrapped text in a cell is aligned to the top and bottom (except the last line). + * If no single line of text wraps in the cell, then the text is not justified. + *
+ */ + JUSTIFY, + + /** + *+ * When text direction is horizontal: the vertical alignment of lines of text is distributed vertically, + * where each line of text inside the cell is evenly distributed across the height of the cell, + * with flush top + *
+ *+ * When text direction is vertical: behaves exactly as distributed horizontal alignment. + * The first words in a line of text (appearing at the top of the cell) are flush + * with the top edge of the cell, and the last words of a line of text are flush with the bottom edge of the cell, + * and the line of text is distributed evenly from top to bottom. + *
+ */ + DISTRIBUTED +} diff --git a/src/java/org/apache/poi/util/DelayableLittleEndianOutput.java b/src/java/org/apache/poi/util/DelayableLittleEndianOutput.java index d8e4395e6..13282ac37 100644 --- a/src/java/org/apache/poi/util/DelayableLittleEndianOutput.java +++ b/src/java/org/apache/poi/util/DelayableLittleEndianOutput.java @@ -1,34 +1,34 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.util; -/** - * Implementors of this interface allow client code to 'delay' writing to a certain section of a - * data output stream.