undefined method `close' for nil:NilClass
JonasHelmoe opened this issue · 2 comments
JonasHelmoe commented
I wrote this simple code:
require 'docx'
# Create a Docx::Document object for our existing docx file
doc = Docx::Document.open("a.docx")
# Retrieve and display paragraphs
doc.paragraphs.each do |p|
puts p
end
...and keep getting "undefined method `close' for nil:NilClass".
I am sure the file is there, and tried many different locations for the file, so I'm suspecting this gem is not maintained.
Can anyone guide me? Thank you
JonasPreisler commented
Sorry, it worked when I used a real docx file. I just changed the file extension to "docx", but only after using a file from here, it worked: https://file-examples.com/index.php/sample-documents-download/sample-doc-download/
85636682 commented
file_path = File.join(Rails.public_path, '/files/file-sample_100kB.docx')
ExceptionTrack::Log.create(title: "file_path", body: "#{file_path}")
content = File.read(file_path)
doc = Docx::Document.open(content)
@JonasPreisler it not worked when I used a real docx file with your ,how did you do that