From: Nick Burch Date: Thu, 14 Aug 2008 21:41:01 +0000 (+0000) Subject: More for bug #45623 - Support for additional HSSF header and footer fields, including... X-Git-Tag: REL_3_2_FINAL~156 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=098d400bac48674dee2b5b9d2542f6d8bdd42a21;p=poi.git More for bug #45623 - Support for additional HSSF header and footer fields, including bold and full file path git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@686053 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 2c5adef95a..e313d8ced4 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 45623 - Support for additional HSSF header and footer fields, including bold and full file path 45623 - Support stripping HSSF header and footer fields (eg page number) out of header and footer text if required 45622 - Support stripping HWPF fields (eg macros) out of text, via Range.stripFields(text) New HPSF based TextExtractor for document metadata, org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 9d64f5febc..f0352ea5f4 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 45623 - Support for additional HSSF header and footer fields, including bold and full file path 45623 - Support stripping HSSF header and footer fields (eg page number) out of header and footer text if required 45622 - Support stripping HWPF fields (eg macros) out of text, via Range.stripFields(text) New HPSF based TextExtractor for document metadata, org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor diff --git a/src/java/org/apache/poi/hssf/usermodel/HeaderFooter.java b/src/java/org/apache/poi/hssf/usermodel/HeaderFooter.java index f4c416bbff..2a2771e442 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HeaderFooter.java +++ b/src/java/org/apache/poi/hssf/usermodel/HeaderFooter.java @@ -120,7 +120,7 @@ public abstract class HeaderFooter { * Returns the string that represents the change in font. * * @param font the new font - * @param style the fonts style + * @param style the fonts style, one of regular, italic, bold, italic bold or bold italic * @return The special string to represent a new font size */ public static String font( String font, String style ) @@ -179,7 +179,25 @@ public abstract class HeaderFooter { * @return The special string for tab name */ public static String tab() { - return TAB_FIELD.sequence; + return SHEET_NAME_FIELD.sequence; + } + + /** + * Returns the string representing the start bold + * + * @return The special string for start bold + */ + public static String startBold() { + return BOLD_FIELD.sequence; + } + + /** + * Returns the string representing the end bold + * + * @return The special string for end bold + */ + public static String endBold() { + return BOLD_FIELD.sequence; } /** @@ -266,14 +284,23 @@ public abstract class HeaderFooter { } - public static final Field TAB_FIELD = new Field("&A"); + public static final Field SHEET_NAME_FIELD = new Field("&A"); public static final Field DATE_FIELD = new Field("&D"); public static final Field FILE_FIELD = new Field("&F"); + public static final Field FULL_FILE_FIELD = new Field("&Z"); public static final Field PAGE_FIELD = new Field("&P"); public static final Field TIME_FIELD = new Field("&T"); public static final Field NUM_PAGES_FIELD = new Field("&N"); - public static final Field UNDERLINE_FIELD = new Field("&U"); - public static final Field DOUBLE_UNDERLINE_FIELD = new Field("&E"); + + public static final Field PICTURE_FIELD = new Field("&P"); + + public static final PairField BOLD_FIELD = new PairField("&B"); // PAID + public static final PairField ITALIC_FIELD = new PairField("&I"); + public static final PairField STRIKETHROUGH_FIELD = new PairField("&S"); + public static final PairField SUBSCRIPT_FIELD = new PairField("&Y"); + public static final PairField SUPERSCRIPT_FIELD = new PairField("&X"); + public static final PairField UNDERLINE_FIELD = new PairField("&U"); + public static final PairField DOUBLE_UNDERLINE_FIELD = new PairField("&E"); /** * Represents a special field in a header or footer, @@ -288,4 +315,13 @@ public abstract class HeaderFooter { ALL_FIELDS.add(this); } } + /** + * A special field that normally comes in a pair, eg + * turn on underline / turn off underline + */ + public static class PairField extends Field { + private PairField(String sequence) { + super(sequence); + } + } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java index 59a1d1f817..caa75633b0 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java @@ -59,13 +59,15 @@ public final class TestHSSFHeaderFooter extends TestCase { String withPage = "I am a&P test header"; String withLots = "I&A am&N a&P test&T header&U"; String withFont = "I&22 am a&\"Arial,bold\" test header"; - String withOtherAnds = "I am a&P test header&Z"; + String withOtherAnds = "I am a&P test header&&"; + String withOtherAnds2 = "I am a&P test header&a&b"; assertEquals(simple, HSSFHeader.stripFields(simple)); assertEquals(simple, HSSFHeader.stripFields(withPage)); assertEquals(simple, HSSFHeader.stripFields(withLots)); assertEquals(simple, HSSFHeader.stripFields(withFont)); - assertEquals(simple + "&Z", HSSFHeader.stripFields(withOtherAnds)); + assertEquals(simple + "&&", HSSFHeader.stripFields(withOtherAnds)); + assertEquals(simple + "&a&b", HSSFHeader.stripFields(withOtherAnds2)); // Now test the default strip flag HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("EmbeddedChartHeaderTest.xls"); @@ -83,6 +85,10 @@ public final class TestHSSFHeaderFooter extends TestCase { head.setAreFieldsStripped(true); assertEquals("Top Left", head.getLeft()); assertTrue(head.areFieldsStripped()); + + // Now even more complex + head.setCenter("HEADER TEXT &P&N&D&T&Z&F&F&A&G"); + assertEquals("HEADER TEXT &G", head.getCenter()); } /**