Sign In  Sign Up Live-Chat

Showing and hiding details in word document

Last post 07-22-2008, 9:48 AM by rabdur. 22 replies.
Page 1 of 2 (23 items)   1 2 Next >
Sort Posts: Previous Next
  •  05-07-2008, 1:46 AM 125731

    Showing and hiding details in word document

    Attachment: Present (inaccessible)

    Dear all,

    I got a dataset which produces salary details of employees in an organization according to there grades.Now salary components are different as well as salary structure for different employees. For ex: for junior officer salary components like car maintenance and driver allowance are missing but for managers these components are present. So i fill the dataset dynamically as per the employees grade. But to show that data in a word document dynamically is seems to be impossible coz we usually merge the fields in the word document once and for all. So i want to have a sort of mechanism where in if the particular component is missing in the dataset then that component should not be displayed in the word document. So kindly help me to achieve this asap.Also find the attached salary structure in which i have to show only those components which are present in the dataset .

    Thanks in Advance

    Amit Dangre.


    This message was posted using Page2Forum (attachment) from Technical Support - Aspose.Words for .NET and Java
     
  •  05-07-2008, 4:14 AM 125770 in reply to 125731

    Re: Showing and hiding details in word document

    Attachment: Present (inaccessible)

    Hi

     

    Thanks for your request. I think that you can achieve this using MergeField event handler. For example see the following code and attached documents.

     

    public void Test157()

    {

        string[] names = { "option1", "option2", "option3", "option4" };

        //Row that contains empty data will be removed

        string[] values = { "val1", "val2", "", "val4" };

        //Open document

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

        //Add MergeField event handler

        doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField157);

        //Execute mail merge

        doc.MailMerge.Execute(names, values);

        //Save document

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

    }

     

    void MailMerge_MergeField157(object sender, MergeFieldEventArgs e)

    {

        //Check if value is empty

        if (string.IsNullOrEmpty(e.FieldValue.ToString()))

        {

            //Get parent row

            Node parantRow = e.Field.Start.GetAncestor(typeof(Row));

            //Remove row

            parantRow.Remove();

        }

    }

     

    I hope this could help you.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-27-2008, 1:06 AM 128707 in reply to 125770

    Re: Showing and hiding details in word document

    please send me the equivalent vb code so i can put into my program .
     
  •  05-27-2008, 3:52 AM 128726 in reply to 128707

    Re: Showing and hiding details in word document

    Hi

     

    Thanks for your request. Here is the same code in VB.

     

    Public Sub Test157()

        Dim names As String() = {"option1", "option2", "option3", "option4"}

        'Row that contains empty data will be removed

        Dim values As String() = {"val1", "val2", "", "val4"}

        'Open document

        Dim doc As Document = New Document("in.doc")

        'Add MergeField event handler

        AddHandler doc.MailMerge.MergeField, AddressOf MailMerge_MergeField157

        'Execute mail merge

        doc.MailMerge.Execute(names, values)

        'Save document

        doc.Save("out.doc")

    End Sub

     

    Private Sub MailMerge_MergeField157(ByVal sender As Object, ByVal e As MergeFieldEventArgs)

        'Check if value is empty

     

        If (String.IsNullOrEmpty(e.FieldValue.ToString())) Then

            'Get parent row

            Dim parantRow As Node = e.Field.Start.GetAncestor(NodeType.Row)

            'Remove row

            parantRow.Remove()

        End If

    End Sub

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-02-2008, 6:56 AM 129586 in reply to 128726

    Re: Showing and hiding details in word document

    Above code is applicable only when we use tables and there we want to remove the row. But i have got a document which contains only text . So in that case how to hide/show contents on certain conditions.

     
  •  06-02-2008, 7:28 AM 129594 in reply to 129586

    Re: Showing and hiding details in word document

    Hi

     

    Thanks for your request. I think that you can try using bookmarks. Insert optional text into bookmarks. You should just set bookmark text as empty string for removing its content. For example see the following code.

     

    doc.Range.Bookmarks["myBookamrk"].Text = string.Empty;

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-03-2008, 6:40 AM 129788 in reply to 129594

    Re: Showing and hiding details in word document

    Hi,

    Thanks for your suggestion .It works fine. but when i use bookmarks to hide/show part of document then unnecessary space is created. Kindly tell me how to remove spaces dynamically so the original format will be intact.

     
  •  06-03-2008, 6:53 AM 129793 in reply to 129788

    Re: Showing and hiding details in word document

    Hi

     

    Thanks for your request. I think that you can also remove paragraph with bookmark. For example you can use the following code:

     

    doc.Range.Bookmarks["myBookamrk"].Text = string.Empty;

    doc.Range.Bookmarks["myBookamrk"].BookmarkStart.ParentNode.Remove();

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-04-2008, 1:10 AM 129946 in reply to 129793

    Re: Showing and hiding details in word document

    Attachment: Present (inaccessible)

    Hi,

    I am sending you the document i m trying to merge. But in the document there is a table in which i have created a bookmark . I want to hide/show this particular row in the table on condition for that i followed the same procedure. but when i run the code it gives me error as

    "Start and end node should have the same grand parent".I think bookmark doesnt work on table item. So please tell me alternative for the same so i can remove table items in the same document using bookmark or some other concept.Kindly find the attached document and also the code i m using for the same.

     

    Plz reply as soon as possible

     
  •  06-04-2008, 4:33 AM 129973 in reply to 129946

    Re: Showing and hiding details in word document

    Hi

     

    Thanks for your inquiry. I think that you can just remove Row from table. Please see my first post in this thread to learn how to achieve this.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-05-2008, 3:02 AM 130132 in reply to 129973

    Re: Showing and hiding details in word document

    Hi alexey,

    thanks for ur suggestion.That option worked but now the problem is when i remove that particular row then ordering is changed. For instance if i remove row numbered 3 then automatically numbering gets changed and i see row no 4 after row 2. So can you gimme some solution on this. And displaying row no. is mandatory so i cant change it with bullets.

     
  •  06-05-2008, 6:41 AM 130156 in reply to 130132

    Re: Showing and hiding details in word document

    Hi

     

    Thanks for your inquiry. You can try using the following code:

     

    Private Sub MailMerge_MergeField157(ByVal sender As Object, ByVal e As MergeFieldEventArgs)

        'Check if value is empty

     

        If (String.IsNullOrEmpty(e.FieldValue.ToString())) Then

            'Get parent row

            Dim parentRow As Row = CType(e.Field.Start.GetAncestor(NodeType.Row), Row)

            'Get parent table

            Dim parentTab As Table = parentRow.ParentTable

            'Remove row

            parentRow.Remove()

            'Reorder numbers

            For rowIndex As Integer = 1 To parentTab.Rows.Count - 1

                Dim firstRun As Run = CType(parentTab.Rows(rowIndex).Cells(0).FirstParagraph.FirstChild, Run)

                firstRun.Text = rowIndex.ToString()

            Next

     

        End If

    End Sub

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-13-2008, 6:39 AM 131229 in reply to 130156

    Re: Showing and hiding details in word document

    Hi,

    Thanks a lot. This code was working fine in table. But i have got same numbering issue in simple text in the same document. So could you tell me how to avoid the same using bookmarks.

     
  •  06-13-2008, 6:52 AM 131230 in reply to 131229

    Re: Showing and hiding details in word document

    Hi

     

    Thanks for your inquiry. Could you please provide me sample document? I will investigate this issue and provide you more information.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-13-2008, 7:04 AM 131232 in reply to 131230

    Re: Showing and hiding details in word document

    Attachment: Present (inaccessible)
    In this document we have listed all the points which are not part of table using numbering like 1,2,3. and i am using the bookmark to hide those points on condition. But when i hide point no 7. then automatically after point 6 , point 8 comes. so check the document and reply me asap.
     
Page 1 of 2 (23 items)   1 2 Next >
View as RSS news feed in XML