aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2009-01-06 20:49:02 +0000
committerNick Burch <nick@apache.org>2009-01-06 20:49:02 +0000
commit5d1f44e314d2ecbe4b2a72d90a2396da1b704c74 (patch)
treeb12ee0720ae1594845e1c4e7db021edfc368602f /src
parent899061e647b516e62e836685ad540e3002c7f1ed (diff)
downloadpoi-5d1f44e314d2ecbe4b2a72d90a2396da1b704c74.tar.gz
poi-5d1f44e314d2ecbe4b2a72d90a2396da1b704c74.zip
Support for reading HSSF column styles
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@732112 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/documentation/content/xdocs/changes.xml1
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java18
-rw-r--r--src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java13
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java11
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/data/ColumnStyle1dp.xlsbin0 -> 18432 bytes
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/data/ColumnStyle1dpColoured.xlsbin0 -> 18432 bytes
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/data/ColumnStyleNone.xlsbin0 -> 17408 bytes
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java39
9 files changed, 83 insertions, 0 deletions
diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml
index 410abba48a..139b48f9a0 100644
--- a/src/documentation/content/xdocs/changes.xml
+++ b/src/documentation/content/xdocs/changes.xml
@@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta5" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="add">Support for reading HSSF column styles</action>
<action dev="POI-DEVELOPERS" type="fix">Hook up POIXMLTextExtractor.getMetadataTextExtractor() to the already written POIXMLPropertiesTextExtractor</action>
<action dev="POI-DEVELOPERS" type="fix">46472 - Avoid NPE in HPSFPropertiesExtractor when no properties exist</action>
<action dev="POI-DEVELOPERS" type="fix">46479 - fixed bugs related to cached formula values and HSSFFormulaEvaluator.evaluateInCell()</action>
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index e9e6761cb2..1af660ed72 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta5" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="add">Support for reading HSSF column styles</action>
<action dev="POI-DEVELOPERS" type="fix">Hook up POIXMLTextExtractor.getMetadataTextExtractor() to the already written POIXMLPropertiesTextExtractor</action>
<action dev="POI-DEVELOPERS" type="fix">46472 - Avoid NPE in HPSFPropertiesExtractor when no properties exist</action>
<action dev="POI-DEVELOPERS" type="fix">46479 - fixed bugs related to cached formula values and HSSFFormulaEvaluator.evaluateInCell()</action>
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
index 9ed29e00f5..30556bd554 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
@@ -36,6 +36,7 @@ import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.DVRecord;
import org.apache.poi.hssf.record.EscherAggregate;
+import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.SCLRecord;
@@ -502,6 +503,23 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
{
sheet.setDefaultRowHeight((short) (height * 20));
}
+
+ /**
+ * Returns the HSSFCellStyle that applies to the given
+ * (0 based) column, or null if no style has been
+ * set for that column
+ */
+ public HSSFCellStyle getColumnStyle(int column) {
+ short styleIndex = sheet.getXFIndexForColAt((short)column);
+
+ if(styleIndex == 0xf) {
+ // None set
+ return null;
+ }
+
+ ExtendedFormatRecord xf = book.getExFormatAt(styleIndex);
+ return new HSSFCellStyle(styleIndex, xf, book);
+ }
/**
* get whether gridlines are printed.
diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
index 9650db2009..a6a1662c53 100644
--- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
+++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
@@ -177,6 +177,19 @@ public interface Sheet extends Iterable<Row> {
* @param height default row height
*/
void setDefaultRowHeightInPoints(float height);
+
+ /**
+ * Returns the CellStyle that applies to the given
+ * (0 based) column, or null if no style has been
+ * set for that column
+ */
+ public CellStyle getColumnStyle(int column);
+
+ /**
+ * Sets the CellStyle that applies to the given
+ * (0 based) column.
+ */
+// public CellStyle setColumnStyle(int column, CellStyle style);
/**
* Adds a merged region of cells (hence those cells form one)
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index c8de77972d..10391170a1 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -500,6 +500,17 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
worksheet.getSheetFormatPr() :
worksheet.addNewSheetFormatPr();
}
+
+ /**
+ * Returns the CellStyle that applies to the given
+ * (0 based) column, or null if no style has been
+ * set for that column
+ */
+ public CellStyle getColumnStyle(int column) {
+ // TODO
+ return null;
+ }
+
/**
* Get whether to display the guts or not,
diff --git a/src/testcases/org/apache/poi/hssf/data/ColumnStyle1dp.xls b/src/testcases/org/apache/poi/hssf/data/ColumnStyle1dp.xls
new file mode 100755
index 0000000000..1318b0fa5d
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/data/ColumnStyle1dp.xls
Binary files differ
diff --git a/src/testcases/org/apache/poi/hssf/data/ColumnStyle1dpColoured.xls b/src/testcases/org/apache/poi/hssf/data/ColumnStyle1dpColoured.xls
new file mode 100755
index 0000000000..25dd8de6de
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/data/ColumnStyle1dpColoured.xls
Binary files differ
diff --git a/src/testcases/org/apache/poi/hssf/data/ColumnStyleNone.xls b/src/testcases/org/apache/poi/hssf/data/ColumnStyleNone.xls
new file mode 100755
index 0000000000..3f0128aad4
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/data/ColumnStyleNone.xls
Binary files differ
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
index 4757223354..c119daa283 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
@@ -911,4 +911,43 @@ public final class TestHSSFSheet extends TestCase {
}
wb.createSheet(SAME_PREFIX + "Exxxx"); // OK - differs in the 31st char
}
+
+ /**
+ * Tests that we can read existing column styles
+ */
+ public void testReadColumnStyles() {
+ HSSFWorkbook wbNone = HSSFTestDataSamples.openSampleWorkbook("ColumnStyleNone.xls");
+ HSSFWorkbook wbSimple = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dp.xls");
+ HSSFWorkbook wbComplex = HSSFTestDataSamples.openSampleWorkbook("ColumnStyle1dpColoured.xls");
+
+ // Presence / absence checks
+ assertNull(wbNone.getSheetAt(0).getColumnStyle(0));
+ assertNull(wbNone.getSheetAt(0).getColumnStyle(1));
+
+ assertNull(wbSimple.getSheetAt(0).getColumnStyle(0));
+ assertNotNull(wbSimple.getSheetAt(0).getColumnStyle(1));
+
+ assertNull(wbComplex.getSheetAt(0).getColumnStyle(0));
+ assertNotNull(wbComplex.getSheetAt(0).getColumnStyle(1));
+
+ // Details checks
+ HSSFCellStyle bs = wbSimple.getSheetAt(0).getColumnStyle(1);
+ assertEquals(62, bs.getIndex());
+ assertEquals("#,##0.0_ ;\\-#,##0.0\\ ", bs.getDataFormatString());
+ assertEquals("Calibri", bs.getFont(wbSimple).getFontName());
+ assertEquals(11*20, bs.getFont(wbSimple).getFontHeight());
+ assertEquals(8, bs.getFont(wbSimple).getColor());
+ assertFalse(bs.getFont(wbSimple).getItalic());
+ assertEquals(HSSFFont.BOLDWEIGHT_NORMAL, bs.getFont(wbSimple).getBoldweight());
+
+
+ HSSFCellStyle cs = wbComplex.getSheetAt(0).getColumnStyle(1);
+ assertEquals(62, cs.getIndex());
+ assertEquals("#,##0.0_ ;\\-#,##0.0\\ ", cs.getDataFormatString());
+ assertEquals("Arial", cs.getFont(wbComplex).getFontName());
+ assertEquals(8*20, cs.getFont(wbComplex).getFontHeight());
+ assertEquals(10, cs.getFont(wbComplex).getColor());
+ assertFalse(cs.getFont(wbComplex).getItalic());
+ assertEquals(HSSFFont.BOLDWEIGHT_BOLD, cs.getFont(wbComplex).getBoldweight());
+ }
}