Sign In  Sign Up Live-Chat

Problem Merging document into another ignores the position of the original placeholders

Last post 05-20-2008, 8:52 AM by CmJoshua. 16 replies.
Page 1 of 2 (17 items)   1 2 Next >
Sort Posts: Previous Next
  •  05-09-2008, 7:45 AM 126225

    Problem Merging document into another ignores the position of the original placeholders

    Attachment: Present (inaccessible)

    Hi,

     

    I have a problem merging documents into another.

     

    The problem is that for some reasons during the replacement it ignores the position of the original placeholders.

     

    I attach here a small project and templates where the problem can be reproduced.

     

    See following example:

    result:

    PlaceHolderOrder1 in RollePlaceHolderOrder4 in BGPlaceHolderOrder3 in RangPlaceHolderOrder2 in SalaerPlaceHolderOrder5 in Vertragsdauer

     

    NOTE: According the order in place holder should be this order (please see template):

     

    [Rolle_BS64 - PlaceHolderOrder1 in Rolle]

    [Salaer_BS64 - PlaceHolderOrder2 in Salaer]

    [Rang_BS64 - PlaceHolderOrder3 in Rang]

    [BG_BS64 - PlaceHolderOrder4 in BG]

    [Vertragsdauer_BS64 - PlaceHolderOrder5 in Vertragsdauer ]

     

     

    This problem is very significant for us; I'll appreciate very much your help in this issue.

     

    Thanks a regards

    Josue Medrano

     

    UBS AG
    Global Wealth Management & Business Banking
    Information Technology - Custom Development
    HR & EDUCATION SOLUTIONS
    Tel: +41 61 288'2762
    Email:
    josue.medrano-cruz@ubs.com

     
  •  05-09-2008, 8:59 AM 126242 in reply to 126225

    Re: Problem Merging document into another ignores the position of the original placeholders

    Hi

     

    Thanks for your request. e.MatchNode is Run that can contain other text than MatchValue. Please try using the following code:

     

    public ReplaceAction InsertDocEvaluator(object sender, ReplaceEvaluatorArgs e)

    {

     

        //Get MatchNode

        Run run1 = (Run)e.MatchNode;

        //Create Run

        Run run2 = new Run(e.MatchNode.Document, string.Empty);

        //Get index of match value

        int index = run1.Text.IndexOf(e.Match.Value);

        if (index > 0)

        {

            //Split text in match node

            run2.Text = string.IsNullOrEmpty(run1.Text.Substring(0, index)) ? " " : run1.Text.Substring(0, index);

            run1.Text = string.IsNullOrEmpty(run1.Text.Substring(index + e.Match.Value.Length)) ? " " : run1.Text.Substring(index + e.Match.Value.Length);

           

        }

        else

        {

            run2.Text = " ";

            run1.Text = string.IsNullOrEmpty(run1.Text.Substring(e.Match.Value.Length)) ? " " : run1.Text.Substring(e.Match.Value.Length);

        }

        run1.ParentParagraph.InsertBefore(run2, run1);

        DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document);

        //Move to run1

        builder.MoveTo(run1);

       

        string mNodeText = "BM" + (new Random()).Next(1000, 100000);

        builder.StartBookmark(mNodeText);

        builder.EndBookmark(mNodeText);

        try

        {

            InsertDocumentAtBookamrk(mNodeText, builder.Document, m_doc);

        }

        catch(Exception)

        {

        }

        return (ReplaceAction.Skip);

    }

     

    I hope this could help you.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-09-2008, 8:59 AM 126243 in reply to 126225

    Re: Problem Merging document into another ignores the position of the original placeholders

    Hi

     

    Thanks for your request. e.MatchNode is Run that can contain other text than MatchValue. Please try using the following code:

     

    public ReplaceAction InsertDocEvaluator(object sender, ReplaceEvaluatorArgs e)

    {

     

        //Get MatchNode

        Run run1 = (Run)e.MatchNode;

        //Create Run

        Run run2 = new Run(e.MatchNode.Document, string.Empty);

        //Get index of match value

        int index = run1.Text.IndexOf(e.Match.Value);

        if (index > 0)

        {

            //Split text in match node

            run2.Text = string.IsNullOrEmpty(run1.Text.Substring(0, index)) ? " " : run1.Text.Substring(0, index);

            run1.Text = string.IsNullOrEmpty(run1.Text.Substring(index + e.Match.Value.Length)) ? " " : run1.Text.Substring(index + e.Match.Value.Length);

           

        }

        else

        {

            run2.Text = " ";

            run1.Text = string.IsNullOrEmpty(run1.Text.Substring(e.Match.Value.Length)) ? " " : run1.Text.Substring(e.Match.Value.Length);

        }

        run1.ParentParagraph.InsertBefore(run2, run1);

        DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document);

        //Move to run1

        builder.MoveTo(run1);

       

        string mNodeText = "BM" + (new Random()).Next(1000, 100000);

        builder.StartBookmark(mNodeText);

        builder.EndBookmark(mNodeText);

        try

        {

            InsertDocumentAtBookamrk(mNodeText, builder.Document, m_doc);

        }

        catch(Exception)

        {

        }

        return (ReplaceAction.Skip);

    }

     

    I hope this could help you.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-09-2008, 9:29 AM 126250 in reply to 126243

    Re: Problem Merging document into another ignores the position of the original placeholders

    Attachment: Present (inaccessible)
    Hi Alexey
     
    Thanks for your quick answer.
    I've tried the code you gave me, but no luck. the same problem persists.
     
    I attach the project again, this time exactly as the one I am trying, except I removed the the license .
     
    Regards
    Josue
     
  •  05-09-2008, 10:57 AM 126266 in reply to 126250

    Re: Problem Merging document into another ignores the position of the original placeholders

    Attachment: Present (inaccessible)

    Hi

     

    Thanks for your request. Please try using the attached code and let me know if this works.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-13-2008, 2:26 AM 126615 in reply to 126266

    Re: Problem Merging document into another ignores the position of the original placeholders

    Hi Alexey,

    It works!, thanks a lot for your support. I appreciate this very much. I'll do some other test with other escenarios before deploy this solution.

    Again, thanks a lot.

    Regards,  Josue

     
  •  05-13-2008, 9:42 AM 126694 in reply to 126266

    Re: Problem Merging document into another ignores the position of the original placeholders

    Attachment: Present (inaccessible)

    Hi Alexey,

     

    I was doing some other testes, the solution you delivered works really good, however, I found a little bug, It is related to the styles,  after the splitter runs it reset the appropriates styles, as you could see, when the placeholder is replaced with a document it does not matter the style, but when this will be replaces with a text after, the splitter has reset the style.

    I tried to fix by using the style from run1 in run2, but it did no work.

    I send you my little application once again, I hope you can help me out to find a solution.

    I appreciate you help,

    Kind regards,

    Josue

     

    - Before Splitter

     

    [%PlaceHolder_A%]

    [%PlaceHolder_B%]

    [%PlaceHolder_C%]

     

    - After Splitter

     

    [%PlaceHolder_A%]

    [%PlaceHolder_B%]

    [%PlaceHolder_C%]

     

     
  •  05-13-2008, 9:54 AM 126705 in reply to 126694

    Re: Problem Merging document into another ignores the position of the original placeholders

    Hi

     

    Thanks for your request. Just try using The following line of code

     

    Run run2 = (Run)run1.Clone(true);

     

    Instead

     

    Run run2 = new Run(e.MatchNode.Document);

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-13-2008, 10:43 AM 126720 in reply to 126705

    Re: Problem Merging document into another ignores the position of the original placeholders

    Hi Alexey,

    It woks like charm! thanks a lot for your help.

    Best regards,

    Josue

     
  •  05-15-2008, 7:14 AM 127207 in reply to 126720

    Re: Problem Merging document into another ignores the position of the original placeholders

    Attachment: Present (inaccessible)

    Hi Alexey,

     

    We have found another problem in regarding the snippetsnippt code you delivered me to solve the problem regaring the topic.

     

    In the document there are some place holders which will be replaced with plain text, now these have problem, after the splitter runs the space between words is removed and pleaced at the beginning, so when the replacement takes afect the result is that the word stick together and there is a gap at the bigining.

     

    Sorry to bother you, I thought everything was ok, till i found this. 

     

    see sample:

     

    ===Original Text===

     

    UBS AG in                                                                                  (nachstehend UBS)

    und [%Anrede%] [%Vorname%] [%Name%]                                        (nachstehend Arbeitnehmer)

    vereinbaren:

     

    [%VertragDauer2%] [%VertragDauer3%]

     

    ===Result after the splitter===

     

    UBS AG in                                                                                  (nachstehend UBS)

    und   [%Anrede%][%Vorname%][%Name%]                                        (nachstehend Arbeitnehmer)

    vereinbaren:

     

     [%VertragDauer2%][%VertragDauer3%]

     

     

    Notice: that the space which separes each word of the other is removed a passed to the begining of the word.

     

    I attach again the little solution for you to reproduce the error.

     

    Dieses Schreiben ist eine Ergänzung zum bestehenden Arbeitsvertrag vom [Datum] und ändert diesen in folgenden Punkten ab:

    PlaceHolderOrder1 in RollePlaceHolderOrder2 in SalaerPlaceHolderOrder3 in RangPlaceHolderOrder4 in BGPlaceHolderOrder5 in Vertragsdauer

     
  •  05-15-2008, 8:25 AM 127213 in reply to 127207

    Re: Problem Merging document into another ignores the position of the original placeholders

    Hi

     

    Thanks for your request. Please try using the following regex:

     

    Regex splitRegex = new Regex(" *?\\[%(?<name>.*?)%\\]");

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-15-2008, 2:13 PM 127290 in reply to 127213

    Re: Problem Merging document into another ignores the position of the original placeholders

    Hi Alexey,

     

    Thanks for your quick answer, as you see this solve a problem but leads another,

    The placeholders for plain text are ok, the spaces remain, this is just perfect, but this removes all spaces in a row when documents are merged.

     

    OK

    und [%Anrede%] [%Vorname%] [%Name%]

    vereinbaren:

     

    [%VertragDauer2%] [%VertragDauer3%]

     

    NOK

    PlaceHolderOrder2 in SalaerPlaceHolderOrder3 in Rang                                              

     

     

    In template is so:

     

    [%Test1%]                                               [%Test2%]

     

     

    [%Test1%]                                               [%Test2%]

     

    So result should have the gap between place holders.

     

    Many thanks for your help.

     

    Regards

    Josue

     

     
  •  05-16-2008, 3:00 AM