ms word - Converting Docx Files To Text In Swift -
i have .docx file in temporary storage:
let location: nsurl = nsurl.fileurlwithpath(nstemporarydirectory()) let file_name = location.urlbyappendingpathcomponent("5 november 2016.docx")
what want extract text inside document. cannot seem find converters or methods of doing this.
i have tried this:
let file_content = try? nsstring(contentsoffile: string(file_name), encoding: nsutf8stringencoding) print(file_content)
however prints nil.
so how read text in docx file?
your initial issue how string url. string(file_name)
not correct way convert file url file path. proper way use path
function.
let location = nsurl.fileurlwithpath(nstemporarydirectory()) let fileurl = location.urlbyappendingpathcomponent("my file.docx") let filecontent = try? nsstring(contentsoffile: fileurl.path, encoding: nsutf8stringencoding)
note many changes. use proper naming conventions. name variables more clearly.
now here's thing. still won't work because docx file zipped collection of xml , other files. can't load docx file nsstring
. need use nsdata
load zip contents. need unzip it. need go through of files , find desired text. it's far trivial , far beyond scope of single stack overflow post.
Comments
Post a Comment