博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
luacom cygwin
阅读量:4633 次
发布时间:2019-06-09

本文共 1144 字,大约阅读时间需要 3 分钟。

前一段时间想用luacom来操作word文档,最终发现总有 。这两天用cygwin写bash脚本来完成一些Word文档操作,不得已总要调用cscript,通过javascript来访问wordr com对象,而这样调用cscript有两个问题让我很不爽:
  1. cscript又只接受Windows格式的路径,每次都要用 $(cygpath -w xxx) 来转换路径
  2. cscript输出或错误都是gb2312的,每次都要转换成utf-8:cscipt //nologo xxxxx.js 2>&1 | piconv -f gb2312 -t utf-8

Cygwin如何直接访问com对象呢?

cygwin有lua,而lua有luacom,这个能用吗?我刚才试了一下,基本功能貌似没有什么问题。因为cygwin本身就已经将文件名转换成了utf-8的,所有之前纠结于gb2312和utf-8的转换问题也就不是问题了。

编译安装luacom

cygwin需要安装 cmake make gcc g++ git lua,其他基础的当然也要

  • git clone https://github.com/davidm/luacom.git
  • cd luacom
  • mkdir build
  • cmake ..
  • make
  • make install

测试FileSystemObject的枚举中文文件夹功能

#!/usr/bin/luarequire "luacom"local fso = luacom.CreateObject("Scripting.FileSystemObject")local myFolder = fso:GetFolder("F:")for _,file in luacom.pairs(myFolder.SubFolders) do  print(file.Name)end

注:我的F:盘有很我中文文件夹,测试结果正确

测试Word文档建立和保存

#!/usr/bin/luarequire "luacom"wordApp = luacom.CreateObject("Word.Application")wordApp.Visible = truewordDoc = wordApp.Documents:Add()wordApp.Selection:TypeText("中文真的可以吗,我也不知道啊!")wordDoc:SaveAs2("F:\\中文的文件名哦还挺长的.docx")wordDoc:Close(0)wordApp:Quit(0)

转载于:https://www.cnblogs.com/windtail/archive/2012/07/01/2623173.html

你可能感兴趣的文章
读《大道至简》第六章感想
查看>>
ef linq 中判断实体中是否包含某集合
查看>>
金蝶K/3 BOS产品培训教案
查看>>
章三 链表
查看>>
react组件回顶部
查看>>
MyBatis if标签的用法
查看>>
VMware
查看>>
具体解释可变參数列表
查看>>
【LeetCode】Palindrome Partitioning 解题报告
查看>>
用vue-cli脚手架搭建一个仿网易云音乐的全家桶vue项目
查看>>
Solution for Concurrent number of AOS' for this application exceeds the licensed number
查看>>
从壹开始微服务 [ DDD ] 之一 ║ D3模式设计初探 与 我的计划书
查看>>
python 错误之SyntaxError: Missing parentheses in call to 'print'
查看>>
Windows Phone开发(16):样式和控件模板
查看>>
CSE 3100 Systems Programming
查看>>
洛谷 1604——B进制星球(高精度算法)
查看>>
IntelliJ IDEA 的Project structure说明
查看>>
处理 JSON null 和空数组及对象
查看>>
Java Security(JCE基本概念)
查看>>
服务注册发现consul之四: 分布式锁之四:基于Consul的KV存储和分布式信号量实现分布式锁...
查看>>