Heading1 style at Bookmark

Last post 06-09-2009, 12:56 PM by alexey.noskov. 5 replies.
Sort Posts: Previous Next
  •  06-04-2009, 2:16 AM 182476

    Heading1 style at Bookmark .NET

    Hi,

    I need to put Heading1 style at perticular Bookmark..

    Let me know is there any property or method available or Is there any approach to apply Heading1 style in the place of Bookmark??

    Regards,

    Srinu Dhulipalla


    Srinu Dhulipalla
     
  •  06-04-2009, 5:31 AM 182515 in reply to 182476

    Re: Heading1 style at Bookmark

    Hi

     

    Thanks for your inquiry. I think you should use code like the following:

     

    // Open document and create DocumentBuilder

    Document doc = new Document(@"Test178\in.doc");

    DocumentBuilder builder = new DocumentBuilder(doc);

     

    // Move DocumentBuilder cursor to the bookmark

    builder.MoveToBookmark("mybk");

     

    // Set style of current paragraph

    builder.CurrentParagraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

     

    // Save output document

    doc.Save(@"Test178\out.doc");

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-04-2009, 9:56 AM 182572 in reply to 182515

    Re: Heading1 style at Bookmark .NET

    Hi Alexey,

    Thanks for your response,

    but i need to handle this dynamically, like, if the paragraph style above bookmark is Heading1, i should replace bookmark with Heading1

    and the paragraph style above bookmark is Heading2, i should replace the bookmark with Heading2 style.. like this.. it continues....

    Let me know the possible ways to solve this?

    Regards,

    Srinu Dhulipalla


    Srinu Dhulipalla
     
  •  06-04-2009, 12:45 PM 182614 in reply to 182572

    Re: Heading1 style at Bookmark

    Hi

     

    Please attach sample document and expected output here. It is not quite clear for me what you would like to achieve. If you need to determine style of the paragraph where the particular bookmark is located, you can use the same technique as I demonstrated in the code example provided in the previous answer.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-09-2009, 10:23 AM 183099 in reply to 182614

    Re: Heading1 style at Bookmark .NET

    Attachment: Present (inaccessible)

    Hi Alexey,

    Thanks for your response,

    PFA for my sample template, containing two bookmarks called 'SectionNumber' and 'SectionNumber1',

    'SectionNumber' is under Heading1(Introduction), so here i need to put Heading1 style paragraph and 'SectionNumber1' is under Heading2(sub-introduction), so here i need to put Heading2 style...

    So i need to fill all the bookmarks like this.. can u pls help me out in this issue to resolve..

    Regards,

    Srinu Dhulipalla


    Srinu Dhulipalla
    Filed under: bookmark problem
     
  •  06-09-2009, 12:56 PM 183144 in reply to 183099

    Re: Heading1 style at Bookmark

    Hi

     

    Thanks for your inquiry. Maybe the following code could be useful for you:

     

    public void Test188()

    {

        // Open document

        Document doc = new Document(@"Test188\SectionTest_Aspose.dot");

     

        // Create document buider

        DocumentBuilder builder = new DocumentBuilder(doc);

     

        foreach (Bookmark bk in doc.Range.Bookmarks)

        {

            // Move docuemnt builder cursor to the bookmark

            builder.MoveToBookmark(bk.Name);

     

            // set new style identifier

            builder.CurrentParagraph.ParagraphFormat.StyleIdentifier = GetHeading(builder.CurrentParagraph);

        }

     

        // Save output docuemnt

        doc.Save(@"Test188\out.doc");

    }

     

    /// <summary>

    /// Method returns any heading style of any paragraph above the node

    /// if there are no headign paragraphs above the node Normal style is returned

    /// </summary>

    private StyleIdentifier GetHeading(Node node)

    {

        StyleIdentifier style = StyleIdentifier.Normal;

     

        Node currentNode = node;

     

        while(currentNode!=null)

        {

            // check whether current node is paragraph.

            // If so we should che its style

            // and return headign style if current paragraph is heading paragraph

            if(currentNode.NodeType.Equals(NodeType.Paragraph))

            {

                Paragraph curretnPar = (Paragraph) currentNode;

                if(IsHeading(curretnPar.ParagraphFormat.StyleIdentifier))

                {

                    style = curretnPar.ParagraphFormat.StyleIdentifier;

                    break;

                }

            }

     

            // move to the previouse node

            currentNode = currentNode.PreviousPreOrder(node.Document);

        }

     

        return style;

    }

     

    /// <summary>

    /// Returns true if identifier is an identifier of heading paragraph

    /// </summary>

    private bool IsHeading(StyleIdentifier style)

    {

        switch (style)

        {

            case StyleIdentifier.Heading1:

            case StyleIdentifier.Heading2:

            case StyleIdentifier.Heading3:

            case StyleIdentifier.Heading4:

            case StyleIdentifier.Heading5:

            case StyleIdentifier.Heading6:

            case StyleIdentifier.Heading7:

            case StyleIdentifier.Heading8:

            case StyleIdentifier.Heading9:

                return true;

            default:

                return false;

        }

    }

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
View as RSS news feed in XML