Excel Comment truncated during reading

2019-09-10 18:01发布

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条回答
冷血范
2楼-- · 2019-09-10 18:28

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); 
查看更多
登录 后发表回答