前言
注意
安装的时候需要电脑上的
Python
版本为2.7
,否则编译报错。
设置环境
代码语言:javascript复制npm config set python python2.7
npm config set msvs_version 2017
安装
代码语言:javascript复制npm install winax --msvs_version=2017
使用
代码语言:javascript复制var winax = require('winax');
var con = new winax.Object('ADODB.Connection');
利用WPS进行文档转换
文档格式转换
文档格式转换 支持 wps、wpt、doc、docx、dot、txt等所有文档格式文件
代码语言:javascript复制var winax = require('winax');
var Variant = winax.Variant;
var source_path = "D:\Tools\1.doc";
var target_path = "D:\Tools\1.pdf";
var wax = new winax.Object("KWPS.Application", {
activate: true
});
try {
var doc = wax.Documents.Open(new Variant(source_path), new Variant(true), new Variant(true));
doc.SaveAs(new Variant(target_path), new Variant(17));
doc.Close();
} catch (e) {
console.info(e);
} finally {
wax.Quit();
}
幻灯片格式转换
幻灯片格式转换 支持ppt、pps、pptx、ppsx、dps、dpt、pot、uof
代码语言:javascript复制var winax = require('winax');
var Variant = winax.Variant;
var source_path = "D:\Tools\1.pptx";
var target_path = "D:\Tools\2.pdf";
var wax = new winax.Object("KWPP.Application", {
activate: true
});
try {
var doc = wax.Presentations.Open(new Variant(source_path), new Variant(true));
doc.SaveAs(new Variant(target_path), new Variant(32));
doc.Close();
} catch (e) {
console.info(e);
} finally {
wax.Quit();
}
转换表格
表格格式转换 支持et、ett、xls、xlsx、xlt、uof、prn、csv
代码语言:javascript复制var winax = require('winax');
var Variant = winax.Variant;
var source_path = "D:\Tools\1.xlsx";
var target_path = "D:\Tools\3.pdf";
var wax = new winax.Object("KET.Application", {
activate: true
});
try {
var doc = wax.Workbooks.Open(new Variant(source_path), new Variant(0), new Variant(true));
doc.ExportAsFixedFormat(new Variant(0), new Variant(target_path), new Variant(0));
doc.Close();
} catch (e) {
console.info(e);
} finally {
wax.Quit();
}
文件服务器
安装依赖
代码语言:javascript复制npm install connect
npm install serve-static
代码
代码语言:javascript复制var connect = require("connect");
var serveStatic = require("serve-static");
var app = connect();
app.use(serveStatic("D:\Tools"));
app.listen(5000);
console.info("文件服务器启动了!");
WS服务器
代码语言:javascript复制const WebSocketServer = require('ws').Server;
wss = new WebSocketServer({port: 12122});
wss.on('connection', (ws) => {
// 有客户端连接时, 打印一条日志
console.log('client connected');
// 并且创建'message'监听
ws.on('message', (message) => {
// 直接将消息打印出来
console.log(message);
});
});