-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathword_sample.js
33 lines (30 loc) · 910 Bytes
/
word_sample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var win32ole = require('win32ole');
win32ole.print('word_sample\n');
console.log(win32ole.version());
var path = require('path');
var cwd = path.join(win32ole.MODULEDIRNAME, '..');
var fs = require('fs');
var tmpdir = path.join(cwd, 'test/tmp');
if(!fs.existsSync(tmpdir)) fs.mkdirSync(tmpdir);
var outfile = path.join(tmpdir, 'word_sample.doc');
var word_sample = function(filename){
var wd = win32ole.client.Dispatch('Word.Application');
wd.Visible = true;
var doc = wd.Documents.Add();
var para = doc.Content.Paragraphs.Add();
para.Range.Text = 'stringUTF8';
try{
console.log('saving to: "' + filename + '" ...');
var result = doc.SaveAs(filename);
console.log(result); // *** undefined
}catch(e){
console.log('(exception cached)\n' + e);
}
wd.Documents.Close();
wd.Quit();
};
try{
word_sample(outfile);
}catch(e){
console.log('*** exception cached ***\n' + e);
}