写入word_E014 如何把Ppt文本框文字提取写入Word

22b1e4dc46e8952554b37edf46c5ea16.png

f7eae58bdb1f5ba8124e552e7dcae583.png

Hi,How are you doing?

我是职场编码(CodeVoc)。

在E000中,我们介绍了Node.js、Ruby、Electron等工具下载安装。

这期,给你演示一下由Electron联合Ruby制作的小工具。

知乎视频​www.zhihu.com

借助Electron官方Demo,我们很容易制作一个工具展示平台。

3cd387aed19ef547754fd00ccc089ce4.png

点击“View Demo”会弹出我们的工具界面。

99c74b2db59efc4c526447d4348f0139.png

一、项目需求

这个工具的主要目的是为了把Ppt文本框文字提取写入Word。

它除了可以选择源文件,还可以选择目标文件。

点击“执行”按钮,就可以把Ppt文本框文字提取写入Word。

b2a84ebf9e89ab459c678efab00f1120.png

二、界面设计

【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

关注四点前白后绿气泡某杺平台,搜索“职场编码”查看源码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值