优化js代码注入
This commit is contained in:
1 parent
d15e8185bb
commit
6ba9ed637b
3 files changed
+176
-64
No files matched your search
+73
-27
@@ -1,29 +1,75 @@
|
||||
const wps = {
|
||||
app: wps.WpsApplication(),
|
||||
replace: () => {
|
||||
Selection.SetRange(16, 16);
|
||||
Selection.Find.Wrap = wdFindContinue;
|
||||
(obj => {
|
||||
obj.Text = "1";
|
||||
obj.Forward = true;
|
||||
obj.Wrap = wdFindContinue;
|
||||
obj.MatchCase = false;
|
||||
obj.MatchByte = true;
|
||||
obj.MatchWildcards = false;
|
||||
obj.MatchWholeWord = false;
|
||||
obj.MatchFuzzy = false;
|
||||
obj.Replacement.Text = "2";
|
||||
})(Selection.Find);
|
||||
(obj => {
|
||||
obj.Style = "";
|
||||
obj.Highlight = wdUndefined;
|
||||
(obj => {
|
||||
obj.Style = "";
|
||||
obj.Highlight = wdUndefined;
|
||||
})(obj.Replacement);
|
||||
})(Selection.Find);
|
||||
Selection.Find.Execute(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, wdReplaceAll, undefined, undefined, undefined, undefined);
|
||||
Selection.Find.Replacement.Text = "2";
|
||||
}
|
||||
const wpsInstance = {
|
||||
app: wps.WpsApplication().Application,
|
||||
// 启动Word
|
||||
|
||||
// Word导出PDF
|
||||
|
||||
// 读取Word文本
|
||||
getText: () => {
|
||||
const activeDocument = wpsInstance.app.ActiveDocument;
|
||||
return activeDocument.Content.Text;
|
||||
},
|
||||
// 写入文本至Word中
|
||||
setText: (args) => {
|
||||
let text = args.text;
|
||||
const doc = wpsInstance.app.ActiveDocument;
|
||||
doc.Range(wpsInstance.app.Selection.Start, wpsInstance.app.Selection.End).Text = text;
|
||||
|
||||
},
|
||||
// 定位Word光标
|
||||
setCursor: (args) => {
|
||||
const activeDocument = wpsInstance.app.ActiveDocument;
|
||||
const range = activeDocument.Content;
|
||||
range.SetRange(args.start, args.end);
|
||||
},
|
||||
// 移动Word光标
|
||||
|
||||
// 替换Word文本
|
||||
replace: (args) => {
|
||||
const text = args.text;
|
||||
const replacement = args.replacement;
|
||||
const find = wpsInstance.app.Selection.Find;
|
||||
const activeDocument = wpsInstance.app.ActiveDocument;
|
||||
|
||||
activeDocument.Content.Select();
|
||||
find.Text = text;
|
||||
find.MatchByte = false;
|
||||
find.Replacement.Text = replacement;
|
||||
find.Execute(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, 2, undefined, undefined, undefined, undefined);
|
||||
},
|
||||
// 读取Word表格
|
||||
|
||||
// 插入Word表格
|
||||
addTable: (args) => {
|
||||
const rows = args.rows;
|
||||
const cols = args.cols;
|
||||
const doc = wpsInstance.app.ActiveDocument;
|
||||
const range = wpsInstance.app.Selection.Range;
|
||||
|
||||
doc.Tables.Add(range, rows, cols);
|
||||
},
|
||||
// 插入图片
|
||||
addPicture: (args) => {
|
||||
let path = args.path;
|
||||
let doc = wpsInstance.app.ActiveDocument;
|
||||
doc.InlineShapes.AddPicture(FileName = path, Range = wpsInstance.app.Selection.Range);
|
||||
},
|
||||
// 插入超链接
|
||||
insertHyperlink: (args) => {
|
||||
let link = args.link;
|
||||
let text = args.text;
|
||||
let doc = wpsInstance.app.ActiveDocument;
|
||||
|
||||
doc.Hyperlinks.Add(wpsInstance.app.Selection.Range, link, undefined, undefined, text, undefined);
|
||||
},
|
||||
// 保存Word
|
||||
save: () => {
|
||||
wpsInstance.app.ActiveDocument.Save();
|
||||
},
|
||||
// 关闭Word
|
||||
close: () => {
|
||||
wpsInstance.app.ActiveDocument.Close();
|
||||
}
|
||||
}
|
||||
|
||||
return wpsInstance;
|
||||
Reference in new issue
Block a user