Comments (6)
I just wonder, that nobody recognized it. Do you think, it will get fixed? Here is a word document to reproduce the error.
from docx.
@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.
Hello, thanks for the kind feedback. I will definitely try it out!
from docx.
doc.paragraphs.each do |p|
p.each_text_run do |tr|
tr.substitute('[LAST_NAME]', 'Matthias')
end
end
from docx.
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.
mmm I didn't know that.
from docx.
Related Issues (20)
- undefined method `close' for nil:NilClass HOT 1
- Can't open document using a Pathname. Breaking change between 0.4.0 and 0.6.0 HOT 2
- ENOENT error because internal doc is word/document22.xml HOT 7
- to_s crash, presumably when doc has word/document22.xml inside HOT 2
- I'm trying to test a docx download and I hoped I could use this for parsing but I don't understand how HOT 4
- Detect and trim blank page
- ZIP library isn't working as expected in the document.rb
- Replace different placeholder text in each table cell HOT 4
- Text not being inserted after bookmark HOT 4
- Order of paragraphs and tables HOT 4
- Can watermark be supported
- to_html only considers some styles and not others HOT 1
- Fuzzer + various crashes
- Request to remove monkeypatching on Module HOT 2
- Please cut a new gem release to include a fix HOT 2
- Unable to read Binary String HOT 8
- How to write data without bookmarks ? HOT 1
- Question: only paragraphs that are not part of a table? HOT 5
- Import picture inplace of bookmark
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docx.