2/3 以改成 wscript.exe 來執行對程式按滑鼠右鍵選開起檔案, 選擇你要的軟體, 若沒有可以選擇 windows 安裝路徑下的 system32\wscript.exe 第一個範例 : excel 比較簡單, 我們先說明之 ' 第一個定意新的物件 com.sun.star.service

Similar documents
1 1 Excel VBA 說明 ( ) (_) STEP4 Excel 2 STEP5 A1 1 B2 2 C3 3 STEP6 A1 STEP7 > > 1-11

投影片 1

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

國小簡章 Final

Microsoft PowerPoint - VB14.ppt

Microsoft Word - 小心翼翼的二十一點N.doc

VB程序设计教程

27 :OPC 45 [4] (Automation Interface Standard), (Costom Interface Standard), OPC 2,,, VB Delphi OPC, OPC C++, OPC OPC OPC, [1] 1 OPC 1.1 OPC OPC(OLE f

一 专 业 名 称 专 业 名 称 : 会 计 二 入 学 要 求 与 基 本 学 制 入 学 要 求 : 初 中 毕 业 生 基 本 学 制 : 三 年 ; 其 中 前 二 年 为 在 校 学 习 时 间, 最 后 一 年 为 企 业 实 习 时 间 层 次 : 中 职 三 培 养 目 标 本 专

6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM

OpenOffice.org OpenOffice.org OpenOffice OpenOffice OOo OpenOffice.org 1. Writer MS Word.odt 2. Calc MS Excel.ods 3. Impress MS PowerPoint.odt 4. Base

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

生死之交

ThreeDtunnel.doc

Excel VBA Excel Visual Basic for Application

“国家高等职业教育会计专业

<4D F736F F D B77CC4B3ACF6BFFD2DB0D3B77EC2B2B3F8C2BEBAD82E646F63>

FY.DOC

ebook70-19

Sophos Central 快速安裝手冊

2

untitled

封面-12

Visual Basic D 3D

Microsoft PowerPoint - Lecture7II.ppt

第 2 页 计 算 中 心 工 作 简 报 主 要 作 用 是 屏 蔽 外 网 的 同 时 保 障 局 域 网 的 畅 通, 隔 离 考 试 用 机 与 非 考 试 用 机 的 通 讯, 保 障 考 试 环 境 的 安 全 为 保 证 计 算 机 等 级 考 试 时 音 频 装 置 的 正 常 使

新 闻 学 46 7 新 闻 传 播 学 院 广 告 学 28 4 广 播 电 视 学 23 3 新 闻 学 广 告 学 ). 级 学 生 申 请 准 入 需 修 完 或 正 在 修 2 门 专 业 准 入 课 程 并 取 得 相 应 学 分 ;2). 级 学 生 申 请 准 入 需

银川一职服装设计与工艺专业教学计划

chp6.ppt

輕鬆學 Dreamweaver CS5 網頁設計..\Example\Ch0\ \.html..\example\ch0\ \mouse.txt..\example\ch0\ \ _Ok.html 學習重點 JavaScript 複製程式碼 mouse.txt Ctrl+C Ctrl+C 0-4

( 二 ) 拓 展 岗 位 ( 群 ) 1. 餐 厅 服 务 岗 位 群 在 大 中 型 餐 饮 企 业 星 级 饭 店 主 要 从 事 餐 饮 服 务 的 有 关 工 作, 如 服 务 员 点 菜 师 茶 艺 师 咖 啡 师 调 酒 师 等 2. 食 品 加 工 岗 位 群 主 要 从 事 餐 饮

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

四川省普通高等学校

RUN_PC連載_10_.doc

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

untitled

Microsoft Word - 11.doc

第 一 节 认 识 自 我 的 意 义 一 个 人 只 有 认 识 自 我, 才 能 够 正 确 地 认 识 到 自 己 的 优 劣 势, 找 出 自 己 的 职 业 亮 点, 为 自 己 的 顺 利 求 职 推 波 助 澜 ; 一 个 人 只 有 认 识 自 我, 才 能 在 求 职 中 保 持

第一章

