How to get the text and style from textbox

Hi,
How can we find the style and content of textbox via Aspose Words.
Regards,
Divesh Salian

Hi Divesh,

Thanks for your inquiry. Please note that there can be different type of styles in a document like Paragraph, Character, List and Table type. A style allows you to define a set of formatting that can be reused on many elements in a document. A style loaded into a document is represented in the Aspose.Words DOM by the Style class.

In your shared document the text is inside shapes. Shape represents an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture. Please use the following code snippet to get the text of shapes and text style.

Document doc = new Document(MyDir + "19439_GraphicsInsideTextBo.doc");

foreach(Shape shp in doc.GetChildNodes(NodeType.Shape, true))
{
    // iterate through each Paragraph node of Shape
    foreach(Paragraph para in shp.GetChildNodes(NodeType.Paragraph, true))
    {
        // Get text of Paragraph
        String txt = para.ToString(SaveFormat.Text);
        Style style = para.ParagraphFormat.Style;
        String StyleName = style.Name;
    }
}

Moreover, you can also get the text and font properties by using Run node as shown in following code snippet. Run can only be a child of Paragraph.

Document doc = new Document(MyDir + "19439_GraphicsInsideTextBo.doc");
foreach(Shape shp in doc.GetChildNodes(NodeType.Shape, true))
{
    // iterate through each Run node of Shape
    foreach(Run run in shp.GetChildNodes(NodeType.Run, true))
    {
        // Get text of Run
        String txt = run.Text;
        // Get font name
        String fontname = run.Font.Name;
        // Get font size
        double size = run.Font.Size;
    }
}

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.