From: Nick Burch Date: Sun, 27 Dec 2009 16:46:38 +0000 (+0000) Subject: Looks like we already had Ref8U but with a different name... Switch to using CellRang... X-Git-Tag: REL_3_7_BETA1~176 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc6f208d7919eb61dbf9933f40a3f6e01589f5b1;p=poi.git Looks like we already had Ref8U but with a different name... Switch to using CellRangeAddress instead! git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@894078 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/FeatRecord.java b/src/java/org/apache/poi/hssf/record/FeatRecord.java index a772ca5488..8304278e96 100644 --- a/src/java/org/apache/poi/hssf/record/FeatRecord.java +++ b/src/java/org/apache/poi/hssf/record/FeatRecord.java @@ -18,7 +18,7 @@ package org.apache.poi.hssf.record; import org.apache.poi.hssf.record.common.FtrHeader; -import org.apache.poi.hssf.record.common.Ref8U; +import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.LittleEndianOutput; /** @@ -41,7 +41,7 @@ public final class FeatRecord extends StandardRecord { /** Only matters if type is ISFFEC2 */ private long cbFeatData; private int reserved3; // Should always be zero - private Ref8U[] cellRefs; + private CellRangeAddress[] cellRefs; private byte[] rgbFeat; @@ -64,9 +64,9 @@ public final class FeatRecord extends StandardRecord { cbFeatData = in.readInt(); reserved3 = in.readShort(); - cellRefs = new Ref8U[cref]; + cellRefs = new CellRangeAddress[cref]; for(int i=0; i - * This record part specifies common way of encoding a - * block of cells via first-last row-column. - */ -public final class Ref8U { - private short firstRow; // zero-based - private short lastRow; // zero-based - private short firstCol; // zero-based - private short lastCol; // zero-based - - public Ref8U() { - } - - public Ref8U(RecordInputStream in) { - firstRow = in.readShort(); - lastRow = in.readShort(); - firstCol = in.readShort(); - lastCol = in.readShort(); - } - - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append(" [CELL RANGE]\n"); - buffer.append(" Rows " + firstRow + " to " + lastRow); - buffer.append(" Cols " + firstCol + " to " + lastCol); - buffer.append(" [/CELL RANGE]\n"); - return buffer.toString(); - } - - public void serialize(LittleEndianOutput out) { - out.writeShort(firstRow); - out.writeShort(lastRow); - out.writeShort(firstCol); - out.writeShort(lastCol); - } - - public static int getDataSize() { - return 8; - } - - public short getFirstRow() { - return firstRow; - } - public void setFirstRow(short firstRow) { - this.firstRow = firstRow; - } - - public short getLastRow() { - return lastRow; - } - public void setLastRow(short lastRow) { - this.lastRow = lastRow; - } - - public short getFirstCol() { - return firstCol; - } - public void setFirstCol(short firstCol) { - this.firstCol = firstCol; - } - - public short getLastCol() { - return lastCol; - } - public void setLastCol(short lastCol) { - this.lastCol = lastCol; - } -} \ No newline at end of file diff --git a/src/java/org/apache/poi/ss/util/CellRangeAddress.java b/src/java/org/apache/poi/ss/util/CellRangeAddress.java index 0b0f3a9729..2c34d5f4a7 100644 --- a/src/java/org/apache/poi/ss/util/CellRangeAddress.java +++ b/src/java/org/apache/poi/ss/util/CellRangeAddress.java @@ -24,6 +24,9 @@ import org.apache.poi.util.LittleEndianOutput; /** * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address'

+ * + *

