Tweak how you get dataformat strings out of cell styles, to be more logical, and in keeping with how we'll want to do things for xssf too

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@639836 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2008-03-21 21:04:47 +00:00
parent 9162d07625
commit ce8c6149ff
3 changed files with 24 additions and 9 deletions

View File

@ -211,7 +211,7 @@ public class HSSFCell
} }
ExtendedFormatRecord xf = book.getExFormatAt(cval.getXFIndex()); ExtendedFormatRecord xf = book.getExFormatAt(cval.getXFIndex());
setCellStyle(new HSSFCellStyle(( short ) cval.getXFIndex(), xf)); setCellStyle(new HSSFCellStyle(( short ) cval.getXFIndex(), xf, book));
} }
/** /**
@ -914,7 +914,7 @@ public class HSSFCell
{ {
short styleIndex=record.getXFIndex(); short styleIndex=record.getXFIndex();
ExtendedFormatRecord xf = book.getExFormatAt(styleIndex); ExtendedFormatRecord xf = book.getExFormatAt(styleIndex);
return new HSSFCellStyle(styleIndex, xf); return new HSSFCellStyle(styleIndex, xf, book);
} }
/** /**

View File

@ -20,7 +20,7 @@ package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.ExtendedFormatRecord; import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.util.*; import org.apache.poi.hssf.util.HSSFColor;
/** /**
* High level representation of the style of a cell in a sheet of a workbook. * High level representation of the style of a cell in a sheet of a workbook.
@ -38,6 +38,7 @@ public class HSSFCellStyle
{ {
private ExtendedFormatRecord format = null; private ExtendedFormatRecord format = null;
private short index = 0; private short index = 0;
private Workbook workbook = null;
/** /**
* general (normal) horizontal alignment * general (normal) horizontal alignment
@ -230,9 +231,13 @@ public class HSSFCellStyle
/** Creates new HSSFCellStyle why would you want to do this?? */ /** Creates new HSSFCellStyle why would you want to do this?? */
protected HSSFCellStyle(short index, ExtendedFormatRecord rec, HSSFWorkbook workbook)
protected HSSFCellStyle(short index, ExtendedFormatRecord rec)
{ {
this(index, rec, workbook.getWorkbook());
}
protected HSSFCellStyle(short index, ExtendedFormatRecord rec, Workbook workbook)
{
this.workbook = workbook;
this.index = index; this.index = index;
format = rec; format = rec;
} }
@ -268,6 +273,16 @@ public class HSSFCellStyle
return format.getFormatIndex(); return format.getFormatIndex();
} }
/**
* Get the contents of the format string, by looking up
* the DataFormat against the bound workbook
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
*/
public String getDataFormatString() {
HSSFDataFormat format = new HSSFDataFormat(workbook);
return format.getFormat(getDataFormat());
}
/** /**
* Get the contents of the format string, by looking up * Get the contents of the format string, by looking up
* the DataFormat against the supplied workbook * the DataFormat against the supplied workbook
@ -289,7 +304,7 @@ public class HSSFCellStyle
public void setFont(HSSFFont font) public void setFont(HSSFFont font)
{ {
format.setIndentNotParentFont(true); format.setIndentNotParentFont(true);
short fontindex = font.getIndex(); short fontindex = ((HSSFFont) font).getIndex();
format.setFontIndex(fontindex); format.setFontIndex(fontindex);
} }
@ -309,7 +324,7 @@ public class HSSFCellStyle
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short) * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
*/ */
public HSSFFont getFont(HSSFWorkbook parentWorkbook) { public HSSFFont getFont(HSSFWorkbook parentWorkbook) {
return parentWorkbook.getFontAt(getFontIndex()); return ((HSSFWorkbook) parentWorkbook).getFontAt(getFontIndex());
} }
/** /**

View File

@ -903,7 +903,7 @@ public class HSSFWorkbook extends POIDocument
{ {
ExtendedFormatRecord xfr = workbook.createCellXF(); ExtendedFormatRecord xfr = workbook.createCellXF();
short index = (short) (getNumCellStyles() - 1); short index = (short) (getNumCellStyles() - 1);
HSSFCellStyle style = new HSSFCellStyle(index, xfr); HSSFCellStyle style = new HSSFCellStyle(index, xfr, this);
return style; return style;
} }
@ -927,7 +927,7 @@ public class HSSFWorkbook extends POIDocument
public HSSFCellStyle getCellStyleAt(short idx) public HSSFCellStyle getCellStyleAt(short idx)
{ {
ExtendedFormatRecord xfr = workbook.getExFormatAt(idx); ExtendedFormatRecord xfr = workbook.getExFormatAt(idx);
HSSFCellStyle style = new HSSFCellStyle(idx, xfr); HSSFCellStyle style = new HSSFCellStyle(idx, xfr, this);
return style; return style;
} }