A 单 位 负 责 人 B 会 计 机 构 负 责 人 C 会 计 主 管 人 员 D 会 计 人 员 多 选 题 : 1. 单 位 伪 造 变 造 会 计 凭 证 会 计 账 簿, 编 制 虚 假 财 务 会 计 报 告 的, 县 级 以 上 人 民 政 府 财 政 部 可 以 依 法 行 使 的

记 忆 155 期 北 京 大 学 文 革 专 辑 (9) 目 录 专 稿 章 铎 从 高 云 鹏 的 遭 遇, 看 迟 群 之 流 的 专 制 附 : 高 云 鹏 给 胡 宗 式 章 铎 的 信 (2015 年 11 月 19 日 ) 评 论 马 云 龙 王 复 兴 抢 救 记 忆 : 一 个 北


标题

Microsoft Word - media-tips-zh.doc


p.2 1 <HTML> 2 3 <HEAD> 4 <TITLE> </TITLE> 5 </HEAD> 6 7 <BODY> 8 <H3><B> </B></H3> 9 <H4><I> </I></H4> 10 </BODY> </HTML> 1. HTML 1. 2.

contents 1 4 Chapter 2 Chapter 5 Chapter 管理自動儲存的版本 以文件復原窗格復原檔案 自訂快速工具 自訂快速存取工具列 自訂功能區

IP505SM_manual_cn.doc

Microsoft PowerPoint - OPVB1基本VB.ppt

ebook129-11

TwinCAT 1. TwinCAT TwinCAT PLC PLC IEC TwinCAT TwinCAT Masc

untitled

附录J:Eclipse教程

3 Driver do Microsoft Access (*.mdb) hisdata IFIX 1.4

C H A P T E R 7 Windows Vista Windows Vista Windows Vista FAT16 FAT32 NTFS NTFS New Technology File System NTFS

epub83-1

<4D F736F F D20B9D8D3DAD3A1B7A2A1B6D6D0B9FAC4DCD4B4BDA8C9E8BCAFCDC5D3D0CFDEB9ABCBBEC1AEBDE0B7E7CFD5B7C0BFD8B9DCC0EDCAB5CAA9B0ECB7A8A3A8CAD4D0D0A3A9A1B7B5C4CDA8D6AA2E646F63>

,,

Open topic Bellman-Ford算法与负环


7 8 9 因 應 最 近 地 震 頻 繁, 究 竟 於 不 同 地 震 規 模 發 生 時 是 否 均 要 進 行 就 地 掩 蔽 及 地 震 停 止 時 須 否 疏 散 至 室 外 空 曠 地, 應 將 正 確 作 法 告 知 所 有 師 生, 而 非 演 練 一 套, 真 正 地 震 時 卻

<4D F736F F D D342DA57CA7DEA447B14D2DA475B57BBB50BADEB27AC3FEB14DA447B8D5C344>

投影片 1


目 录 教 学 简 讯 快 报. 1 青 少 年 工 作 系..5 社 会 工 作 学 院...10 法 学 院.14 经 济 管 理 学 院 17 新 闻 与 传 播 系 19 公 共 管 理 系.21 中 国 语 言 文 学 系.25 外 国 语 言 文 学 系.28

李 老 他 自 己 却 老 是 自 称 科 员, 老 说 我 李 科 员 怎 样 怎 样, 倒 好 像 这 是 一 个 值 得 他 夸 耀 的 什 么 官 衔 一 样 他 是 我 们 这 个 衙 门 里 资 格 最 老 的 科 员, 他 自 己 却 说 是 这 个 衙 门 里 最 没 有 出 息 的

untitled

The golden pins of the PCI card can be oxidized after months or years

IsPostBack 2

2015年4月11日雅思阅读预测机经(新东方版)

教 务 信 息 教 学 日 常 运 行 工 作 4 月 6 日, 教 务 部 高 丽 琴 老 师 参 加 南 昌 市 教 育 局 2016 年 中 小 学 教 师 资 格 认 定 工 作 培 训 会 2016 年 教 师 资 格 认 定 工 作 是 从 省 考 向 国 考 过 渡 后 的 第 一 次

计算机网络与经济(二).doc

