谢谢版主的解答,此问题终于解决了。用了以下方法, 仅供有需要的人参考。
RichTextBox richTextBox = new RichTextBox();
richTextBox.Font = Spread_Excel.Cells[i, j].Font;
richTextBox.Text = dr["CellValue"].ToString();
for (int v = 0; v < richTextBox.Text.Length; v++)
{
if (richTextBox.Text.ToString().Substring(v, 1) == "^" && richTextBox.Text.Length > 0)
{
richTextBox.SelectionStart = v - 1;
richTextBox.SelectionLength = 1;
richTextBox.SelectionCharOffset = 5;
richTextBox.SelectionStart = v;
richTextBox.SelectionLength = 1;
richTextBox.SelectedText = "";
}
else if (richTextBox.Text.ToString().Substring(v, 1) == "&" && richTextBox.Text.Length > 0)
{
richTextBox.SelectionStart = v - 1;
richTextBox.SelectionLength = 1;
richTextBox.SelectionCharOffset = -5;
richTextBox.SelectionStart = v;
richTextBox.SelectionLength = 1;
richTextBox.SelectedText = "";
}
}
RichTextCellType rtct = new RichTextCellType();
Spread_Excel.Cells[i, j].CellType = rtct;
Spread_Excel.Cells[i, j].Value = richTextBox.Rtf;
|