From d514f9b689602c73110d5c73b8941829af4c6ec0 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 14 Sep 2008 22:19:06 +0000 Subject: [PATCH] Make a start on exposing the StyleRecord details into HSSFCellStyle, but not fully there yet git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@695303 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/model/Workbook.java | 55 ++++++++++++++++++ .../apache/poi/hssf/record/StyleRecord.java | 5 +- .../poi/hssf/usermodel/HSSFCellStyle.java | 32 ++++++++++ .../poi/hssf/data/WithExtendedStyles.xls | Bin 0 -> 6656 bytes .../poi/hssf/usermodel/TestCellStyle.java | 36 ++++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/testcases/org/apache/poi/hssf/data/WithExtendedStyles.xls diff --git a/src/java/org/apache/poi/hssf/model/Workbook.java b/src/java/org/apache/poi/hssf/model/Workbook.java index f8a426108a..1e37a80ca2 100644 --- a/src/java/org/apache/poi/hssf/model/Workbook.java +++ b/src/java/org/apache/poi/hssf/model/Workbook.java @@ -773,6 +773,61 @@ public final class Workbook implements Model { numxfs++; return xf; } + + /** + * Returns the StyleRecord for the given + * xfIndex, or null if that ExtendedFormat doesn't + * have a Style set. + */ + public StyleRecord getStyleRecord(int xfIndex) { + // Style records always follow after + // the ExtendedFormat records + boolean done = false; + for(int i=records.getXfpos(); iMl&xKZ18eUZ8EXha6+zeuJSt)J*P*wNMY zLE_}ctDcAX|?u?Giv;6z3DF~f)k$$882LyFT( zP7e>EcAJ)0;fsQJewIN-p?D7~r6A5|p&>+JoGO|zqS4|BS}b#$*CK^+My)S##`VZ4 z4FWvVS_o-Ks&6u`A;EYQB7)*{=^5Wa^UMl&f>4`UPjt)!*xn!;C zN4uo0KjtczPp~gULQE{$%(^t`*sgy{;lo9qLXULYZ0X5PcSPs6>R8 z1mS3#)1mDH?0vubI^6EmA$)7rIz*qWb?DG?Qc=T=BoFSLXKbH`u0v#6rSdrMJO>7P zM}|j-`=fftc&`!BA9=XxaJa{aL<~kl*)!1JZyrp|K3S*m7N*dwdzu{<@aK-3ESczq zX3xI;>+M6wd>3E$NMr3s-_zakoNBwleJC>?by~bWzn*V>) z{FC-Ts);ht#b^kiXYu!GM2<_3`VV#7WM+}_7RdFc9dZw5+SO0P1ZmO^$wRo|9>N#~ zO=cD;<#RriP0FNe6B_Ne8fuUm5nBDqh{qLEvYBS`l?Ty?|7u8X>6S6fe+YM6{`=dH zzkvNpC*(wN_Z+k&k_HWDo6LiIw2LJ#7 literal 0 HcmV?d00001 diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java index 1dc826cc6f..e2783b4434 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java @@ -29,6 +29,8 @@ import java.io.*; import java.util.*; import junit.framework.*; + +import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.util.TempFile; /** @@ -41,6 +43,10 @@ public class TestCellStyle extends TestCase { + private static HSSFWorkbook openSample(String sampleFileName) { + return HSSFTestDataSamples.openSampleWorkbook(sampleFileName); + } + /** Creates a new instance of TestCellStyle */ public TestCellStyle(String name) @@ -303,6 +309,36 @@ public class TestCellStyle assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##")); assertEquals(5, wbClone.getNumberOfFonts()); } + + public void testStyleNames() throws Exception { + HSSFWorkbook wb = openSample("WithExtendedStyles.xls"); + HSSFSheet s = wb.getSheetAt(0); + HSSFCell c1 = s.getRow(0).getCell(0); + HSSFCell c2 = s.getRow(1).getCell(0); + HSSFCell c3 = s.getRow(2).getCell(0); + + HSSFCellStyle cs1 = c1.getCellStyle(); + HSSFCellStyle cs2 = c2.getCellStyle(); + HSSFCellStyle cs3 = c3.getCellStyle(); + + assertNotNull(cs1); + assertNotNull(cs2); + assertNotNull(cs3); + + // Check we got the styles we'd expect + assertEquals(10, cs1.getFont(wb).getFontHeightInPoints()); + assertEquals(9, cs2.getFont(wb).getFontHeightInPoints()); + assertEquals(12, cs3.getFont(wb).getFontHeightInPoints()); + + assertEquals(15, cs1.getIndex()); + assertEquals(23, cs2.getIndex()); + assertEquals(24, cs3.getIndex()); + + // Now check the style names +// assertEquals(null, cs1.getUserStyleName()); +// assertEquals("style1", cs2.getUserStyleName()); +// assertEquals("style2", cs3.getUserStyleName()); + } public static void main(String [] ignored_args) {