Microsoft PowerPoint ?????????3 [Compatibility Mode]

Transcription:

1/3 wscript(vbs) 控制 OpenOffice 建立日期 :2009/11/06 作者 :cschen33.tw@gmail.com 目前大部份的程式 (ERP) 會呼叫 office(word 或是 excel) 來產生要的報表, 因為免費軟體 OpenOffice 已經越來越穩定, 是不是也可以使用 OpenOffice 取代 Office 嗎? 目前在網路上找到一篇 http://wiki.services.openoffice.org/wiki/documentation/devguide/prouno/bridge/automation_bridge http://www.kalitech.fr/clients/doc/vb_apiooo_en.html 想要依樣畫葫蘆但是沒有 scalc, 後來也找到好幾篇, 但是根據文章來實作, 發現有很多問題都不可行, 因此自已錄製 OOo 的巨集, 並猜測試可行! 要求 支援的作業平台 (Windows 95, 98, NT4, ME, 2000, XP) 快速入門 1.calc Set osm =CreateObject("com.sun.star.ServiceManager") 'Set ocr = osm.createinstance("com.sun.star.reflection.corereflection") Set odesktop = osm.createinstance("com.sun.star.frame.desktop") Dim aargs() 2.writer Set odoc = odesktop.loadcomponentfromurl("private:factory/scalc","_blank",0,aargs) Set osheet = odoc.getsheets().getbyindex(0) Call osheet.getcellbyposition(0,0).setvalue(1000.32) Call osheet.getcellbyposition(0,1).setstring("abc") Dim osm Dim odesk Dim arg() 'Instanciate OOo : this line is mandatory with VB for OOo API Set osm = CreateObject("com.sun.star.ServiceManager") 'Create the first and most important service Set odesk = osm.createinstance("com.sun.star.frame.desktop") ' 建立一個新的文件 Set odoc = odesk.loadcomponentfromurl("private:factory/swriter", "_blank", 0, arg()) ' 關閉這個文件 ' 開啟一個已經存在的檔案 ( 請注意第一個參數 ) Set odoc = odesk.loadcomponentfromurl("file:///c:/dev/ooo/test.doc", "_blank", 0, arg()) ' 儲存檔案 Call odoc.storetourl("file:///c:/dev/ooo/test2.sxw", arg()) ' 關閉檔案 將上述兩檔存成副檔名 vbs, 就可以直接執行, 有人執行會出現 dos 的視窗, 是因為它是使用 cscript.exe 來執行, 你可

2/3 以改成 wscript.exe 來執行對程式按滑鼠右鍵選開起檔案, 選擇你要的軟體, 若沒有可以選擇 windows 安裝路徑下的 system32\wscript.exe 第一個範例 : excel 比較簡單, 我們先說明之 ' 第一個定意新的物件 com.sun.star.servicemanager Set osm = CreateObject("com.sun.star.ServiceManager") ' 建立一個實體 Set odesktop = osm.createinstance("com.sun.star.frame.desktop") ' 定義讀取參數, 我們不會變, 因此定義的空陣列, 一般寫入才會變 Dim aargs() ' 設定要開啟新的檔案 calc Set odoc = odesktop.loadcomponentfromurl("private:factory/scalc","_blank",0,aargs) ' 取得第一個空白頁 Set osheet = odoc.getsheets().getbyindex(0) ' 輸入值,SetValue 是設定數字,SetString 是設定文字 Call osheet.getcellbyposition(0,0).setvalue(1000.32) Call osheet.getcellbyposition(0,1).setstring("abc") 第二個範例 : ' 這裏有一個多了定義, 其實也可以不用定義, 在 wscript 不需要定義 as object 否則會有錯誤訊息產生 Dim osm 'Root object for accessing OpenOffice from VB Dim odesk, odoc As Object 'First objects from the API ' 定義讀取參數, 我們不會變更, 因此定義空陣列, 一般寫入才會變 Dim arg() ' 第一個定意新的物件 com.sun.star.servicemanager Set osm = CreateObject("com.sun.star.ServiceManager") ' 建立一個實體 Set odesk = osm.createinstance("com.sun.star.frame.desktop") ' 開啟一個新的文件 writer Set odoc = odesk.loadcomponentfromurl("private:factory/swriter", "_blank", 0, arg()) ' 關閉這個文件 ' 開啟一個已經存在的檔案 (pay attention to the syntax for first argument) Set odoc = odesk.loadcomponentfromurl("file:///c:/dev/ooo/test.doc", "_blank", 0, arg()) ' 儲存檔案, 因為我們沒有要變更模式因此不變更寫入參數 Call odoc.storetourl("file:///c:/dev/ooo/test2.sxw", arg()) ' 關閉檔案 ' 刪除物件 特殊函式在 OOo API 中有一些屬性的類型是 structure, 它是使用者自定的類型, 並無法直接存取, 要使用 Bridge_GetStruct 來取得屬性, 及指定屬性 ' ' 建立及設定 com.sun.star.beans.propertyvalue 屬性 ' Public Function MakePropertyValue(cName, uvalue) Dim ostruct, oservicemanager Set oservicemanager = CreateObject("com.sun.star.ServiceManager") Set ostruct = oservicemanager.bridge_getstruct("com.sun.star.beans.propertyvalue") ostruct.name = cname ostruct.value = uvalue ' 設定傳回值 Set MakePropertyValue = ostruct End Function