In the Microsoft documentation, this is also known as a + * Ref8U - see page 831 of version 1.0 of the documentation. * * Note - {@link SelectionRecord} uses the BIFF5 version of this structure * @author Dragos Buleandra (dragos.buleandra@trade2b.ro) diff --git a/src/testcases/org/apache/poi/hssf/record/common/TestRef8U.java b/src/testcases/org/apache/poi/hssf/record/common/TestRef8U.java deleted file mode 100644 index 41e90a8354..0000000000 --- a/src/testcases/org/apache/poi/hssf/record/common/TestRef8U.java +++ /dev/null @@ -1,79 +0,0 @@ -/* ==================================================================== -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.common; - -import java.io.ByteArrayOutputStream; - -import org.apache.poi.hssf.record.TestcaseRecordInputStream; -import org.apache.poi.util.LittleEndianOutputStream; - -import junit.framework.TestCase; - -public final class TestRef8U extends TestCase { - byte[] data = new byte[] { - (byte)0x02,(byte)0x00, - (byte)0x04,(byte)0x00, - (byte)0x00,(byte)0x00, - (byte)0x03,(byte)0x00, - }; - - public void testLoad() { - Ref8U ref = new Ref8U( - TestcaseRecordInputStream.create(0x000, data) - ); - assertEquals(2, ref.getFirstRow()); - assertEquals(4, ref.getLastRow()); - assertEquals(0, ref.getFirstCol()); - assertEquals(3, ref.getLastCol()); - - assertEquals( 8, Ref8U.getDataSize() ); - } - - public void testStore() - { - Ref8U ref = new Ref8U(); - - byte[] recordBytes; - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - LittleEndianOutputStream out = new LittleEndianOutputStream(baos); - - // With nothing set - ref.serialize(out); - recordBytes = baos.toByteArray(); - assertEquals(recordBytes.length, data.length); - for (int i = 0; i < data.length; i++) { - assertEquals("At offset " + i, 0, recordBytes[i]); - } - - // Now set the flags - ref.setFirstRow((short)2); - ref.setLastRow((short)4); - ref.setFirstCol((short)0); - ref.setLastCol((short)3); - - // Re-test - baos.reset(); - ref.serialize(out); - recordBytes = baos.toByteArray(); - - assertEquals(recordBytes.length, data.length); - for (int i = 0; i < data.length; i++) { - assertEquals("At offset " + i, data[i], recordBytes[i]); - } - } -} diff --git a/src/testcases/org/apache/poi/ss/util/TestCellRangeAddress.java b/src/testcases/org/apache/poi/ss/util/TestCellRangeAddress.java new file mode 100644 index 0000000000..a2dff595c5 --- /dev/null +++ b/src/testcases/org/apache/poi/ss/util/TestCellRangeAddress.java @@ -0,0 +1,80 @@ +/* ==================================================================== +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.util; + +import java.io.ByteArrayOutputStream; + +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.util.LittleEndianOutputStream; + +import junit.framework.TestCase; + +public final class TestCellRangeAddress extends TestCase { + byte[] data = new byte[] { + (byte)0x02,(byte)0x00, + (byte)0x04,(byte)0x00, + (byte)0x00,(byte)0x00, + (byte)0x03,(byte)0x00, + }; + + public void testLoad() { + CellRangeAddress ref = new CellRangeAddress( + TestcaseRecordInputStream.create(0x000, data) + ); + assertEquals(2, ref.getFirstRow()); + assertEquals(4, ref.getLastRow()); + assertEquals(0, ref.getFirstColumn()); + assertEquals(3, ref.getLastColumn()); + + assertEquals( 8, CellRangeAddress.ENCODED_SIZE ); + } + + public void testStore() + { + CellRangeAddress ref = new CellRangeAddress(0,0,0,0); + + byte[] recordBytes; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + LittleEndianOutputStream out = new LittleEndianOutputStream(baos); + + // With nothing set + ref.serialize(out); + recordBytes = baos.toByteArray(); + assertEquals(recordBytes.length, data.length); + for (int i = 0; i < data.length; i++) { + assertEquals("At offset " + i, 0, recordBytes[i]); + } + + // Now set the flags + ref.setFirstRow((short)2); + ref.setLastRow((short)4); + ref.setFirstColumn((short)0); + ref.setLastColumn((short)3); + + // Re-test + baos.reset(); + ref.serialize(out); + recordBytes = baos.toByteArray(); + + assertEquals(recordBytes.length, data.length); + for (int i = 0; i < data.length; i++) { + assertEquals("At offset " + i, data[i], recordBytes[i]); + } + } +}