Hi,How are you doing?
我是职场编码(CodeVoc)。
在E000中,我们介绍了Node.js、Ruby、Electron等工具下载安装。
这期,给你演示一下由Electron联合Ruby制作的小工具。
借助Electron官方Demo,我们很容易制作一个工具展示平台。
点击“View Demo”会弹出我们的工具界面。
一、项目需求
这个工具的主要目的是为了把Ppt文本框文字提取写入Word。
它除了可以选择源文件,还可以选择目标文件。
点击“执行”按钮,就可以把Ppt文本框文字提取写入Word。
二、界面设计
【html】
生成表单容器:<form></form>
生成布局标签:<div></div>
生成行内标签:<span></span>
生成单行输入框:<input id="source_line"><input id="goal_line">
生成文件选择按钮:
<input type="file" id="goal_file">
<input type="file" id="source_file">
生成普通按钮:<input type="button" id="execute">
【css】
关注四点前白后绿气泡某杺平台,搜索“职场编码”查看源码。
【javascript】
根据ID,选中source_file按钮
var source_line=document.getElementById('source_line')
给source_file按钮,添加"change"事件
source_line.value=document.getElementById('source_file').files[0].path
根据ID,选中goal_file按钮,
var goal_line=document.getElementById('goal_line')
给goal_file按钮,添加"change"事件
goal_file.value=document.getElementById('goal_file').files[0].path
execute按钮添加单击事件
execute.addEventListener("click",function(){获取参数1,获取参数2,调用})
获取参数1
var source_line=document.getElementById('source_line').value
获取参数2
var goal_line=document.getElementById('goal_line').value
调用Ruby脚本
const { spawn } = require('child_process')
const ls = spawn('ruby', ['Ruby脚本完整路径',参数1,参数2])
三、逻辑梳理
=> 基础语法
引用Ruby标准库
require "win32ole"
创建双参数入口方法
def Ppt_to_word(pth_source,pth_goal)
接收控制台传双参
Ppt_to_word(ARGV[0],ARGV[1])
幻灯片计数、shapes计数
m=pst.slides.count
n=pst.slides(i).shapes.count
设置循环
(1..m).each{|i|
(1..n).each{|j|
}
}
=> 对象模型
创建可视化Word、Ppt应用
@wap=WIN32OLE::new("word.application");@wap.visible=true
@pap=WIN32OLE::new("powerpoint.application");@pap.visible=true
打开Word文档、Ppt演示文稿
wdc=@wap.documents.open(pth_goal)
pst=@pap.presentations.open(pth_source)
新增Word段落
wdc.paragraphs.add
执行Ppt文本框数据写入Word段落操作
wdc.paragraphs(s).range.text=pst.slides(i).shapes(j).textframe.textrange.text
关注四点前白后绿气泡某杺平台,搜索“职场编码”查看源码。