3/3 陣列 ' 定義, 是必須的,vbs 可以定義空的陣列, 但是 autoit3 不可以定義空的陣列 Dim stest(0) ' 指定 Set stest(0) = MakePropertyValue("ToPoint","$A$4") ' 引用 stest() #wscript 的定義陣列, 我試了好久, 找一下資料才找到 Dim abc(3) 可以存 4 個值 abc(0),abc(1),abc(2),abc(3) Dim abc(0) 可以存 1 個值 輸入值的方法 1. osheet.getcellbyposition(0,0).setvalue 1000.32 2. Call osheet.getcellbyposition(2,2).setvalue(1000.32) 3. Call osheet.getcellbyposition(1,1).setstring("abc") 4. osheet.getcellbyposition(1,1).setstring "abc" 5. osheet.getcellrangebyname("b1").value = 12 1 和 2 是相同的 3 和 4 是相同的 選取選取 B3 call odesktop.currentcomponent.currentcontroller.select(osheet.getcellrangebyname("b3")) 選取 B3:G5(B3 到 G5) call odesktop.currentcomponent.currentcontroller.select(osheet.getcellrangebyname("b3:g5")) ' 置中 Dim t3(0) set t3(0) = MakePropertyValue("HorizontalAlignment", 2) call dispatcher.executedispatch(document, ".uno:horizontalalignment", "", 0, t3) ' 原 OOo 巨集中的 com.sun.star.table.cellhorijustify.center 的值是無法直接取得, 因此使用數字來取代 '0 正常,1 靠左,2 置中,3 靠右 ' 移動 ' 移動到 a3:f17, 這是一個選取的空間 set t4(0) = MakePropertyValue("ToPoint","$A$3:$F$17") call dispatcher.executedispatch(document, ".uno:gotocell","",0,t4) ' 開啟檔案 ' 路徑 c:\tmp\sample.rtf 變更為 file:///c \tmp\sample.rtf, 其中 代表 : Set odoc = odesktop.loadcomponentfromurl("file:///c \tmp\sample.rtf","_blank",0,aargs) 附件共 3 件 1.scalc.vbs 2.swriter.vbs 3.autoit3.vbs

