mirror of https://github.com/apache/poi.git
bug 58775: use short for data format index, int for cell style index
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1721930 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
35c8e0c5ed
commit
cac40dd101
|
@ -1322,11 +1322,10 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
* get the number of styles the workbook contains
|
* get the number of styles the workbook contains
|
||||||
* @return count of cell styles
|
* @return count of cell styles
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short getNumCellStyles()
|
public int getNumCellStyles()
|
||||||
{
|
{
|
||||||
return (short) workbook.getNumExFormats();
|
return workbook.getNumExFormats();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1335,10 +1334,10 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
* @return HSSFCellStyle object at the index
|
* @return HSSFCellStyle object at the index
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HSSFCellStyle getCellStyleAt(short idx)
|
public HSSFCellStyle getCellStyleAt(int idx)
|
||||||
{
|
{
|
||||||
ExtendedFormatRecord xfr = workbook.getExFormatAt(idx);
|
ExtendedFormatRecord xfr = workbook.getExFormatAt(idx);
|
||||||
HSSFCellStyle style = new HSSFCellStyle(idx, xfr, this);
|
HSSFCellStyle style = new HSSFCellStyle((short)idx, xfr, this);
|
||||||
|
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,7 +344,7 @@ public interface Workbook extends Closeable, Iterable<Sheet> {
|
||||||
*
|
*
|
||||||
* @return count of cell styles
|
* @return count of cell styles
|
||||||
*/
|
*/
|
||||||
short getNumCellStyles();
|
int getNumCellStyles();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cell style object at the given index
|
* Get the cell style object at the given index
|
||||||
|
@ -352,7 +352,7 @@ public interface Workbook extends Closeable, Iterable<Sheet> {
|
||||||
* @param idx index within the set of styles (0-based)
|
* @param idx index within the set of styles (0-based)
|
||||||
* @return CellStyle object at the index
|
* @return CellStyle object at the index
|
||||||
*/
|
*/
|
||||||
CellStyle getCellStyleAt(short idx);
|
CellStyle getCellStyleAt(int idx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write out this workbook to an Outputstream.
|
* Write out this workbook to an Outputstream.
|
||||||
|
|
|
@ -189,9 +189,9 @@ public final class CellUtil {
|
||||||
|
|
||||||
// index seems like what index the cellstyle is in the list of styles for a workbook.
|
// index seems like what index the cellstyle is in the list of styles for a workbook.
|
||||||
// not good to compare on!
|
// not good to compare on!
|
||||||
short numberCellStyles = workbook.getNumCellStyles();
|
int numberCellStyles = workbook.getNumCellStyles();
|
||||||
|
|
||||||
for (short i = 0; i < numberCellStyles; i++) {
|
for (int i = 0; i < numberCellStyles; i++) {
|
||||||
CellStyle wbStyle = workbook.getCellStyleAt(i);
|
CellStyle wbStyle = workbook.getCellStyleAt(i);
|
||||||
Map<String, Object> wbStyleMap = getFormatProperties(wbStyle);
|
Map<String, Object> wbStyleMap = getFormatProperties(wbStyle);
|
||||||
|
|
||||||
|
|
|
@ -877,7 +877,7 @@ public class SXSSFWorkbook implements Workbook {
|
||||||
* @return count of cell styles
|
* @return count of cell styles
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public short getNumCellStyles()
|
public int getNumCellStyles()
|
||||||
{
|
{
|
||||||
return _wb.getNumCellStyles();
|
return _wb.getNumCellStyles();
|
||||||
}
|
}
|
||||||
|
@ -889,7 +889,7 @@ public class SXSSFWorkbook implements Workbook {
|
||||||
* @return CellStyle object at the index
|
* @return CellStyle object at the index
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CellStyle getCellStyleAt(short idx)
|
public CellStyle getCellStyleAt(int idx)
|
||||||
{
|
{
|
||||||
return _wb.getCellStyleAt(idx);
|
return _wb.getCellStyleAt(idx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -853,16 +853,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
||||||
return pictures; //YK: should return Collections.unmodifiableList(pictures);
|
return pictures; //YK: should return Collections.unmodifiableList(pictures);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the cell style object at the given index
|
|
||||||
*
|
|
||||||
* @param idx index within the set of styles
|
|
||||||
* @return XSSFCellStyle object at the index
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public XSSFCellStyle getCellStyleAt(short idx) {
|
|
||||||
return getCellStyleAt(idx&0xffff);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Get the cell style object at the given index
|
* Get the cell style object at the given index
|
||||||
*
|
*
|
||||||
|
@ -931,9 +921,8 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
||||||
*
|
*
|
||||||
* @return count of cell styles
|
* @return count of cell styles
|
||||||
*/
|
*/
|
||||||
@Override
|
public int getNumCellStyles() {
|
||||||
public short getNumCellStyles() {
|
return stylesSource.getNumCellStyles();
|
||||||
return (short) (stylesSource).getNumCellStyles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2507,6 +2507,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
||||||
XSSFCellStyle style = wb.createCellStyle();
|
XSSFCellStyle style = wb.createCellStyle();
|
||||||
assertEquals(i, style.getUIndex());
|
assertEquals(i, style.getUIndex());
|
||||||
}
|
}
|
||||||
|
assertEquals(numStyles, wb.getNumCellStyles());
|
||||||
|
|
||||||
// avoid OOM in gump run
|
// avoid OOM in gump run
|
||||||
File file = XSSFTestDataSamples.writeOutAndClose(wb, "bug57880");
|
File file = XSSFTestDataSamples.writeOutAndClose(wb, "bug57880");
|
||||||
|
@ -2522,6 +2523,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
||||||
//Assume identical cell styles aren't consolidated
|
//Assume identical cell styles aren't consolidated
|
||||||
//If XSSFWorkbooks ever implicitly optimize/consolidate cell styles (such as when the workbook is written to disk)
|
//If XSSFWorkbooks ever implicitly optimize/consolidate cell styles (such as when the workbook is written to disk)
|
||||||
//then this unit test should be updated
|
//then this unit test should be updated
|
||||||
|
assertEquals(numStyles, wb.getNumCellStyles());
|
||||||
for (int i=1; i<numStyles; i++) {
|
for (int i=1; i<numStyles; i++) {
|
||||||
XSSFCellStyle style = wb.getCellStyleAt(i);
|
XSSFCellStyle style = wb.getCellStyleAt(i);
|
||||||
assertNotNull(style);
|
assertNotNull(style);
|
||||||
|
|
|
@ -1019,9 +1019,9 @@ public class TestXSSFCellStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyStyles(Workbook reference, Workbook target) {
|
public static void copyStyles(Workbook reference, Workbook target) {
|
||||||
final short numberOfStyles = reference.getNumCellStyles();
|
final int numberOfStyles = reference.getNumCellStyles();
|
||||||
// don't copy default style (style index 0)
|
// don't copy default style (style index 0)
|
||||||
for (short i = 1; i < numberOfStyles; i++) {
|
for (int i = 1; i < numberOfStyles; i++) {
|
||||||
final CellStyle referenceStyle = reference.getCellStyleAt(i);
|
final CellStyle referenceStyle = reference.getCellStyleAt(i);
|
||||||
final CellStyle targetStyle = target.createCellStyle();
|
final CellStyle targetStyle = target.createCellStyle();
|
||||||
targetStyle.cloneStyleFrom(referenceStyle);
|
targetStyle.cloneStyleFrom(referenceStyle);
|
||||||
|
|
|
@ -225,9 +225,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
|
||||||
public void getNumCellStyles() throws IOException{
|
public void getNumCellStyles() throws IOException{
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
try {
|
try {
|
||||||
short i = workbook.getNumCellStyles();
|
|
||||||
//get default cellStyles
|
//get default cellStyles
|
||||||
assertEquals(1, i);
|
assertEquals(1, workbook.getNumCellStyles());
|
||||||
} finally {
|
} finally {
|
||||||
workbook.close();
|
workbook.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2006,7 +2006,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
|
||||||
@Test
|
@Test
|
||||||
public void bug49751() throws Exception {
|
public void bug49751() throws Exception {
|
||||||
HSSFWorkbook wb = openSample("49751.xls");
|
HSSFWorkbook wb = openSample("49751.xls");
|
||||||
short numCellStyles = wb.getNumCellStyles();
|
int numCellStyles = wb.getNumCellStyles();
|
||||||
List<String> namedStyles = Arrays.asList(
|
List<String> namedStyles = Arrays.asList(
|
||||||
"20% - Accent1", "20% - Accent2", "20% - Accent3", "20% - Accent4", "20% - Accent5",
|
"20% - Accent1", "20% - Accent2", "20% - Accent3", "20% - Accent4", "20% - Accent5",
|
||||||
"20% - Accent6", "40% - Accent1", "40% - Accent2", "40% - Accent3", "40% - Accent4",
|
"20% - Accent6", "40% - Accent1", "40% - Accent2", "40% - Accent3", "40% - Accent4",
|
||||||
|
@ -2017,7 +2017,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
|
||||||
"Neutral", "Note", "Output", "Title", "Total", "Warning Text");
|
"Neutral", "Note", "Output", "Title", "Total", "Warning Text");
|
||||||
|
|
||||||
List<String> collecteddStyles = new ArrayList<String>();
|
List<String> collecteddStyles = new ArrayList<String>();
|
||||||
for (short i = 0; i < numCellStyles; i++) {
|
for (int i = 0; i < numCellStyles; i++) {
|
||||||
HSSFCellStyle cellStyle = wb.getCellStyleAt(i);
|
HSSFCellStyle cellStyle = wb.getCellStyleAt(i);
|
||||||
String styleName = cellStyle.getUserStyleName();
|
String styleName = cellStyle.getUserStyleName();
|
||||||
if (styleName != null) {
|
if (styleName != null) {
|
||||||
|
|
Loading…
Reference in New Issue