-
Notifications
You must be signed in to change notification settings - Fork 303
Description
Setting richText when a cell/range has a formula should either Throw or simply replace the formula as the cell-value has changed.
In addition as a secondary failure ("följdfel") or a potential seperate bug after calculate:
If IsRichText is called or looking at the range attributes in the debugger both update the actual richtext reference. While if you do not call IsRichText. The cellRange still shows the old values but ws.Cells["B1"].RichText.Text shows the new values.
This should probably be changed so that we consistently either leave values in the old variable or update the reference during Calculate. Most likely Update as that seems to be what most if not all the other properties (value/text etc.) seem to do and a richTextCollection is also technically a value.
Test to reproduce (both cases):
[TestMethod]
public void DirtyRichText()
{
using (var pck = OpenPackage("dirtyRT.xlsx"))
{
var ws = pck.Workbook.Worksheets.Add("richText");
ws.Cells["A1"].Value = 1001.1d;
ws.Cells["C1"].Formula = "ROUND(A1, 1)";
ws.Cells["B1"].Formula = "\"My favorite number is: \"&TEXT(ROUND(A1,1),\"#,##0.00;(#,##0.00)\")";
//Set richtext on range with that has a formula
//This should clear Formula but does not
ws.Cells["B1"].RichText.Add("My favorite number is: 1001.1", true);
//This then Results in strange behaviour below when running calculate/IsRichText
var cellRange = ws.Cells["B1"];
var origRT = cellRange.RichText;
ws.Calculate();
var afterRt1 = cellRange.Text;
var cellRich = ws.Cells["B1"].RichText.Text; //A FRESH reference to the cell, yielding: 1001,10000
var OLDCellRich = cellRange.RichText.Text; //Dirty COPY of the cell and its values, yielding: 1001.1\n
//This causes the richText of cellRange.RichText to update
var myFormula = cellRange.IsRichText;
//So does Just LOOKING at the cellRange variable properties In the debugger. It trigger their Getters.
//This property changes the actual values of the range when observed in the debugger.
//This makes debugging harder and highly confusing both to us and end-users as you may look at a value
//See that it is innaccurate and then check it again only to see that it is correct for no discernable reason.
var OLDCellRichAfterDebug = cellRange.RichText.Text;
Assert.AreEqual(OLDCellRich, OLDCellRichAfterDebug);
}
}Metadata
Metadata
Assignees
Labels
Type
Projects
Status