0

Is it possible to create a .doc format file in JavaScript?
Currently I have a Mozilla addon which creates .txt files but curious to see if it could be extended to .doc ..

file = Components.classes["@mozilla.org/file/local;1"]
                     .createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(fullPathToFile);

if (file.exists() === false) 
    {file.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420);}

var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
                    .createInstance(Components.interfaces.nsIFileOutputStream),
converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
                    .createInstance(Components.interfaces.nsIConverterOutputStream);


outputStream.init(file, 0x02 | 0x08 | 0x20, 420, 0);
converter.init(outputStream, "UTF-8", 0, 0);
converter.writeString('\n --------------------------------------------------- \n');
converter.close();
2
  • While it should be possible, you might want to look at RTF files which will be much easier to create -- if you rename them as a 'DOC' file, very few people will know the difference. If you are doing a form letter with search-and-replace fields, those are super-easy to do as an RTF. Commented Mar 25, 2013 at 4:30
  • was hoping for an actual .doc, instead of .rtf workaround
    – bobbyrne01
    Commented Apr 5, 2013 at 18:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.