<!-- Don't forget to update status.xml too! -->
<release version="3.1-beta1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">44606 - Support calculated string values for evaluated formulas</action>
<action dev="POI-DEVELOPERS" type="add">Add accessors to horizontal and vertical alignment in HSSFTextbox</action>
<action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</action>
<action dev="POI-DEVELOPERS" type="add">28627 / 44580 - Fix Range.delete() in HWPF</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1-beta1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">44606 - Support calculated string values for evaluated formulas</action>
<action dev="POI-DEVELOPERS" type="add">Add accessors to horizontal and vertical alignment in HSSFTextbox</action>
<action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</action>
<action dev="POI-DEVELOPERS" type="add">28627 / 44580 - Fix Range.delete() in HWPF</action>
* change the cell to a string cell and set its value.
* If value is null then we will change the cell to a Blank cell.
*/
-
- public void setCellValue(HSSFRichTextString value)
- {
+ public void setCellValue(HSSFRichTextString value) {
int row=record.getRow();
short col=record.getColumn();
short styleIndex=record.getXFIndex();
- if (value == null)
- {
+ if (value == null) {
setCellType(CELL_TYPE_BLANK, false, row, col, styleIndex);
+ return;
}
- else
- {
- if ((cellType != CELL_TYPE_STRING ) && ( cellType != CELL_TYPE_FORMULA))
- {
- setCellType(CELL_TYPE_STRING, false, row, col, styleIndex);
- }
- int index = 0;
-
- UnicodeString str = value.getUnicodeString();
-// jmh if (encoding == ENCODING_COMPRESSED_UNICODE)
-// jmh {
-// jmh str.setCompressedUnicode();
-// jmh } else if (encoding == ENCODING_UTF_16)
-// jmh {
-// jmh str.setUncompressedUnicode();
-// jmh }
- index = book.addSSTString(str);
- (( LabelSSTRecord ) record).setSSTIndex(index);
- stringValue = value;
- stringValue.setWorkbookReferences(book, (( LabelSSTRecord ) record));
- stringValue.setUnicodeString(book.getSSTString(index));
+ if (cellType == CELL_TYPE_FORMULA) {
+ // Set the 'pre-evaluated result' for the formula
+ // note - formulas do not preserve text formatting.
+ FormulaRecordAggregate fr = (FormulaRecordAggregate) record;
+ // must make new sr because fr.getStringRecord() may be null
+ StringRecord sr = new StringRecord();
+ sr.setString(value.getString()); // looses format
+ fr.setStringRecord(sr);
+ return;
+ }
+
+ if (cellType != CELL_TYPE_STRING) {
+ setCellType(CELL_TYPE_STRING, false, row, col, styleIndex);
}
+ int index = 0;
+
+ UnicodeString str = value.getUnicodeString();
+ index = book.addSSTString(str);
+ (( LabelSSTRecord ) record).setSSTIndex(index);
+ stringValue = value;
+ stringValue.setWorkbookReferences(book, (( LabelSSTRecord ) record));
+ stringValue.setUnicodeString(book.getSSTString(index));
}
public void setCellFormula(String formula) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.GregorianCalendar;
-import java.util.List;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hssf.model.Sheet;
-import org.apache.poi.hssf.record.HyperlinkRecord;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.TempFile;
* @author Dan Sherman (dsherman at isisph.com)
* @author Alex Jacoby (ajacoby at gmail.com)
*/
-
-public class TestHSSFCell
-extends TestCase {
- public TestHSSFCell(String s) {
- super(s);
- }
+public final class TestHSSFCell extends TestCase {
/**
* test that Boolean and Error types (BoolErrRecord) are supported properly.
assertEquals("Formula", "A1+B1", c.toString());
}
+ public void testSetStringInFormulaCell_bug44606() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFCell cell = wb.createSheet("Sheet1").createRow(0).createCell((short)0);
+ cell.setCellFormula("B1&C1");
+ try {
+ cell.setCellValue(new HSSFRichTextString("hello"));
+ } catch (ClassCastException e) {
+ throw new AssertionFailedError("Identified bug 44606");
+ }
+ }
+
public static void main(String [] args) {
System.out
.println("Testing org.apache.poi.hssf.usermodel.TestHSSFCell");