Repository navigation
Expand file tree
/
Copy pathWordConvert.js
More file actions
153 lines (132 loc) · 5.24 KB
/
Copy pathWordConvert.js
File metadata and controls
153 lines (132 loc) · 5.24 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
*
* @param args {args.NameInput:string,args.NameOutput:string}
*/
var WordConvert = function (args) {
try {
// ************************************************************************
// PRIVATE VARIABLES AND FUNCTIONS
// ***********************************************************************
var FSO = new ActiveXObject("Scripting.FileSystemObject");
/**
*
* @param FileName
* @returns path or null
*/
var GetFullPath = function (FileName) {
var path = null;
if (FSO.FileExists(FileName)) path = FSO.GetAbsolutePathName(FileName);
if (!path) throw new Error("Ïóòü íå íàéäåí:" + FileName);
return path;
};
/**
*
* @param foldername
* @returns fullpath
*/
var GetOutFolderPath = function (foldername)
{
var path = null;
var treeArray = foldername.split(/([\\/])/)
var namefile = treeArray[treeArray.length - 1];
treeArray.splice(treeArray.length - 1, 1)
if (treeArray[0] == "..") { treeArray[0] = FSO.GetAbsolutePathName(".\\"); }
var pathtofolder = treeArray.join('\\')
if (FSO.FolderExists(pathtofolder)) path = FSO.GetAbsolutePathName(pathtofolder);
if (path == null) throw new Error("Ïóòü íå íàéäåí:" + path);
return path + "\\" + namefile;
}
var NameInput = "";
var NameOutput = "";
var PathInput = "";
var PathOutput = "";
if (args!=null) {
if (args.NameInput!=null) { NameInput = args.NameInput; PathInput = GetFullPath(NameInput); }
if (args.NameOutput!=null) { NameOutput = args.NameOutput; PathOutput = GetOutFolderPath(NameOutput); }
}
/**
*
* @param file
*/
var DeleteFile =function(file)
{
var path_f = GetFullPath(file);
FSO.DeleteFile(path_f);
}
/**
*
* @returns HTML
*/
var GetHTMLfromFile = function () {
var myModelessDialog = showModelessDialog(PathOutput, window, "status:false; dialogWidth:400px;dialogHeight:400px;help:no;status:no;center:yes;resizable:yes;minimize:yes;maximize:yes;scroll:no;");
var modelessBody = myModelessDialog.document.body;
var HTML = myModelessDialog.document.getElementsByTagName('html')[0].innerHTML;
myModelessDialog.close();
return HTML;
}
// ************************************************************************
// PRIVILEGED METHODS
// MAY BE INVOKED PUBLICLY AND MAY ACCESS PRIVATE ITEMS
// ************************************************************************
/**
*
* @param outdocumentname
* @returns
*/
this.SaveAsHTML = function (outdocumentname) {
if (outdocumentname!=null) {
NameOutput = outdocumentname;
PathOutput = GetOutFolderPath(outdocumentname);
}
if (PathOutput == "")
{
NameOutput = ".\\Default.html";
PathOutput = GetOutFolderPath(NameOutput);
}
var wrdApp = new ActiveXObject("Word.Application");
var wrdDoc = wrdApp.Documents.Open(PathInput);
wrdApp.ActiveDocument.SaveAs(PathOutput, 8); // 8 represents the html fileformat
wrdDoc.Close(0);
wrdApp.Quit();
}
/**
*
* @param inputname
*/
this.Open = function (inputname) {
if (!inputname) {
NameInput = inputname;
PathInput = GetFullPath(inputname);
}
}
/**
*
* @returns HTML
*/
this.GetHTML = function ()
{
return GetHTMLfromFile();
}
/**
* @fires SaveAsHTML
* @returns HTML
*/
this.GenerateHTML = function()
{
if (!PathInput) throw new Error("Âõîäíîé ôàéë íå óñòàíîâëåí");
this.SaveAsHTML();
}
/**
*
* @returns path to Default.html
*/
this.GetSrcHTML = function ()
{
return PathOutput;
}
}
catch (e)
{
alert(e.message + "\nLine:" + e.lineNumber);
}
}