Patch from Josh from bug #44606 - Support calculated string values for evaluated formulas
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@637595 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f3193f779e
commit
8ca38c3e23
@ -36,6 +36,7 @@
|
||||
|
||||
<!-- 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>
|
||||
|
@ -33,6 +33,7 @@
|
||||
<!-- 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>
|
||||
|
@ -589,38 +589,36 @@ public class HSSFCell
|
||||
* 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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_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) {
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
@ -15,7 +14,6 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
|
||||
package org.apache.poi.hssf.usermodel;
|
||||
|
||||
@ -24,12 +22,11 @@ import java.io.FileInputStream;
|
||||
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;
|
||||
@ -41,12 +38,7 @@ 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.
|
||||
@ -388,6 +380,17 @@ extends TestCase {
|
||||
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");
|
||||
|
Loading…
Reference in New Issue
Block a user