Excel Comment truncated during reading

无人久伴 提交于 2019-12-25 04:06:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!