Hello. I faced with a problem when filling out cells with rich formatting.
So, for example, after rendering, template cell with "some {p:MyValue} text" turns into "some simple text", losing formatting.
Is it possible to add processing for such cells?
It seems to me that can be done (of course with correct formatting) by changing the code in ExcelPanel.cs something like...
if (!cell.HasRichText)
{
MatchCollection matches = Regex.Matches(cellValue, templatePattern, RegexOptions.IgnoreCase);
if (matches.Count == 0)
{
continue;
}
XLCellValue newValue = GetCellValue(cellValue, templatePattern, matches);
cell.Value = newValue;
}
else
{
IXLRichText richText = cell.GetRichText();
foreach(IXLRichString richString in richText)
{
string cellPartValue = richString.Text;
MatchCollection matches = Regex.Matches(cellPartValue, templatePattern, RegexOptions.IgnoreCase);
if (matches.Count == 0)
{
continue;
}
XLCellValue newValue = GetCellValue(cellPartValue, templatePattern, matches);
richString.Text = newValue.GetText();
}
}
private XLCellValue GetCellValue(string cellValue, string templatePattern, MatchCollection matches)
{
HierarchicalDataItem dataContext = GetDataContext();
if (matches.Count == 1 && Regex.IsMatch(cellValue, $@"^{templatePattern}$", RegexOptions.IgnoreCase))
{
object value = _templateProcessor.GetValue(cellValue, dataContext);
if (value == null)
{
return Blank.Value;
}
else if (value.GetType().IsNumeric())
{
return Convert.ToDouble(value);
}
else
{
return value switch
{
bool boolValue => boolValue,
DateTime dateTimeValue => dateTimeValue,
TimeSpan timeSpanValue => timeSpanValue,
_ => GetValueFromString(value.ToString())
};
}
}
foreach (object match in matches)
{
string template = match.ToString();
cellValue = cellValue.Replace(template, _templateProcessor.GetValue(template, dataContext)?.ToString());
}
return GetValueFromString(cellValue);
XLCellValue GetValueFromString(string value) => value == string.Empty ? Blank.Value : value;
}