D
Dennis
I tried to read the text from an Excel textbox, but the returned string is
always truncated to 255 characters. Did I do anything wrong? Please help!
The following is how to reproduce my problem:
- Create an Excel spreasheet C:\temp\Book1.xls and add a text box shape
object (named it Text Box 1) to sheet1 from the Drawing toolbar.
- Copy or enter some text into the text box with more than 2000 characters.
- Create a Windows project with C# and add a button button1, and a
multi-line textbox textbox1 to form1.
- Add reference to Microsoft Excel 11.0 Object Library from the COM tab.
- The code of button1_Click:
using Excel = Microsoft.Office.Interop.Excel;
private void button1_Click(object sender, System.EventArgs e)
{
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet xlWs;
object missing = System.Reflection.Missing.Value;
oXL = new Excel.Application();
oWB = oXL.Workbooks.Open(@"C:\temp\Book1.xls",
missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing);
xlWs =(Excel.Worksheet) oWB.Sheets.get_Item("Sheet1");
string s = xlWs.Shapes.Item("Text Box
1").TextFrame.Characters(1,missing).Text;//.Count.ToString();
textBox1.Text = s;
oXL.Quit();
}
always truncated to 255 characters. Did I do anything wrong? Please help!
The following is how to reproduce my problem:
- Create an Excel spreasheet C:\temp\Book1.xls and add a text box shape
object (named it Text Box 1) to sheet1 from the Drawing toolbar.
- Copy or enter some text into the text box with more than 2000 characters.
- Create a Windows project with C# and add a button button1, and a
multi-line textbox textbox1 to form1.
- Add reference to Microsoft Excel 11.0 Object Library from the COM tab.
- The code of button1_Click:
using Excel = Microsoft.Office.Interop.Excel;
private void button1_Click(object sender, System.EventArgs e)
{
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet xlWs;
object missing = System.Reflection.Missing.Value;
oXL = new Excel.Application();
oWB = oXL.Workbooks.Open(@"C:\temp\Book1.xls",
missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing);
xlWs =(Excel.Worksheet) oWB.Sheets.get_Item("Sheet1");
string s = xlWs.Shapes.Item("Text Box
1").TextFrame.Characters(1,missing).Text;//.Count.ToString();
textBox1.Text = s;
oXL.Quit();
}