Skip to content

Commit 93c5e35

Browse files
authored
Merge pull request #1407 from EPPlusSoftware/bug/richtext_blank
Rich text blank issue
2 parents 9dffadd + 70c22fc commit 93c5e35

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/EPPlus/ExcelRangeBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,13 @@ public bool IsRichText
12791279
get
12801280
{
12811281
IsRangeValid("richtext");
1282-
return _worksheet._flags.GetFlagValue(_fromRow, _fromCol, CellFlags.RichText);
1282+
var isRt = _worksheet._flags.GetFlagValue(_fromRow, _fromCol, CellFlags.RichText);
1283+
if (isRt)
1284+
{
1285+
_rtc = _worksheet.GetRichText(_fromRow, _fromCol, this);
1286+
return _rtc.Count>0;
1287+
}
1288+
return isRt;
12831289
}
12841290
set
12851291
{

src/EPPlus/ExcelWorksheet.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,15 +1443,14 @@ private void LoadHyperLinks(XmlReader xr)
14431443
internal ExcelRichTextCollection GetRichText(int row, int col, ExcelRangeBase r = null)
14441444
{
14451445
var v = GetCoreValueInner(row, col);
1446-
//var isRt = _flags.GetFlagValue(row, col, CellFlags.RichText);
1447-
//if (isRt && v._value is ExcelRichTextCollection rtc)
1448-
if (v._value is ExcelRichTextCollection rtc)
1446+
var isRt = _flags.GetFlagValue(row, col, CellFlags.RichText);
1447+
if (isRt && v._value is ExcelRichTextCollection rtc)
14491448
{
14501449
return rtc;
14511450
}
14521451
else
14531452
{
1454-
var text = ValueToTextHandler.GetFormattedText(v._value, Workbook, v._styleId, false);
1453+
var text = ValueToTextHandler.GetFormattedText(v._value, Workbook, v._styleId, false);
14551454
if (string.IsNullOrEmpty(text))
14561455
{
14571456
var item = new ExcelRichTextCollection(Workbook, r);
@@ -2230,7 +2229,6 @@ public object GetValue(int Row, int Column)
22302229
var v = GetValueInner(Row, Column);
22312230
if (v!=null)
22322231
{
2233-
//var cell = ((ExcelCell)_cells[cellID]);
22342232
if (_flags.GetFlagValue(Row, Column, CellFlags.RichText))
22352233
{
22362234
return (object)Cells[Row, Column].RichText.Text;

src/EPPlus/Style/RichText/ExcelRichTextCollection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ internal ExcelRichTextCollection(ExcelWorkbook wb, ExcelRangeBase cells)
3838
{
3939
_wb = wb;
4040
_cells = cells;
41-
}
41+
_cells._worksheet._flags.SetFlagValue(_cells._fromRow, _cells._fromCol, true, CellFlags.RichText);
42+
}
4243

43-
internal ExcelRichTextCollection(string s, ExcelRangeBase cells)
44+
internal ExcelRichTextCollection(string s, ExcelRangeBase cells)
4445
{
4546
_wb = cells._workbook;
4647
_cells = cells;

src/EPPlusTest/Core/Range/RangeRichTextTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,18 @@ public void IsRichTextShouldKeepValues()
183183

184184
Thread.CurrentThread.CurrentCulture = ci;
185185
}
186-
187186
[TestMethod]
187+
public void VerifyRichTextIsBlankIfAccess()
188+
{
189+
using(var p=new ExcelPackage())
190+
{
191+
var ws = p.Workbook.Worksheets.Add("Sheet1");
192+
var t = ws.Cells["A1"].RichText.Text;
193+
194+
Assert.AreEqual(string.Empty, ws.Cells["A1"].Value);
195+
}
196+
}
197+
[TestMethod]
188198
public void ValidateRichText_TextIsReflectedOnRemove()
189199
{
190200
var package = new OfficeOpenXml.ExcelPackage();

0 commit comments

Comments
 (0)