1

我有一个 DecXpress 报告,数据源显示了一个数据正在发送的文件,例如

PRODUCT - APPLE<BR/>ITEM NUMBER - 23454</BR>LOT NUMBER 3343 <BR/>

现在这就是它在单元格中的显示方式,所以我决定解码,但没有任何效果,我尝试了 HttpUtility.HtmlDecode,在这里我正在尝试 WebUtility.HtmlDecode。

   private void xrTableCell9_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
    XRTableCell cell = sender as XRTableCell;
    string _description = WebUtility.HtmlDecode(Convert.ToString(GetCurrentColumnValue("Description")));
    cell.Text = _description;

}

如何解码数据源中此列的值?

谢谢

4

1 回答 1

1

如果您还需要显示描述,则< />需要使用HtmlEncode


如果您需要从该 html 中提取文本

public static string ExtractTextFromHtml(this string text)
        {
            if (String.IsNullOrEmpty(text))
                return text;
            var sb = new StringBuilder();
            var doc = new HtmlDocument();
            doc.LoadHtml(text);
            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//text()"))
            {
                if (!String.IsNullOrWhiteSpace(node.InnerText))
                    sb.Append(HtmlEntity.DeEntitize(node.InnerText.Trim()) + " ");
            }
            return sb.ToString();
        }

你需要HtmlAgilityPack


要删除 br 标签:

var str = Convert.ToString(GetCurrentColumnValue("Description"));
Regex.Replace(str,  @"</?\s?br\s?/?>", System.Environment.NewLine, RegexOptions.IgnoreCase);
于 2012-02-20T23:11:21.030 回答