E013 如何把Excel表格數據寫入Ppt文本框內

E013 如何把Excel表格數據寫入Ppt文本框內

Hi,How are you doing?

我是職場編碼(CodeVoc)。

在E000中,我們介紹了Node.js、Ruby、Electron等工具下載安裝。

這期,給你演示一下由Electron聯合Ruby製作的小工具。

播放

暫停

進入全屏

退出全屏

00:00

00:00

重播

刷新

試試

藉助Electron官方Demo,我們很容易製作一個工具展示平臺。

E013 如何把Excel表格數據寫入Ppt文本框內

點擊“View Demo”會彈出我們的工具界面。

E013 如何把Excel表格數據寫入Ppt文本框內

一、項目需求

這個工具的主要目的是為了把Excel表格數據寫入Ppt文本框內。

它除了可以選擇源文件,還可以選擇目標文件。

點擊“寫入”按鈕,就完成了Excel表格數據寫入Ppt文本框操作。

E013 如何把Excel表格數據寫入Ppt文本框內

二、界面設計

【html】

生成表單容器:

生成佈局標籤:

生成行內標籤:

生成單行輸入框:

生成文件選擇按鈕:

<code> 
<

input

type

=

"file"

id=

"goal_file"

> <

input

type

=

"file"

id=

"source_file"

> /<code>

生成普通按鈕:

【css】

關注四點前白後綠氣泡某詞平臺,搜索“職場編碼”查看源碼。

【javascript】

根據ID,選中source_file按鈕

<code>

var

source_line=

document

.getElementById(

'source_line'

) /<code>

給source_file按鈕,添加"change"事件

<code>

source_line.value

=document.getElementById(

'source_file'

).files[

0

].path /<code>

根據ID,選中goal_file按鈕,

<code>

var

goal_line=

document

.getElementById(

'goal_line'

) /<code>

給goal_file按鈕,添加"change"事件

<code>

goal_file.value

=document.getElementById(

'goal_file'

).files[

0

].path /<code>

execute按鈕添加單擊事件

<code>

execute

.addEventListener(

"click"

,

function

()

{獲取參數

1

,獲取參數

2

,調用}) /<code>

獲取參數1

<code>

var

source_line=document.getElementById(

'source_line'

).

value

/<code>

獲取參數2

<code>

var

goal_line=document.getElementById(

'goal_line'

).

value

/<code>

調用Ruby腳本

<code>

const

{ spawn } =

require

(

'child_process'

)

const

ls = spawn(

'ruby'

, [

'Ruby腳本完整路徑'

,參數

1

,參數

2

]) /<code>

三、邏輯梳理

=> 基礎語法

引用Ruby標準庫

<code>

require

"win32ole"

/<code>

創建雙參數入口方法

<code>

def

Excel_to_ppt

(pth_source,pth_goal)

/<code>

接收控制檯傳雙參

<code>

Excel_to_ppt

(

ARGV

[0]

,

ARGV

[1]

)/<code>

幻燈片計數、創建數組

<code>

n

=pst.slides.count

arr

=Array

arr

=ebk.worksheets(

1

).usedrange.value/<code>

設置循環

<code>

123

.times{ } (

1

..n/

2

).each{

|i|

}/<code>

=> 對象模型

創建可視化Excel、Ppt應用

<code>

@eap

=

WIN32OLE

::new(

"excel.application"

);

@eap

.visible=true

@pap

=

WIN32OLE

::new(

"powerpoint.application"

);

@pap

.visible=true/<code>

打開Excel工作簿、Ppt演示文稿

<code>

ebk

[email protected](pth_source)

pst

[email protected](pth_goal)/<code>

操作slides對象

<code>

pst

.slides

(2)

.copy

pst

.slides

.paste

3

pst

.slides

(1)

.copy

pst

.slides

.paste

3/<code>

執行數組寫入Ppt文本框操作(格式化:format("%1d",數據))

<code>pst.slides(j).shapes(1).textframe.textrange.text=format("%1d",arr[

i

][

0

])+"."+arr[

i

][

2

] pst.slides(j+1).shapes(1).textframe.textrange.text=arr[

i

][

3

]/<code>

關注四點前白後綠氣泡某詞平臺,搜索“職場編碼”查看源碼。


分享到:


相關文章: