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
This commit is contained in:
Nick Burch 2008-08-14 21:41:01 +00:00
parent f4b314c1fe
commit c4a69b0b45
4 changed files with 51 additions and 7 deletions

View File

@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.1.1-alpha1" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="add">45623 - Support for additional HSSF header and footer fields, including bold and full file path</action>
<action dev="POI-DEVELOPERS" type="add">45623 - Support stripping HSSF header and footer fields (eg page number) out of header and footer text if required</action>
<action dev="POI-DEVELOPERS" type="add">45622 - Support stripping HWPF fields (eg macros) out of text, via Range.stripFields(text)</action>
<action dev="POI-DEVELOPERS" type="add">New HPSF based TextExtractor for document metadata, org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor</action>

View File

@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1.1-alpha1" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="add">45623 - Support for additional HSSF header and footer fields, including bold and full file path</action>
<action dev="POI-DEVELOPERS" type="add">45623 - Support stripping HSSF header and footer fields (eg page number) out of header and footer text if required</action>
<action dev="POI-DEVELOPERS" type="add">45622 - Support stripping HWPF fields (eg macros) out of text, via Range.stripFields(text)</action>
<action dev="POI-DEVELOPERS" type="add">New HPSF based TextExtractor for document metadata, org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor</action>

View File

@ -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);
}
}
}

View File

@ -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());
}
/**