scalce.vbs 頁頁 :1/1 C:\Documents and Settings\cs_chen\ 桌頁 \svn\doc\openoffice\ 上上上上上上 : 2009/11/6 上上 08:55:22 1: ' 建立 com 2: Set osm = CreateObject("com.sun.star.ServiceManager") 3: ' 建立實體 4: Set odesktop = osm.createinstance("com.sun.star.frame.desktop") 5: ' 定義陣列,vbs 的陣列定義和一般不同 : 如 t1(0), 可以存 1 個 0->0 一個, 而 t1(1), 可以存 2 個 0->1 6: Dim aargs(),t1(0),t2(7),t3(0),t4(0),saveparam(0) 7: Set odoc = odesktop.loadcomponentfromurl("private:factory/scalc","_blank",0,aargs) 8: Set osheet = odoc.getsheets().getbyindex(0) 9: Set document = odesktop.currentcomponent.currentcontroller.frame 10: Set dispatcher = osm.createinstance("com.sun.star.frame.dispatchhelper") 11: 12: ' 輸入數字 13: osheet.getcellbyposition(0,0).setvalue 1 14: Call osheet.getcellbyposition(0,1).setvalue(2) 15: osheet.getcellrangebyname("a3").value = 3 16: osheet.getcellrangebyname("a4").setvalue 4 17: 18: ' 輸入字串 19: osheet.getcellbyposition(1,0).setstring "a" 20: Call osheet.getcellbyposition(1,1).setstring("b") 21: 22: ' 讀取值 23: ocell = osheet.getcellrangebyname("b3").value 24: MsgBox ocell 25: 26: ' 選取欄位並輸入文字 27: osheet.getcellrangebyname("d8").setstring( " 中文字測試 ") 28: 29: ' 設字型大小 30: call odesktop.currentcomponent.currentcontroller.select(osheet.getcellrangebyname("b3:g5")) 31: set t1(0) = MakePropertyValue("FontHeight.Height",14) 32: call dispatcher.executedispatch( document, ".uno:fontheight","", 0, t1) 33: 34: ' 設定邊界 35: set t2(0) = MakePropertyValue("OuterBorder.LeftBorder",Array(0,0,2,0)) 36: set t2(1) = MakePropertyValue("OuterBorder.LeftDistance",0) 37: set t2(2) = MakePropertyValue("OuterBorder.RightBorder",Array(0,0,2,0)) 38: set t2(3) = MakePropertyValue("OuterBorder.RightDistance",0) 39: set t2(4) = MakePropertyValue("OuterBorder.TopBorder",Array(0,0,2,0)) 40: set t2(5) = MakePropertyValue("OuterBorder.TopDistance",0) 41: set t2(6) = MakePropertyValue("OuterBorder.BottomBorder",Array(0,0,2,0)) 42: set t2(7) = MakePropertyValue("OuterBorder.BottomDistance",0) 43: call dispatcher.executedispatch( document, ".uno:setborderstyle","", 0, t2) 44: 45: ' 移動 46: set t4(0) = MakePropertyValue("ToPoint","$A$3:$F$17") 47: call dispatcher.executedispatch(document, ".uno:gotocell","",0,t4) 48: 49: ' 置中 50: 'com.sun.star.table.cellhorijustify.center 的值是無法直接取得, 因此使用數字來取代 51: '0 正常,1 靠左,2 置中,3 靠右 52: set t3(0) = MakePropertyValue("HorizontalAlignment", 2) 53: call dispatcher.executedispatch(document, ".uno:horizontalalignment", "", 0, t3) 54: 55: 56: ' 存成 PDF 57: Set SaveParam(0) = MakePropertyValue("FilterName", "writer_pdf_export") 58: Call odoc.storetourl("file:///c:/tmp/testdoc.pdf", SaveParam) 59: 60: Function MakePropertyValue(cName, uvalue) 61: Dim opropertyvalue 62: Dim osm 63: Set osm = CreateObject("com.sun.star.ServiceManager") 64: Set opropertyvalue = osm.bridge_getstruct("com.sun.star.beans.propertyvalue") 65: opropertyvalue.name = cname 66: opropertyvalue.value = uvalue 67: Set MakePropertyValue = opropertyvalue 68: 69: End Function 70: 71: PSPad editor 4.5.4 (2356) www.pspad.com 2009/11/6 下上 12:44:44 cs_chen

