Giter Site home page Giter Site logo

Comments (6)

HannesMatthias avatar HannesMatthias commented on June 11, 2024 1

I just wonder, that nobody recognized it. Do you think, it will get fixed? Here is a word document to reproduce the error.

reproduce.docx

from docx.

satoryu avatar satoryu commented on June 11, 2024 1

@HannesMatthias I investigated the docx file you attached.
As you may know, docx file is a zip file consists of XML files. one of the XML file is word/document.xml, which represents entire content.

In this file, [EMPLOYEE_LAST_NAME] does not exist as it is split to two word [EMPLOYEE_LAST_ and NAME]

      <w:r w:rsidR="00B53417">
        <w:rPr>
          <w:rFonts w:ascii="Univers" w:hAnsi="Univers"/>
          <w:sz w:val="24"/>
          <w:lang w:val="en-AU"/>
        </w:rPr>
        <w:t>[EMPLOYEE_LAST_</w:t>
      </w:r>
      <w:proofErr w:type="gramStart"/>
      <w:r w:rsidR="00B53417">
        <w:rPr>
          <w:rFonts w:ascii="Univers" w:hAnsi="Univers"/>
          <w:sz w:val="24"/>
          <w:lang w:val="en-AU"/>
        </w:rPr>
        <w:t>NAME]</w:t>
      </w:r>

This is editor's issue, MS Word and Google Docs sometimes split words internally but different from what we see.

I recommend you to use bookmarks to point the place to where you want to insert some text , Docx::Document#bookmarks and Docx::Elements::Bookmark#insert_text_after.

For example, if your docx file has a bookmark named 'last_name', you can insert some text Jack there by using the following code:

doc = Docx::Document.open('/path/to/your/word/file.docx')
bookmarks = doc.bookmarks

bookmark = bookmarks['last_name']
bookmark.insert_text_after('Jack')

but I didn't confirm this script would work as you expect.

from docx.

HannesMatthias avatar HannesMatthias commented on June 11, 2024 1

Hello, thanks for the kind feedback. I will definitely try it out!

from docx.

WaKeMaTTa avatar WaKeMaTTa commented on June 11, 2024
doc.paragraphs.each do |p|
  p.each_text_run do |tr|
    tr.substitute('[LAST_NAME]', 'Matthias')
  end
end

from docx.

HannesMatthias avatar HannesMatthias commented on June 11, 2024

Hi @WaKeMaTTa, this is what I try to achive, but if I output the result of each "tr" I get something like this:

First iteration: [LAST_
Second iteraion: NAME] ...

The "each_text_run" splits my placeholders sometimes, which is weird.

from docx.

WaKeMaTTa avatar WaKeMaTTa commented on June 11, 2024

mmm I didn't know that.

from docx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.