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:
parent
9162d07625
commit
ce8c6149ff
@ -211,7 +211,7 @@ public class HSSFCell
|
||||
}
|
||||
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();
|
||||
ExtendedFormatRecord xf = book.getExFormatAt(styleIndex);
|
||||
return new HSSFCellStyle(styleIndex, xf);
|
||||
return new HSSFCellStyle(styleIndex, xf, book);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@ package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.model.Workbook;
|
||||
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.
|
||||
@ -38,6 +38,7 @@ public class HSSFCellStyle
|
||||
{
|
||||
private ExtendedFormatRecord format = null;
|
||||
private short index = 0;
|
||||
private Workbook workbook = null;
|
||||
|
||||
/**
|
||||
* general (normal) horizontal alignment
|
||||
@ -230,9 +231,13 @@ public class HSSFCellStyle
|
||||
|
||||
|
||||
/** Creates new HSSFCellStyle why would you want to do this?? */
|
||||
|
||||
protected HSSFCellStyle(short index, ExtendedFormatRecord rec)
|
||||
protected HSSFCellStyle(short index, ExtendedFormatRecord rec, HSSFWorkbook workbook)
|
||||
{
|
||||
this(index, rec, workbook.getWorkbook());
|
||||
}
|
||||
protected HSSFCellStyle(short index, ExtendedFormatRecord rec, Workbook workbook)
|
||||
{
|
||||
this.workbook = workbook;
|
||||
this.index = index;
|
||||
format = rec;
|
||||
}
|
||||
@ -268,6 +273,16 @@ public class HSSFCellStyle
|
||||
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
|
||||
* the DataFormat against the supplied workbook
|
||||
@ -289,7 +304,7 @@ public class HSSFCellStyle
|
||||
public void setFont(HSSFFont font)
|
||||
{
|
||||
format.setIndentNotParentFont(true);
|
||||
short fontindex = font.getIndex();
|
||||
short fontindex = ((HSSFFont) font).getIndex();
|
||||
format.setFontIndex(fontindex);
|
||||
}
|
||||
|
||||
@ -309,7 +324,7 @@ public class HSSFCellStyle
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
|
||||
*/
|
||||
public HSSFFont getFont(HSSFWorkbook parentWorkbook) {
|
||||
return parentWorkbook.getFontAt(getFontIndex());
|
||||
return ((HSSFWorkbook) parentWorkbook).getFontAt(getFontIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -903,7 +903,7 @@ public class HSSFWorkbook extends POIDocument
|
||||
{
|
||||
ExtendedFormatRecord xfr = workbook.createCellXF();
|
||||
short index = (short) (getNumCellStyles() - 1);
|
||||
HSSFCellStyle style = new HSSFCellStyle(index, xfr);
|
||||
HSSFCellStyle style = new HSSFCellStyle(index, xfr, this);
|
||||
|
||||
return style;
|
||||
}
|
||||
@ -927,7 +927,7 @@ public class HSSFWorkbook extends POIDocument
|
||||
public HSSFCellStyle getCellStyleAt(short idx)
|
||||
{
|
||||
ExtendedFormatRecord xfr = workbook.getExFormatAt(idx);
|
||||
HSSFCellStyle style = new HSSFCellStyle(idx, xfr);
|
||||
HSSFCellStyle style = new HSSFCellStyle(idx, xfr, this);
|
||||
|
||||
return style;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user