Fix bug #50756 - When formatting numbers based on their Cell Style, treat GENERAL the same as the more typical General
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1069775 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2f15806b6e
commit
d1aab350fd
@ -34,6 +34,7 @@
|
||||
|
||||
<changes>
|
||||
<release version="3.8-beta1" date="2010-??-??">
|
||||
<action dev="poi-developers" type="fix">50756 - When formatting numbers based on their Cell Style, treat GENERAL the same as the more typical General</action>
|
||||
<action dev="poi-developers" type="fix">fixed HSSFWorkbook.createCellStyle to throw exception if the maximum number of cell styles was exceeded</action>
|
||||
<action dev="poi-developers" type="fix">50539 - Better fix for html-style br tags (invalid XML) inside XSSF documents</action>
|
||||
<action dev="poi-developers" type="add">49928 - allow overridden built-in formats in HSSFCellStyle</action>
|
||||
|
@ -196,7 +196,7 @@ public class DataFormatter {
|
||||
if (format != null) {
|
||||
return format;
|
||||
}
|
||||
if ("General".equals(formatStr) || "@".equals(formatStr)) {
|
||||
if ("General".equalsIgnoreCase(formatStr) || "@".equals(formatStr)) {
|
||||
if (DataFormatter.isWholeNumber(cellValue)) {
|
||||
return generalWholeNumFormat;
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ import org.apache.poi.ss.formula.ptg.Ptg;
|
||||
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
import org.apache.poi.ss.usermodel.Name;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
@ -1953,4 +1954,36 @@ if(1==2) {
|
||||
assertEquals("Cell A,1", sheet.getRow(1).getCell(0).getStringCellValue());
|
||||
assertEquals("Cell A,3", sheet.getRow(2).getCell(0).getStringCellValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* If you send a file between Excel and OpenOffice enough, something
|
||||
* will turn the "General" format into "GENERAL"
|
||||
*/
|
||||
public void test50756() throws Exception {
|
||||
HSSFWorkbook wb = openSample("50756.xls");
|
||||
HSSFSheet s = wb.getSheetAt(0);
|
||||
HSSFRow r17 = s.getRow(16);
|
||||
HSSFRow r18 = s.getRow(17);
|
||||
HSSFDataFormatter df = new HSSFDataFormatter();
|
||||
|
||||
assertEquals(10.0, r17.getCell(1).getNumericCellValue());
|
||||
assertEquals(20.0, r17.getCell(2).getNumericCellValue());
|
||||
assertEquals(20.0, r17.getCell(3).getNumericCellValue());
|
||||
assertEquals("GENERAL", r17.getCell(1).getCellStyle().getDataFormatString());
|
||||
assertEquals("GENERAL", r17.getCell(2).getCellStyle().getDataFormatString());
|
||||
assertEquals("GENERAL", r17.getCell(3).getCellStyle().getDataFormatString());
|
||||
assertEquals("10", df.formatCellValue(r17.getCell(1)));
|
||||
assertEquals("20", df.formatCellValue(r17.getCell(2)));
|
||||
assertEquals("20", df.formatCellValue(r17.getCell(3)));
|
||||
|
||||
assertEquals(16.0, r18.getCell(1).getNumericCellValue());
|
||||
assertEquals(35.0, r18.getCell(2).getNumericCellValue());
|
||||
assertEquals(123.0, r18.getCell(3).getNumericCellValue());
|
||||
assertEquals("GENERAL", r18.getCell(1).getCellStyle().getDataFormatString());
|
||||
assertEquals("GENERAL", r18.getCell(2).getCellStyle().getDataFormatString());
|
||||
assertEquals("GENERAL", r18.getCell(3).getCellStyle().getDataFormatString());
|
||||
assertEquals("16", df.formatCellValue(r18.getCell(1)));
|
||||
assertEquals("35", df.formatCellValue(r18.getCell(2)));
|
||||
assertEquals("123", df.formatCellValue(r18.getCell(3)));
|
||||
}
|
||||
}
|
||||
|
BIN
test-data/spreadsheet/50756.xls
Normal file
BIN
test-data/spreadsheet/50756.xls
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user