110,571
社区成员
发帖
与我相关
我的任务
分享
IRow row = sheet.GetRow(i);
ICell cell = row.GetCell(0);
XSSFRichTextString richText = (XSSFRichTextString)cell.RichStringCellValue;
var ctrst = richText.GetCTRst();
Console.WriteLine("row:{0}, col:{1}, val:{2}, rlen:{3}", i, 0, richText.String, ctrst.r.Count);
if (ctrst.r.Count > 0)
{
foreach (var item in ctrst.r)
{
bool isStrike;
if (item.rPr != null && item.rPr.strike != null)
isStrike = item.rPr.strike.val;
else
isStrike = cell.CellStyle.GetFont(book).IsStrikeout;
Console.WriteLine("\t string:" + item.t + ", isStrike:" + isStrike); //item.t是对应的字符串
}
}
else
Console.WriteLine("\t isStrike: " + cell.CellStyle.GetFont(book).IsStrikeout);
IRichTextString richTextString = cell.RichStringCellValue;
for (int j = 0; j < richTextString.Length; ++j)
{
short a = richTextString.GetFontAtIndex(j);
if (a > 0)
{
IFont font = workBook.GetFontAt(a);
if (font.IsStrikeout)
{
//位于i上的字符是带删除线的
s3 += richTextString.ToString().Substring(j, 1);
}
}
}
图中 第三条 就直接报错了 xlsx的版本
IRichTextString richTextString = cell.RichStringCellValue;
for (int j = 0; j < richTextString.Length; ++j)
{
IFont font = workBook.GetFontAt(
richTextString.GetFontAtIndex(j));
if (font.IsStrikeout)
{
//位于i上的字符是带删除线的
//ss += xssfRichTextString.ToString().Substring(j, 1);
}
}
if (hssfRichTextString != null)
{
string ss = "";
hssfRichTextString = (HSSFRichTextString)cell.RichStringCellValue;
for (int j = 0; j < hssfRichTextString.Length; ++j)
{
IFont font = workBook.GetFontAt(hssfRichTextString.GetFontAtIndex(j));
if (font.IsStrikeout)
{
//位于i上的字符是带删除线的
ss += hssfRichTextString.ToString().Substring(j, 1);
}
}
MessageBox.Show(ss, i + "");
}
if (xssfRichTextString != null)
{
string ss = "";
xssfRichTextString =(XSSFRichTextString) cell.RichStringCellValue;
for (int j = 0; j < xssfRichTextString.Length; ++j)
{
IFont font = workBook.GetFontAt(xssfRichTextString.GetFontAtIndex(j));
if (font.IsStrikeout)
{
//位于i上的字符是带删除线的
ss += xssfRichTextString.ToString().Substring(j, 1);
}
}
MessageBox.Show(ss, i + "");
}
用的NPOI 2.2.0.0 这个版本的IRichTextString richTextString = cell.RichStringCellValue;
for(int i = 0; i < richTextString.Length; ++i)
{
IFont font = workbook.GetFontAt(richTextString.GetFontAtIndex(i));
if(font.IsStrikeout)
//位于i上的字符是带删除线的
}