Added underline capability to the header and footer.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353648 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shawn Laubach 2005-04-22 14:56:35 +00:00
parent 5bb531e555
commit c0ba718df8
2 changed files with 241 additions and 161 deletions

View File

@ -33,184 +33,224 @@ import org.apache.poi.hssf.record.FooterRecord;
*/ */
public class HSSFFooter extends Object { public class HSSFFooter extends Object {
FooterRecord footerRecord; FooterRecord footerRecord;
String left; String left;
String center; String center;
String right; String right;
/** /**
* Constructor. Creates a new footer interface from a footer record * Constructor. Creates a new footer interface from a footer record
* @param footerRecord Footer record to create the footer with * @param footerRecord Footer record to create the footer with
*/ */
protected HSSFFooter(FooterRecord footerRecord) { protected HSSFFooter(FooterRecord footerRecord) {
this.footerRecord = footerRecord; this.footerRecord = footerRecord;
String foot = footerRecord.getFooter(); String foot = footerRecord.getFooter();
while (foot != null && foot.length() > 1) { while (foot != null && foot.length() > 1) {
int pos = foot.length(); int pos = foot.length();
switch (foot.substring(1, 2).charAt(0)) { switch (foot.substring(1, 2).charAt(0)) {
case 'L' : case 'L' :
if (foot.indexOf("&C") >= 0) { if (foot.indexOf("&C") >= 0) {
pos = Math.min(pos, foot.indexOf("&C")); pos = Math.min(pos, foot.indexOf("&C"));
} }
if (foot.indexOf("&R") >= 0) { if (foot.indexOf("&R") >= 0) {
pos = Math.min(pos, foot.indexOf("&R")); pos = Math.min(pos, foot.indexOf("&R"));
} }
left = foot.substring(2, pos); left = foot.substring(2, pos);
foot = foot.substring(pos); foot = foot.substring(pos);
break; break;
case 'C' : case 'C' :
if (foot.indexOf("&L") >= 0) { if (foot.indexOf("&L") >= 0) {
pos = Math.min(pos, foot.indexOf("&L")); pos = Math.min(pos, foot.indexOf("&L"));
} }
if (foot.indexOf("&R") >= 0) { if (foot.indexOf("&R") >= 0) {
pos = Math.min(pos, foot.indexOf("&R")); pos = Math.min(pos, foot.indexOf("&R"));
} }
center = foot.substring(2, pos); center = foot.substring(2, pos);
foot = foot.substring(pos); foot = foot.substring(pos);
break; break;
case 'R' : case 'R' :
if (foot.indexOf("&C") >= 0) { if (foot.indexOf("&C") >= 0) {
pos = Math.min(pos, foot.indexOf("&C")); pos = Math.min(pos, foot.indexOf("&C"));
} }
if (foot.indexOf("&L") >= 0) { if (foot.indexOf("&L") >= 0) {
pos = Math.min(pos, foot.indexOf("&L")); pos = Math.min(pos, foot.indexOf("&L"));
} }
right = foot.substring(2, pos); right = foot.substring(2, pos);
foot = foot.substring(pos); foot = foot.substring(pos);
break; break;
default : foot = null; default : foot = null;
}
} }
} }
}
/** /**
* Get the left side of the footer. * Get the left side of the footer.
* @return The string representing the left side. * @return The string representing the left side.
*/ */
public String getLeft() { public String getLeft() {
return left; return left;
} }
/** /**
* Sets the left string. * Sets the left string.
* @param newLeft The string to set as the left side. * @param newLeft The string to set as the left side.
*/ */
public void setLeft(String newLeft) { public void setLeft(String newLeft) {
left = newLeft; left = newLeft;
createFooterString(); createFooterString();
} }
/** /**
* Get the center of the footer. * Get the center of the footer.
* @return The string representing the center. * @return The string representing the center.
*/ */
public String getCenter() { public String getCenter() {
return center; return center;
} }
/** /**
* Sets the center string. * Sets the center string.
* @param newCenter The string to set as the center. * @param newCenter The string to set as the center.
*/ */
public void setCenter(String newCenter) { public void setCenter(String newCenter) {
center = newCenter; center = newCenter;
createFooterString(); createFooterString();
} }
/** /**
* Get the right side of the footer. * Get the right side of the footer.
* @return The string representing the right side. * @return The string representing the right side.
*/ */
public String getRight() { public String getRight() {
return right; return right;
} }
/** /**
* Sets the right string. * Sets the right string.
* @param newRight The string to set as the right side. * @param newRight The string to set as the right side.
*/ */
public void setRight(String newRight) { public void setRight(String newRight) {
right = newRight; right = newRight;
createFooterString(); createFooterString();
} }
/** /**
* Creates the complete footer string based on the left, center, and middle * Creates the complete footer string based on the left, center, and middle
* strings. * strings.
*/ */
private void createFooterString() { private void createFooterString() {
footerRecord.setFooter( footerRecord.setFooter(
"&C" + (center == null ? "" : center) + "&C" + (center == null ? "" : center) +
"&L" + (left == null ? "" : left) + "&L" + (left == null ? "" : left) +
"&R" + (right == null ? "" : right)); "&R" + (right == null ? "" : right));
footerRecord.setFooterLength((byte)footerRecord.getFooter().length()); footerRecord.setFooterLength((byte)footerRecord.getFooter().length());
} }
/** /**
* Returns the string that represents the change in font size. * Returns the string that represents the change in font size.
* @param size the new font size * @param size the new font size
* @return The special string to represent a new font size * @return The special string to represent a new font size
*/ */
public static String fontSize(short size) { public static String fontSize(short size) {
return "&" + size; return "&" + size;
} }
/** /**
* Returns the string that represents the change in font. * Returns the string that represents the change in font.
* @param font the new font * @param font the new font
* @param style the fonts style * @param style the fonts style
* @return The special string to represent a new font size * @return The special string to represent a new font size
*/ */
public static String font(String font, String style) { public static String font(String font, String style) {
return "&\"" + font + "," + style + "\""; return "&\"" + font + "," + style + "\"";
} }
/** /**
* Returns the string representing the current page number * Returns the string representing the current page number
* @return The special string for page number * @return The special string for page number
*/ */
public static String page() { public static String page() {
return "&P"; return "&P";
} }
/** /**
* Returns the string representing the number of pages. * Returns the string representing the number of pages.
* @return The special string for the number of pages * @return The special string for the number of pages
*/ */
public static String numPages() { public static String numPages() {
return "&N"; return "&N";
} }
/** /**
* Returns the string representing the current date * Returns the string representing the current date
* @return The special string for the date * @return The special string for the date
*/ */
public static String date() { public static String date() {
return "&D"; return "&D";
} }
/** /**
* Returns the string representing the current time * Returns the string representing the current time
* @return The special string for the time * @return The special string for the time
*/ */
public static String time() { public static String time() {
return "&T"; return "&T";
} }
/** /**
* Returns the string representing the current file name * Returns the string representing the current file name
* @return The special string for the file name * @return The special string for the file name
*/ */
public static String file() { public static String file() {
return "&F"; return "&F";
} }
/** /**
* Returns the string representing the current tab (sheet) name * Returns the string representing the current tab (sheet) name
* @return The special string for tab name * @return The special string for tab name
*/ */
public static String tab() { public static String tab() {
return "&A"; return "&A";
} }
/**
* Returns the string representing the start underline
*
* @return The special string for start underline
*/
public static String startUnderline()
{
return "&U";
}
/**
* Returns the string representing the end underline
*
* @return The special string for end underline
*/
public static String endUnderline()
{
return "&U";
}
/**
* Returns the string representing the start double underline
*
* @return The special string for start double underline
*/
public static String startDoubleUnderline()
{
return "&E";
}
/**
* Returns the string representing the end double underline
*
* @return The special string for end double underline
*/
public static String endDoubleUnderline()
{
return "&E";
}
} }

View File

@ -252,5 +252,45 @@ public class HSSFHeader
{ {
return "&A"; return "&A";
} }
/**
* Returns the string representing the start underline
*
* @return The special string for start underline
*/
public static String startUnderline()
{
return "&U";
}
/**
* Returns the string representing the end underline
*
* @return The special string for end underline
*/
public static String endUnderline()
{
return "&U";
}
/**
* Returns the string representing the start double underline
*
* @return The special string for start double underline
*/
public static String startDoubleUnderline()
{
return "&E";
}
/**
* Returns the string representing the end double underline
*
* @return The special string for end double underline
*/
public static String endDoubleUnderline()
{
return "&E";
}
} }