Skip to content
本页内容

AirScript

金山文档提供了一个基于云的 JavaScript 平台,允许用户通过该平台进行脚本创建、访问和修改文件内容。

适用范围

目前仅支持电子表格文件

接口列表

快速开始

将表格文件的A1单元格改成HelloWorld

1. 提交脚本以及运行参数到 JavaScript 云平台

curl --request POST \
	--url 'https://developer.kdocs.cn/api/v1/openapi/personal/files/G_xvUrobayOMXvA4IJFVq19n6epm0T7PjYphWo-N3cE/script?access_token=kvqxrspxjctdojjqdildjhonzwusaquc' \
	--data '{"script":"Application.Range(\"A1\").Value = \"HelloWorld\""}'
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"script\":\"Application.Range(\\\"A1\\\").Value = \\\"HelloWorld\\\"\"}");
Request request = new Request.Builder()
	.url("https://developer.kdocs.cn/api/v1/openapi/personal/files/G_xvUrobayOMXvA4IJFVq19n6epm0T7PjYphWo-N3cE/script?access_token=kvqxrspxjctdojjqdildjhonzwusaquc")
	.post(body)
	.build();

Response response = client.newCall(request).execute();
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://developer.kdocs.cn/api/v1/openapi/personal/files/G_xvUrobayOMXvA4IJFVq19n6epm0T7PjYphWo-N3cE/script?access_token=kvqxrspxjctdojjqdildjhonzwusaquc"

	payload := strings.NewReader("{\"script\":\"Application.Range(\\\"A1\\\").Value = \\\"HelloWorld\\\"\"}")

	req, _ := http.NewRequest("POST", url, payload)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
import http.client

conn = http.client.HTTPSConnection("developer.kdocs.cn")

payload = "{\"script\":\"Application.Range(\\\"A1\\\").Value = \\\"HelloWorld\\\"\"}"

conn.request("POST", "/api/v1/openapi/personal/files/G_xvUrobayOMXvA4IJFVq19n6epm0T7PjYphWo-N3cE/script?access_token=kvqxrspxjctdojjqdildjhonzwusaquc", payload)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
<?php

$curl = curl_init();

curl_setopt_array($curl, [
	CURLOPT_URL => "https://developer.kdocs.cn/api/v1/openapi/personal/files/G_xvUrobayOMXvA4IJFVq19n6epm0T7PjYphWo-N3cE/script?access_token=kvqxrspxjctdojjqdildjhonzwusaquc",
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => "",
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 30,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => "POST",
	CURLOPT_POSTFIELDS => "{\"script\":\"Application.Range(\\\"A1\\\").Value = \\\"HelloWorld\\\"\"}",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
	echo "cURL Error #:" . $err;
} else {
	echo $response;
}
const data = JSON.stringify({
	"script": "Application.Range(\"A1\").Value = \"HelloWorld\""
});

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
	if (this.readyState === this.DONE) {
		console.log(this.responseText);
	}
});

xhr.open("POST", "https://developer.kdocs.cn/api/v1/openapi/personal/files/G_xvUrobayOMXvA4IJFVq19n6epm0T7PjYphWo-N3cE/script?access_token=kvqxrspxjctdojjqdildjhonzwusaquc");

xhr.send(data);
const http = require("https");

const options = {
	"method": "POST",
	"hostname": "developer.kdocs.cn",
	"port": null,
	"path": "/api/v1/openapi/personal/files/G_xvUrobayOMXvA4IJFVq19n6epm0T7PjYphWo-N3cE/script?access_token=kvqxrspxjctdojjqdildjhonzwusaquc",
	"headers": {}
};

const req = http.request(options, function (res) {
	const chunks = [];

	res.on("data", function (chunk) {
		chunks.push(chunk);
	});

	res.on("end", function () {
		const body = Buffer.concat(chunks);
		console.log(body.toString());
	});
});

