vbs修改office设置_E002 Ruby 写入数据 【 =gt; Office 】
生活随笔
收集整理的這篇文章主要介紹了
vbs修改office设置_E002 Ruby 写入数据 【 =gt; Office 】
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
上期,我們利用Electron&Ruby構(gòu)建一個(gè)簡單程序。(Electron簡稱“E”)以前,你可能沒接觸過,你想知道怎么從〇—>壹。
導(dǎo) 引
(一)下載node.js運(yùn)行時(shí)在此之前,你需要下載Node.js。就像你使用C#編程,你需要安裝.netframework一個(gè)道理。你需要到官網(wǎng)進(jìn)行下載安裝,這是啟動(dòng)E的關(guān)鍵。我推薦你安裝左邊這個(gè)穩(wěn)定版。安裝過程不用說了吧,一直點(diǎn)下一步直到安裝結(jié)束。徽標(biāo)+D,打開CMD命令提示符,輸入如下命令。#=>node?-v#=>npm?-v#=>只是習(xí)慣寫法,用于指示你輸入指令。顯示版本,則安裝成功。(二)配置初始化想要啟動(dòng)E,需要三個(gè)文件,即index.html,main.js,package.json。package.json里面是一些基本信息,main.js用于將index.html嵌入E。index.html就是我們看到的首頁。因?yàn)榘凑展倬W(wǎng)說明一步一步很費(fèi)事。我一般都是打開一個(gè)記事本,復(fù)制代碼配置模板完成初始化操作。1.package.json【必填】?"main": "main.js",【必填】"scripts": { "start": "electron ." },{ "name": "your-app", "version": "0.1.0", "main": "main.js", "scripts": { "start": "electron ." }, "devDependencies": { "electron": "^9.1.1" }, "dependencies": { "child_process": "^1.0.2" }}2.main.jsconst?{?app,?BrowserWindow?}?=?require('electron')function createWindow () { // 創(chuàng)建瀏覽器窗口 const win = new BrowserWindow({?? width:?1280,? ?height:?580,? ?resizable:?false,//不可更改登陸窗口尺寸??//?集成node環(huán)境(必選)??webPreferences:?{ nodeIntegration:?true??}}) win.loadFile('index.html') // 加載index.html}app.whenReady().then(createWindow)??????????//初始化上圖結(jié)構(gòu)是必填的,否則無法生成窗體。3.index.html<html> <head> <title> 公眾號 => 職場編碼 K31389title> head> <style type="text/css"> div{line-height: 555px} button{vertical-align: middle;width:180px;height:35px;opacity: 0}style> <body background="data/static/splash.gif"> <div > <center> <button id="popChildWindows" >彈出子窗口button> center> div> body> <script> var btnPopChiildWin=document.getElementById('popChildWindows') btnPopChiildWin.onclick = PopChiildWin function PopChiildWin(){ window.open('code/home.html','','width=1280,height=730') }script>html>首頁指定位置,設(shè)置一個(gè)按鈕。通過window.open()加載一個(gè)擁有部分權(quán)限窗口。4.安裝Electron依賴三文件準(zhǔn)備到位后,在當(dāng)前文件夾CMD運(yùn)行#=>npm install --save-dev electron運(yùn)行后出現(xiàn)node_modules,package-lock.json。5.設(shè)置一鍵啟動(dòng)因?yàn)槲淳幾g成EXE文件。我們每次都需要輸入CMD指令才能進(jìn)去。設(shè)置zero.bat批處理文件作為開啟窗口入口。@echo offcd %~dp0npm start獲取當(dāng)前目錄#=>cd %~dp0設(shè)置start.vbs隱藏CMD界面。Set ws = CreateObject("Wscript.Shell")ws.run "cmd /c zero.bat",vbhide這樣就完成了E的初始化。home.html界面改裝自官方DEMO。(三)文件分布結(jié)構(gòu)code_careers|--code? ? |--comprehensive????????|--Write_in_office????????????-002~Write_in_office.rb????????????◎Write_in_office.html????????????◎Write_in_office.js????? ? ●comprehensive.html? ? ☆home.html|--node_modules? ? ★main.js????★package.json????★index.html這個(gè)鏈接模式和數(shù)據(jù)庫差不多。主界面有2個(gè),index.html,home.html。內(nèi)容頁:comprehensive.html展示頁:Write_in_office.html一頁連著一頁,一個(gè)嵌著一個(gè)。package.json->main.js->index.html->home.html->comprehensive.html->Write_in_office.js->Write_in_office.html他們的鏈接格式只有在源代碼里才能看到。例如:package.json#=>?"main": "main.js"main.js#=>?win.loadFile('index.html')index.html#=>window.open('code/home.html')home.html#=>comprehensive.html#=>require('./comprehensive/Write_in_office/Write_in_office')Write_in_office.js#=>win.loadURL(path.join('file://', __dirname, 'Write_in_office.html'))由此可見,js負(fù)責(zé)生成界面,html負(fù)責(zé)展示,環(huán)環(huán)相扣,彼此連接。正 文
(一)界面設(shè)計(jì)1.html設(shè)置便于我們整體調(diào)節(jié)位置。設(shè)置接收輸入。設(shè)置選擇下拉選項(xiàng)。設(shè)置執(zhí)行按鈕。2.css通過.類名,標(biāo)簽名,#ID,選擇控件標(biāo)記相關(guān)屬性。3.javascript用自然語言描述:通過getElementById指定按鈕,設(shè)置點(diǎn)擊事件監(jiān)聽。主要獲取輸入?yún)?shù)值,如下拉列表選取值,文本框輸入值。通過require('child_process').spawn執(zhí)行Ruby帶參腳本。<html> <head> <title>002 Ruby 寫入數(shù)據(jù) 【 => Office 】title> head> <style type="text/css"> form{ position: relative; text-align: center; width: 580px; top:65px; height:200px; } #execute{ position:relative; left: -200px; margin-top: 30px; } textarea{ left:0px; margin:0px; width: 400px; height: 60px;??????} select{ position: absolute; top:0px; margin:0px;????????height:?60px; } .execute{ position: relative; left: -160px; top:60px; width:100px; height:30px; }style> <body> <form class="form base"> <textarea class="input_word"id="input_word">textarea> <select id="select_name"> <option value ="excel">exceloption> <option value ="word">wordoption> <option value="ppt">pptoption> select> <input type="button" class="execute" value="寫 入" id="execute"> form> <script type="text/javascript"> var execute=document.getElementById('execute') execute.addEventListener("click",function(){ var select_name=document.getElementById('select_name').value var input_word=document.getElementById('input_word').value const { spawn } = require('child_process'); const ls = spawn('ruby', ['./code/comprehensive/Write_in_office/002~Write_in_office.rb' ,select_name,input_word]); })script> body>html>(二)代碼展示通過Main(ARGV[0],ARGV[1])獲取控制臺(tái)輸入?yún)?shù)。接收參數(shù),傳入defMain(name,txt)方法,根據(jù)name不同,分別進(jìn)行判斷,接著傳入各自方法完成數(shù)據(jù)寫入操作。通過ebk=eap.workbooks.add新建工作簿,通過wdc=wap.documents.add新建文檔,通過pst=pap.presentations.add新建演示文稿,通過ebk.worksheets(1).cells(1,1).value=txt寫入excel,通過wdc.paragraphs(1).range.text=txt寫入word,通過psd.shapes(1).textframe.textrange.text=txt寫入ppt。注:新建演示文稿時(shí),需要通過psd=pst.slides.add(1,11)新建幻燈片。require?"win32ole"def New_excel(txt) eap=WIN32OLE::new("excel.application") eap.visible=true ebk=eap.workbooks.add ebk.worksheets(1).cells(1,1).value=txtenddef New_word(txt) wap=WIN32OLE::new("word.application") wap.visible=true wdc=wap.documents.add wdc.paragraphs(1).range.text=txtenddef New_ppt(txt) pap=WIN32OLE::new("powerpoint.application") pap.visible=true pst=pap.presentations.add psd=pst.slides.add(1,11) # ppLayoutTitleOnly psd.shapes(1).textframe.textrange.text=txtenddef Main(name,txt) case name when "excel" then New_excel(txt) when "word" then New_word(txt) when "ppt" then New_ppt(txt) endendMain(ARGV[0],ARGV[1])總結(jié)
以上是生活随笔為你收集整理的vbs修改office设置_E002 Ruby 写入数据 【 =gt; Office 】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中常见的运行时错误_17个常
- 下一篇: gson解析天气json_几种常用JSO