How to read text in drawing objects (HSSFTextbox) ?

May 18, 2011 at 3:34 PM

I am quite new to the NPOI project. I am trying to parse information from xls files to feed a database.

I have been able to read most of the information I need so far except for text in drawing objects.

I am using the following c# code:

            Sheet sheet = hssfworkbook.GetSheet("test");

            HSSFPatriarch patriarch = (HSSFPatriarch)sheet.DrawingPatriarch;

            for (int i = 0; i < patriarch.Children.Count; i++)
            {
                Object o = patriarch.Children[i];

                if (o.GetType() == typeof(HSSFTextbox))
                {
                    HSSFTextbox tbox = patriarch.Children[i] as HSSFTextbox;
                    int len = tbox.String.Length;
                    String text = tbox.String.String;
                }
            }

patriarch.Children.Count returns the expected number of drawing objects in the sheet. Also, the "o" is of type HSSFTextbox as expected.

However, "text" is always an empty string although I am able to view the correct string in the POIFS Browser sample app.

I am missing something? Can anyone help?

Thanks a lot in advance.

mc