init
This commit is contained in:
commit
5b00bd10d0
15 files changed
+524
No files matched your search
@@ -0,0 +1,69 @@
|
||||
function onbuttonclick(idStr)
|
||||
{
|
||||
switch(idStr)
|
||||
{
|
||||
case "getDocName":{
|
||||
let doc = window.Application.ActiveDocument
|
||||
let textValue = ""
|
||||
if (!doc){
|
||||
textValue = textValue + "当前没有打开任何文档"
|
||||
return
|
||||
}
|
||||
textValue = textValue + doc.Name
|
||||
document.getElementById("text_p").innerHTML = textValue
|
||||
break
|
||||
}
|
||||
case "createTaskPane":{
|
||||
let tsId = window.Application.PluginStorage.getItem("taskpane_id")
|
||||
if (!tsId){
|
||||
let tskpane = window.Application.CreateTaskPane(GetUrlPath() + "/taskpane.html")
|
||||
let id = tskpane.ID
|
||||
window.Application.PluginStorage.setItem("taskpane_id", id)
|
||||
tskpane.Visible = true
|
||||
}else{
|
||||
let tskpane = window.Application.GetTaskPane(tsId)
|
||||
tskpane.Visible = true
|
||||
}
|
||||
break
|
||||
}
|
||||
case "newDoc":{
|
||||
window.Application.Documents.Add()
|
||||
break
|
||||
}
|
||||
case "addString":{
|
||||
let doc = window.Application.ActiveDocument
|
||||
if (doc){
|
||||
doc.Range(0, 0).Text="Hello, wps加载项!"
|
||||
//好像是wps的bug, 这两句话触发wps重绘
|
||||
let rgSel = window.Application.Selection.Range
|
||||
if (rgSel)
|
||||
rgSel.Select()
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "closeDoc":{
|
||||
if (window.Application.Documents.Count < 2)
|
||||
{
|
||||
alert("当前只有一个文档,别关了。")
|
||||
break
|
||||
}
|
||||
|
||||
let doc = window.Application.ActiveDocument
|
||||
if (doc)
|
||||
doc.Close()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
var xmlReq = WpsInvoke.CreateXHR();
|
||||
var url = location.origin + "/.debugTemp/NotifyDemoUrl"
|
||||
xmlReq.open("GET", url);
|
||||
xmlReq.onload = function (res) {
|
||||
var node = document.getElementById("DemoSpan");
|
||||
node.innerText = res.target.responseText;
|
||||
};
|
||||
xmlReq.send();
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
|
||||
//这个函数在整个wps加载项中是第一个执行的
|
||||
function OnAddinLoad(ribbonUI){
|
||||
if (typeof (window.Application.ribbonUI) != "object"){
|
||||
window.Application.ribbonUI = ribbonUI
|
||||
}
|
||||
|
||||
if (typeof (window.Application.Enum) != "object") { // 如果没有内置枚举值
|
||||
window.Application.Enum = WPS_Enum
|
||||
}
|
||||
|
||||
window.Application.PluginStorage.setItem("EnableFlag", false) //往PluginStorage中设置一个标记,用于控制两个按钮的置灰
|
||||
window.Application.PluginStorage.setItem("ApiEventFlag", false) //往PluginStorage中设置一个标记,用于控制ApiEvent的按钮label
|
||||
return true
|
||||
}
|
||||
|
||||
var WebNotifycount = 0;
|
||||
function OnAction(control) {
|
||||
const eleId = control.Id
|
||||
switch (eleId) {
|
||||
case "btnShowMsg":
|
||||
{
|
||||
const doc = window.Application.ActiveDocument
|
||||
if (!doc) {
|
||||
alert("当前没有打开任何文档")
|
||||
return
|
||||
}
|
||||
alert(doc.Name)
|
||||
}
|
||||
break;
|
||||
case "btnIsEnbable":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
|
||||
window.Application.PluginStorage.setItem("EnableFlag", !bFlag)
|
||||
|
||||
//通知wps刷新以下几个按饰的状态
|
||||
window.Application.ribbonUI.InvalidateControl("btnIsEnbable")
|
||||
window.Application.ribbonUI.InvalidateControl("btnShowDialog")
|
||||
window.Application.ribbonUI.InvalidateControl("btnShowTaskPane")
|
||||
//window.Application.ribbonUI.Invalidate(); 这行代码打开则是刷新所有的按钮状态
|
||||
break
|
||||
}
|
||||
case "btnShowDialog":
|
||||
window.Application.ShowDialog(GetUrlPath() + "/ui/dialog.html", "这是一个对话框网页", 400 * window.devicePixelRatio, 400 * window.devicePixelRatio, false)
|
||||
break
|
||||
case "btnShowTaskPane":
|
||||
{
|
||||
let tsId = window.Application.PluginStorage.getItem("taskpane_id")
|
||||
if (!tsId) {
|
||||
let tskpane = window.Application.CreateTaskPane(GetUrlPath() + "/ui/taskpane.html")
|
||||
let id = tskpane.ID
|
||||
window.Application.PluginStorage.setItem("taskpane_id", id)
|
||||
tskpane.Visible = true
|
||||
} else {
|
||||
let tskpane = window.Application.GetTaskPane(tsId)
|
||||
tskpane.Visible = !tskpane.Visible
|
||||
}
|
||||
}
|
||||
break
|
||||
case "btnApiEvent":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("ApiEventFlag")
|
||||
let bRegister = bFlag ? false : true
|
||||
window.Application.PluginStorage.setItem("ApiEventFlag", bRegister)
|
||||
if (bRegister){
|
||||
window.Application.ApiEvent.AddApiEventListener('DocumentNew', OnNewDocumentApiEvent)
|
||||
}
|
||||
else{
|
||||
window.Application.ApiEvent.RemoveApiEventListener('DocumentNew', OnNewDocumentApiEvent)
|
||||
}
|
||||
|
||||
window.Application.ribbonUI.InvalidateControl("btnApiEvent")
|
||||
}
|
||||
break
|
||||
case "btnWebNotify":
|
||||
{
|
||||
let currentTime = new Date()
|
||||
let timeStr = currentTime.getHours() + ':' + currentTime.getMinutes() + ":" + currentTime.getSeconds()
|
||||
window.Application.OAAssist.WebNotify("这行内容由wps加载项主动送达给业务系统,可以任意自定义, 比如时间值:" + timeStr + ",次数:" + (++WebNotifycount), true)
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function GetImage(control) {
|
||||
const eleId = control.Id
|
||||
switch (eleId) {
|
||||
case "btnShowMsg":
|
||||
return "images/1.svg"
|
||||
case "btnShowDialog":
|
||||
return "images/2.svg"
|
||||
case "btnShowTaskPane":
|
||||
return "images/3.svg"
|
||||
default:
|
||||
;
|
||||
}
|
||||
return "images/newFromTemp.svg"
|
||||
}
|
||||
|
||||
function OnGetEnabled(control) {
|
||||
const eleId = control.Id
|
||||
switch (eleId) {
|
||||
case "btnShowMsg":
|
||||
return true
|
||||
break
|
||||
case "btnShowDialog":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
|
||||
return bFlag
|
||||
break
|
||||
}
|
||||
case "btnShowTaskPane":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
|
||||
return bFlag
|
||||
break
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function OnGetVisible(control){
|
||||
return true
|
||||
}
|
||||
|
||||
function OnGetLabel(control){
|
||||
const eleId = control.Id
|
||||
switch (eleId) {
|
||||
case "btnIsEnbable":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
|
||||
return bFlag ? "按钮Disable" : "按钮Enable"
|
||||
break
|
||||
}
|
||||
case "btnApiEvent":
|
||||
{
|
||||
let bFlag = window.Application.PluginStorage.getItem("ApiEventFlag")
|
||||
return bFlag ? "清除新建文件事件" : "注册新建文件事件"
|
||||
break
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
function OnNewDocumentApiEvent(doc){
|
||||
alert("新建文件事件响应,取文件名: " + doc.Name)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
function openOfficeFileFromSystemDemo(param){
|
||||
let jsonObj = (typeof(param)=='string' ? JSON.parse(param) : param)
|
||||
alert("从业务系统传过来的参数为:" + JSON.stringify(jsonObj))
|
||||
return {wps加载项项返回: jsonObj.filepath + ", 这个地址给的不正确"}
|
||||
}
|
||||
|
||||
function InvokeFromSystemDemo(param){
|
||||
let jsonObj = (typeof(param)=='string' ? JSON.parse(param) : param)
|
||||
let handleInfo = jsonObj.Index
|
||||
switch (handleInfo){
|
||||
case "getDocumentName":{
|
||||
let docName = ""
|
||||
if (window.Application.ActiveDocument){
|
||||
docName = window.Application.ActiveDocument.Name
|
||||
}
|
||||
|
||||
return {当前打开的文件名为:docName}
|
||||
}
|
||||
|
||||
case "newDocument":{
|
||||
let newDocName=""
|
||||
let doc = window.Application.Documents.Add()
|
||||
newDocName = doc.Name
|
||||
|
||||
return {操作结果:"新建文档成功,文档名为:" + newDocName}
|
||||
}
|
||||
|
||||
case "OpenFile":{
|
||||
let filePath = jsonObj.filepath
|
||||
window.Application.Documents.OpenFromUrl(filePath)
|
||||
return {操作结果:"打开文件成功"}
|
||||
}
|
||||
}
|
||||
|
||||
return {其它xxx:""}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
function onbuttonclick(idStr)
|
||||
{
|
||||
if (typeof (window.Application.Enum) != "object") { // 如果没有内置枚举值
|
||||
window.Application.Enum = WPS_Enum
|
||||
}
|
||||
switch(idStr)
|
||||
{
|
||||
case "dockLeft":{
|
||||
let tsId = window.Application.PluginStorage.getItem("taskpane_id")
|
||||
if (tsId){
|
||||
let tskpane = window.Application.GetTaskPane(tsId)
|
||||
tskpane.DockPosition = window.Application.Enum.msoCTPDockPositionLeft
|
||||
}
|
||||
break
|
||||
}
|
||||
case "dockRight":{
|
||||
let tsId = window.Application.PluginStorage.getItem("taskpane_id")
|
||||
if (tsId){
|
||||
let tskpane = window.Application.GetTaskPane(tsId)
|
||||
tskpane.DockPosition = window.Application.Enum.msoCTPDockPositionRight
|
||||
}
|
||||
break
|
||||
}
|
||||
case "hideTaskPane":{
|
||||
let tsId = window.Application.PluginStorage.getItem("taskpane_id")
|
||||
if (tsId){
|
||||
let tskpane = window.Application.GetTaskPane(tsId)
|
||||
tskpane.Visible = false
|
||||
}
|
||||
break
|
||||
}
|
||||
case "addString":{
|
||||
let doc = window.Application.ActiveDocument
|
||||
if (doc){
|
||||
doc.Range(0, 0).Text="Hello, wps加载项!"
|
||||
//好像是wps的bug, 这两句话触发wps重绘
|
||||
let rgSel = window.Application.Selection.Range
|
||||
if (rgSel)
|
||||
rgSel.Select()
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "getDocName":{
|
||||
let doc = window.Application.ActiveDocument
|
||||
let textValue = "";
|
||||
if (!doc){
|
||||
textValue = textValue + "当前没有打开任何文档"
|
||||
return
|
||||
}
|
||||
textValue = textValue + doc.Name
|
||||
document.getElementById("text_p").innerHTML = textValue
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
var xmlReq = WpsInvoke.CreateXHR();
|
||||
var url = location.origin + "/.debugTemp/NotifyDemoUrl"
|
||||
xmlReq.open("GET", url);
|
||||
xmlReq.onload = function (res) {
|
||||
var node = document.getElementById("DemoSpan");
|
||||
node.innerText = res.target.responseText;
|
||||
};
|
||||
xmlReq.send();
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
//在后续的wps版本中,wps的所有枚举值都会通过wps.Enum对象来自动支持,现阶段先人工定义
|
||||
var WPS_Enum = {
|
||||
msoCTPDockPositionLeft: 0,
|
||||
msoCTPDockPositionRight: 2
|
||||
}
|
||||
|
||||
function GetUrlPath() {
|
||||
let e = document.location.toString()
|
||||
return -1 != (e = decodeURI(e)).indexOf("/") && (e = e.substring(0, e.lastIndexOf("/"))), e
|
||||
}
|
||||
/**
|
||||
* 通过wps提供的接口执行一段脚本
|
||||
* @param {*} param 需要执行的脚本
|
||||
*/
|
||||
function shellExecuteByOAAssist(param) {
|
||||
if (wps != null) {
|
||||
wps.OAAssist.ShellExecute(param)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user