Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"replaceText" not working #82

Closed
SachinAspenify opened this issue Dec 18, 2023 · 7 comments
Closed

"replaceText" not working #82

SachinAspenify opened this issue Dec 18, 2023 · 7 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@SachinAspenify
Copy link

Environment - node.js version v21.0.0
OS - Mac

The package is very useful. Thanks for open-sourcing it.

I am trying to use the software to generate PPTX file from a template file. The "ReplaceText" function is not working as expected.

I tried to debug the code. But could not find any method that gives me text in an element.

Please find attached sample code I am using for my testing.
agreement-ppt.zip

@singerla singerla added the bug Something isn't working label Dec 18, 2023
@singerla
Copy link
Owner

Hi! It is because ppt separates the text into three xml elements:

<a:p>
  <a:r>
    <a:rPr lang="de-DE" sz="2000" i="1" dirty="0">
      <a:solidFill>
        <a:schemeClr val="accent6"/>
      </a:solidFill>
    </a:rPr>
    <a:t>{ </a:t>
  </a:r>
  <a:r>
    <a:rPr lang="de-DE" sz="2000" i="1" dirty="0" err="1">
      <a:solidFill>
        <a:schemeClr val="accent6"/>
      </a:solidFill>
    </a:rPr>
    <a:t>CustomerName</a:t>
  </a:r>
  <a:r>
    <a:rPr lang="de-DE" sz="2000" i="1" dirty="0">
      <a:solidFill>
        <a:schemeClr val="accent6"/>
      </a:solidFill>
    </a:rPr>
  <a:t> }</a:t>
  </a:r>
  <a:endParaRPr lang="de-DE" dirty="0"/>
</a:p>

Altough there is isolateTaggedNodes() in /src/helper/text-replace-helper.ts to handle those cases, it didn't work in your case.

You can try a workaround:

  • Cut out your {CustomerName} tag from textbox to clipboard.
  • Paste it into a plaintext editor (e.g. notepad) to remove all (visible and invisible) formatting.
  • Copy & paste {CustomerName} back to the textbox.

This will not make any visible difference, but join the xml elements.

This was first bubbling up in #73 .

Please let me know if this helps. Any help on isolateTaggedNodes() will be highly appreciated 😃

@singerla
Copy link
Owner

I see there is a difference: err="1" Could this be related to spell checking? I can remember some really weird situations in the past and finding a solution will make a happy man out of me 😆

@SachinAspenify
Copy link
Author

I did try the solution you mentioned earlier. Somehow I did not work.

What I did now, is that I deleted the placehoder and re-added it to PPT. Now it worked fine. We can close the issue. Thanks for your help.

Is there a way, we view the ppt xml so that it is easy to debug.

@singerla
Copy link
Owner

You could try slide.modifyElement('testElementName', [XmlHelper.dump]);

I'm happy to help 😃

@SachinAspenify
Copy link
Author

I identified the underlying issue. I utilized an existing PowerPoint (PPT) file as a template and included curly brackets around a placeholder string that was already present in the presentation. This unintentionally resulted in the creation of three distinct components ('{', 'placeholder string', '}'), as shown by you above. Consequently, the replaceText function did not function as expected.

It might be beneficial to include this information in a troubleshooting guide to help others avoid encountering a similar issue in the future.

@singerla singerla added the wontfix This will not be worked on label Dec 19, 2023
@singerla
Copy link
Owner

Thanks a lot for your feedback. In my point of view, this is a bug, because your approach should work on all text elements. At the moment, I won't go deeper into this, because the workaround is very simple.

@singerla
Copy link
Owner

It could also help to disable spell checking for {{mytag}}. If ppt encounters an unknown word, it will split xml blocks and mark the unknown with an err="1" attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants