问题
I have a very long comment in an Excel cell.
I need to able to read this comment.
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!**
}
I read that getting loading the characters need to be looped but how should I wonder how should I do it if I don't know the length of the character?
回答1:
After trial and error, solved by implementing this :
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);
来源:https://stackoverflow.com/questions/10531164/excel-comment-truncated-during-reading