writer.vbs 頁頁 :1/2 C:\Documents and Settings\cs_chen\ 桌頁 \svn\doc\openoffice\ 上上上上上上 : 2009/11/4 下下 05:24:10 1: 'VBScript 範例 2: 'The service manager is always the starting point 3: ' 定義 service manager 4: Set objservicemanager= WScript.CreateObject("com.sun.star.ServiceManager") 5: 6: ' 建立實體 7: Set objcorereflection= objservicemanager.createinstance("com.sun.star.reflection.corereflection") 8: 9: ' 建立在桌面 10: Set objdesktop= objservicemanager.createinstance("com.sun.star.frame.desktop") 11: 12: ' 開啟新的文件 13: Dim args() 14: Set objdocument= objdesktop.loadcomponentfromurl("private:factory/swriter", "_blank", 0, args) 15: 16: ' 定義文字物件 17: Set objtext= objdocument.gettext 18: 19: ' 建立一個暫時的物件 20: Set objcursor= objtext.createtextcursor 21: 22: ' 插入一些文字 23: objtext.insertstring objcursor, " 第一行在新建的文件中." & vblf, false 24: 25: ' 再插入第二行 26: objtext.insertstring objcursor, "Now we're in the second line", false 27: 28: ' 建立一個文字表格 4*4 29: Set objtable= objdocument.createinstance( "com.sun.star.text.texttable") 30: objtable.initialize 4, 4 31: 32: ' 插入表格 33: objtext.inserttextcontent objcursor, objtable, false 34: 35: ' 取得一列 36: Set objrows= objtable.getrows 37: Set objrow= objrows.getbyindex( 0) 38: 39: ' 設定表格的背景顏色 40: objtable.setpropertyvalue "BackTransparent", false 41: objtable.setpropertyvalue "BackColor", 13421823 42: 43: ' 設定第一列使用不同的背景顏色 44: objrow.setpropertyvalue "BackTransparent", false 45: objrow.setpropertyvalue "BackColor", 6710932 46: 47: ' 填入表格第一列 48: insertintocell "A1","FirstColumn", objtable 49: 'insertintocell is a helper function, see below 50: insertintocell "B1","SecondColumn", objtable 51: insertintocell "C1","ThirdColumn", objtable 52: insertintocell "D1","SUM", objtable 53: 54: objtable.getcellbyname("a2").setvalue 22.5 55: objtable.getcellbyname("b2").setvalue 5615.3 56: objtable.getcellbyname("c2").setvalue -2315.7 57: objtable.getcellbyname("d2").setformula"sum " 58: 59: objtable.getcellbyname("a3").setvalue 21.5 60: objtable.getcellbyname("b3").setvalue 615.3 61: objtable.getcellbyname("c3").setvalue -315.7 62: objtable.getcellbyname("d3").setformula "sum " 63: 64: objtable.getcellbyname("a4").setvalue 121.5 65: objtable.getcellbyname("b4").setvalue -615.3 66: objtable.getcellbyname("c4").setvalue 415.7 67: objtable.getcellbyname("d4").setformula "sum " 68: 69: 'Change the CharColor and add a Shadow 70: objcursor.setpropertyvalue "CharColor", 255 71: objcursor.setpropertyvalue "CharShadowed", true 72: 73: 'Create a paragraph break PSPad editor 4.5.4 (2356) www.pspad.com 2009/11/6 下下 12:46:23 cs_chen

