我在Excel单元格中有很长时间的评论。
我需要能够阅读此评论。
Microsoft.Office.Interop.Excel.Comment comment = ws.get_Range(ws.Cells[1, Constants.HIDDEN_DATA_COL], ws.Cells[1, Constants.HIDDEN_DATA_COL]).Comment;
if(comment!=null)
{
Microsoft.Office.Interop.Excel.Characters chars = comment.Shape.TextFrame.Characters(System.Type.Missing, System.Type.Missing);
string theText = chars.Text;
MessageBox.Show(theText); //**truncated!**
}
我读到加载角色需要循环,但如果我不知道角色的长度,我该怎么想呢?
答案 0 :(得分:2)
经过反复试验,通过实施此解决方案:
bool read = true;
string finalText="";
int j = 1;
int lengthMax = 200;
while(read)
{
string textnya = comment.Shape.TextFrame.Characters(j, lengthMax).Text;
finalText = finalText+textnya;
if (textnya.Length < lengthMax)
{
read = false;
}
else
{
j = j + lengthMax;
}
}
MessageBox.show(finalText);