ASF Bugzilla – Attachment 9248 Details for
Bug 24925
Nested IF Formula results in "#VALUE!" in Excel
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
the test file in java
TestXLSWriter.java (text/plain), 2.85 KB, created by
Alec Beaton
on 2003-11-23 08:04:47 UTC
(
hide
)
Description:
the test file in java
Filename:
MIME Type:
Creator:
Alec Beaton
Created:
2003-11-23 08:04:47 UTC
Size:
2.85 KB
patch
obsolete
> >import org.apache.poi.hssf.usermodel.HSSFCell; >import org.apache.poi.hssf.usermodel.HSSFCellStyle; >import org.apache.poi.hssf.usermodel.HSSFDataFormat; >import org.apache.poi.hssf.usermodel.HSSFRow; >import org.apache.poi.hssf.usermodel.HSSFSheet; >import org.apache.poi.hssf.usermodel.HSSFWorkbook; > >import java.io.FileOutputStream; > > >/** > * A Writer which writes to XLS file wit the #VALUE! problem > * > */ >public class TestXLSWriter { > > public static final int COLUMN_A = 0; > public static final int COLUMN_B = 1; > public static final int COLUMN_C = 2; > public static final int COLUMN_D = 3; > > /** > * Creates a new demo. > */ > public TestXLSWriter() { > } > > public void write() > throws Exception { > HSSFWorkbook wb = createTestWorkbook(); > FileOutputStream out = new FileOutputStream("test.xls"); > wb.write(out); > out.close(); > } > > private HSSFWorkbook createTestWorkbook() > throws Exception { > > HSSFWorkbook wb = new HSSFWorkbook(); > HSSFSheet sheet = wb.createSheet("Test Sheet"); > > HSSFRow row; > HSSFCell cell; > > // Create a row and put some cells in it. Rows are 0 based. > row = sheet.createRow((short)0); > > // Create a cell > cell = row.createCell((short)COLUMN_A); > cell.setCellValue(50); > > cell = row.createCell((short)COLUMN_B); > cell.setCellValue(100); > > cell = row.createCell((short)COLUMN_C); > cell.setCellFormula("A1/B1"); > // Although problem occurs with or without representing > // fraction using precent style I use it in my > // program and that's why I put it in the test. > HSSFCellStyle style = wb.createCellStyle(); > style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0%")); > cell.setCellStyle(style); > > cell = row.createCell((short)COLUMN_D); > // Here is the problem : > // basically I want 0 if C1 < 0.3, 2 if C1 > 0.8 and 1 if in between. > // In real life I will turn 0,1,2 to "Failed", "OK", "GOOD" > // why does this line produce #VALUE! ??? > // However when I enter excel 97/XP and click inside this value > // it works. > // Moreover, I know that for sure the nested IF is the problem. > cell.setCellFormula("IF(C1<0.3, 0, IF(C1>0.8, 2, 1))"); > > // Other setCellFormulas that work are : > // without nested IF it works > //cell.setCellFormula("IF(C1<0.3, 0, 1)"); > > // if I try with 30% the parser fails. > // cell.setCellFormula("IF(C1<30%, 0, IF(C1>80%, 2, 1))"); > > return wb; > } > > public static void main (String[] args) throws Exception { > System.out.println("DEBUG: hello"); > TestXLSWriter w = new TestXLSWriter(); > w.write(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 24925
: 9248 |
9249
|
10961
|
10962