writer.vbs 頁頁 :2/2 C:\Documents and Settings\cs_chen\ 桌頁 \svn\doc\openoffice\ 上上上上上上 : 2009/11/4 下下 05:24:10 74: 'The second argument is a com::sun::star::text::controlcharacter::paragraph_break constant 75: objtext.insertcontrolcharacter objcursor, 0, false 76: 77: 'Inserting colored Text. 78: objtext.insertstring objcursor, " This is a colored Text - blue with shadow" & vblf, false 79: 80: 'Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK). 81: objtext.insertcontrolcharacter objcursor, 0, false 82: 83: 'Create a TextFrame. 84: Set objtextframe= objdocument.createinstance("com.sun.star.text.textframe") 85: 86: 'Create a Size struct. 87: Set objsize= createstruct("com.sun.star.awt.size") 88: 'helper function, see below 89: objsize.width= 15000 90: objsize.height= 400 91: objtextframe.setsize( objsize) 92: 93: ' TextContentAnchorType.AS_CHARACTER = 1 94: objtextframe.setpropertyvalue "AnchorType", 1 95: 96: 'insert the frame 97: objtext.inserttextcontent objcursor, objtextframe, false 98: 99: 'Get the text object of the frame 100: Set objframetext= objtextframe.gettext 101: 102: 'Create a cursor object 103: Set objframetextcursor= objframetext.createtextcursor 104: 105: 'Inserting some Text 106: objframetext.insertstring objframetextcursor, "The first line in the newly created text frame.", _ 107: false 108: objframetext.insertstring objframetextcursor, _ 109: vblf & "With this second line the height of the frame raises.", false 110: 111: 'Create a paragraph break 112: 'The second argument is a com::sun::star::text::controlcharacter::paragraph_break constant 113: objframetext.insertcontrolcharacter objcursor, 0, false 114: 115: 'Change the CharColor and add a Shadow 116: objcursor.setpropertyvalue "CharColor", 65536 117: objcursor.setpropertyvalue "CharShadowed", false 118: 119: 'Insert another string 120: objtext.insertstring objcursor, " That's all for now!!", false 121: 122: On Error Resume Next 123: If Err Then 124: MsgBox "An error occurred" 125: End If 126: 127: 128: Sub insertintocell( strcellname, strtext, objtable) 129: Set objcelltext= objtable.getcellbyname( strcellname) 130: Set objcellcursor= objcelltext.createtextcursor 131: objcellcursor.setpropertyvalue "CharColor",16777215 132: objcelltext.insertstring objcellcursor, strtext, false 133: End Sub 134: 135: Function createstruct( strtypename) 136: Set classsize= objcorereflection.forname( strtypename) 137: Dim astruct 138: classsize.createobject astruct 139: Set createstruct= astruct 140: End Function 141: 142: PSPad editor 4.5.4 (2356) www.pspad.com 2009/11/6 下下 12:46:23 cs_chen

autoit3.au3 C:\Documents and Settings\cs_chen\ 桌頁 \svn\doc\openoffice\ 1: #include <Array.au3> 2: Global $setoooprop 3: $osm=objcreate("com.sun.star.servicemanager") 4: if IsObj($oSM) Then 5: $odesktop = $osm.createinstance("com.sun.star.frame.desktop") 6: 7: If IsObj($oDesktop) Then 8: Dim $aargs[1] 9: Dim $t1[1] 10: Dim $t2[1] 11: $aargs[0] = setprop("readonly",false) 12: ;$aargs[1] = setprop("password","secret") 13: ;$aargs[2] = setprop("hidden",false) 14: $odoc = $odesktop.loadcomponentfromurl("private:factory/scalc","_blank",0,$aargs) 15: $document = $odesktop.currentcomponent.currentcontroller.frame 16: $dispatcher = $osm.createinstance("com.sun.star.frame.dispatchhelper") 17: If IsObj($oDoc) Then 18: $osheet = $odoc.getsheets().getbyindex(0) 19: $osheet.getcellbyposition(5,5).setstring( " 中文字測試 ") 20: $odesktop.currentcomponent.currentcontroller.select select($osheet.getcellbyposition(5,5)) 21: $t2[0] = setprop("fontheight.height",14) 22: $dispatcher.executedispatch($document,".uno:fontheight","",0,$t2) 23: $t1[0] = setprop("topoint","a3:f17") 24: $dispatcher.executedispatch($document,".uno:gotocell","",0,$t1) 25: Else 26: MsgBox(0,"oDoc","not object") 27: EndIf 28: Else 29: MsgBox(0,"oDesktop","not object") 30: EndIf 31: Else 32: MsgBox(0,"oExcel","not object") 33: EndIf 34: 35: Func setprop($cname, $uvalue) 36: $osm = ObjCreate("com.sun.star.ServiceManager") 37: $opropertyvalue = $osm.bridge_getstruct("com.sun.star.beans.propertyvalue") 38: $opropertyvalue.name = $cname 39: $opropertyvalue.value = $uvalue 40: $setoooprop = $opropertyvalue 41: Return $setoooprop 42: EndFunc 43: 頁頁 :1/1 上上上上上上 : 2009/11/6 上上 08:47:14 PSPad editor 4.5.4 (2356) www.pspad.com 2009/11/6 下上 12:45:48 cs_chen