req.write(JSON.stringify({script: 'Application.Range("A1").Value = "HelloWorld"'}));
req.end();
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://developer.kdocs.cn/api/v1/openapi/personal/files/G_xvUrobayOMXvA4IJFVq19n6epm0T7PjYphWo-N3cE/script?access_token=kvqxrspxjctdojjqdildjhonzwusaquc");

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"script\":\"Application.Range(\\\"A1\\\").Value = \\\"HelloWorld\\\"\"}");

CURLcode ret = curl_easy_perform(hnd);
var client = new RestClient("https://developer.kdocs.cn/api/v1/openapi/personal/files/G_xvUrobayOMXvA4IJFVq19n6epm0T7PjYphWo-N3cE/script?access_token=kvqxrspxjctdojjqdildjhonzwusaquc");
var request = new RestRequest(Method.POST);
request.AddParameter("undefined", "{\"script\":\"Application.Range(\\\"A1\\\").Value = \\\"HelloWorld\\\"\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
  • 返回值:
{
  "code": 0,
  "data": {
    "task_id": "ID7HWqZ3dheDcYlOF1PdBVCFNM9I5nCmnWwgJqCkX3tSIx6XL3kswKpqqKdgh1YhZ1AOp1GiVgTu42iHLB9mfy2A9KZdAP/dLIGRAbCkc7vNzXU92RuPdCs44LDZdmn1NvisgBMcXIcseg==",
    "task_type": "script"
  }
}

2. 通过 JavaScript 云平台返回的task_id 查询任务执行结果

curl --request GET \
	--url 'https://developer.kdocs.cn/api/v1/openapi/personal/script/status?access_token=kvqxrspxjctdojjqdildjhonzwusaquc&task_id=ID7HWqZ3dheDcYlOF1PdBVCFNM9I5nCmnWwgJqCkX3tSIx6XL3kswKpqqKdgh1YhZ1AOp1GiVgTu42iHLB9mfy2A9KZdAP%252FdLIGRAbCkc7vNzXU92RuPdCs44LDZdmn1NvisgBMcXIcseg%253D%253D'
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
	.url("https://developer.kdocs.cn/api/v1/openapi/personal/script/status?access_token=kvqxrspxjctdojjqdildjhonzwusaquc&task_id=ID7HWqZ3dheDcYlOF1PdBVCFNM9I5nCmnWwgJqCkX3tSIx6XL3kswKpqqKdgh1YhZ1AOp1GiVgTu42iHLB9mfy2A9KZdAP%252FdLIGRAbCkc7vNzXU92RuPdCs44LDZdmn1NvisgBMcXIcseg%253D%253D")
	.get()
	.build();

Response response = client.newCall(request).execute();
package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://developer.kdocs.cn/api/v1/openapi/personal/script/status?access_token=kvqxrspxjctdojjqdildjhonzwusaquc&task_id=ID7HWqZ3dheDcYlOF1PdBVCFNM9I5nCmnWwgJqCkX3tSIx6XL3kswKpqqKdgh1YhZ1AOp1GiVgTu42iHLB9mfy2A9KZdAP%252FdLIGRAbCkc7vNzXU92RuPdCs44LDZdmn1NvisgBMcXIcseg%253D%253D"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
import http.client

conn = http.client.HTTPSConnection("developer.kdocs.cn")

conn.request("GET", "/api/v1/openapi/personal/script/status?access_token=kvqxrspxjctdojjqdildjhonzwusaquc&task_id=ID7HWqZ3dheDcYlOF1PdBVCFNM9I5nCmnWwgJqCkX3tSIx6XL3kswKpqqKdgh1YhZ1AOp1GiVgTu42iHLB9mfy2A9KZdAP%252FdLIGRAbCkc7vNzXU92RuPdCs44LDZdmn1NvisgBMcXIcseg%253D%253D")

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
<?php

$curl = curl_init();

curl_setopt_array($curl, [
	CURLOPT_URL => "https://developer.kdocs.cn/api/v1/openapi/personal/script/status?access_token=kvqxrspxjctdojjqdildjhonzwusaquc&task_id=ID7HWqZ3dheDcYlOF1PdBVCFNM9I5nCmnWwgJqCkX3tSIx6XL3kswKpqqKdgh1YhZ1AOp1GiVgTu42iHLB9mfy2A9KZdAP%252FdLIGRAbCkc7vNzXU92RuPdCs44LDZdmn1NvisgBMcXIcseg%253D%253D",
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => "",
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 30,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => "GET",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
	echo "cURL Error #:" . $err;
} else {
	echo $response;
}
const data = null;

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
	if (this.readyState === this.DONE) {
		console.log(this.responseText);
	}
});

xhr.open("GET", "https://developer.kdocs.cn/api/v1/openapi/personal/script/status?access_token=kvqxrspxjctdojjqdildjhonzwusaquc&task_id=ID7HWqZ3dheDcYlOF1PdBVCFNM9I5nCmnWwgJqCkX3tSIx6XL3kswKpqqKdgh1YhZ1AOp1GiVgTu42iHLB9mfy2A9KZdAP%252FdLIGRAbCkc7vNzXU92RuPdCs44LDZdmn1NvisgBMcXIcseg%253D%253D");

xhr.send(data);
const http = require("https");

const options = {
	"method": "GET",
	"hostname": "developer.kdocs.cn",
	"port": null,
	"path": "/api/v1/openapi/personal/script/status?access_token=kvqxrspxjctdojjqdildjhonzwusaquc&task_id=ID7HWqZ3dheDcYlOF1PdBVCFNM9I5nCmnWwgJqCkX3tSIx6XL3kswKpqqKdgh1YhZ1AOp1GiVgTu42iHLB9mfy2A9KZdAP%252FdLIGRAbCkc7vNzXU92RuPdCs44LDZdmn1NvisgBMcXIcseg%253D%253D",
	"headers": {}
};

const req = http.request(options, function (res) {
	const chunks = [];

	res.on("data", function (chunk) {
		chunks.push(chunk);
	});

	res.on("end", function () {
		const body = Buffer.concat(chunks);
		console.log(body.toString());
	});
});

req.end();
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "https://developer.kdocs.cn/api/v1/openapi/personal/script/status?access_token=kvqxrspxjctdojjqdildjhonzwusaquc&task_id=ID7HWqZ3dheDcYlOF1PdBVCFNM9I5nCmnWwgJqCkX3tSIx6XL3kswKpqqKdgh1YhZ1AOp1GiVgTu42iHLB9mfy2A9KZdAP%252FdLIGRAbCkc7vNzXU92RuPdCs44LDZdmn1NvisgBMcXIcseg%253D%253D");

CURLcode ret = curl_easy_perform(hnd);
var client = new RestClient("https://developer.kdocs.cn/api/v1/openapi/personal/script/status?access_token=kvqxrspxjctdojjqdildjhonzwusaquc&task_id=ID7HWqZ3dheDcYlOF1PdBVCFNM9I5nCmnWwgJqCkX3tSIx6XL3kswKpqqKdgh1YhZ1AOp1GiVgTu42iHLB9mfy2A9KZdAP%252FdLIGRAbCkc7vNzXU92RuPdCs44LDZdmn1NvisgBMcXIcseg%253D%253D");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
  • 返回值:
{
  "error": "",
  "status": "finish",
  "data": {
    "logs": [
      {
        "args": [
          "脚本环境初始化..."
        ],
        "filename": "system",
        "level": "info",
        "timestamp": "17:49:24.693"
      },
      {
        "args": [
          "已开始执行"
        ],
        "filename": "system",
        "level": "info",
        "timestamp": "17:49:26.622"
      },
      {
        "args": [
          "执行完毕"
        ],
        "filename": "system",
        "level": "info",
        "timestamp": "17:49:26.714"
      }
    ],
    "result": "HelloWorld"
  }
}

脚本编写

编写指南