当前位置: 首页 > news >正文

临沂医院网站建设国税网站建设现状

临沂医院网站建设,国税网站建设现状,企业网站注册域名的步骤,乐清网站制作libreOffice API是用于访问libreOffice的编程接口。可以使用libreOffice API创建、打开、修改和打印libreOffice文档。 LibreOffice API支持Basic、Java、C/C、Javascript、Python语言。 这是通过一种称为通用网络对象 (Universal Network Objects, UNO) 的技术实现的#xff…libreOffice API是用于访问libreOffice的编程接口。可以使用libreOffice API创建、打开、修改和打印libreOffice文档。 LibreOffice API支持Basic、Java、C/C、Javascript、Python语言。 这是通过一种称为通用网络对象 (Universal Network Objects, UNO) 的技术实现的该技术可以为各种编程语言提供接口。 https://api.libreoffice.org/docs/idl/ref/index.html 一、uno概念 一类型 uno类型使用一种称为UNOIDLUNO接口定义语言的语言定义这种语言与CORBA IDL或MIDL类似。 1.简单类型   UNO类型说明void空类型仅在any中用作方法返回类型。boolean可以是true或false。byte有符号的8位整数类型范围从 -128到127包括上下限。short有符号的16位整数类型范围从 -32768到32767包括上下限。unsigned short无符号的16位整数类型已不再使用。long有符号的32位整数类型范围从 -2147483648到2147483647包括上下限。unsigned long无符号的32位整数类型已不再使用。hyper有符号的64位整数类型范围从 -9223372036854775808到9223372036854775807包括上下限。unsigned hyper无符号的64位整数类型已不再使用。floatIEC 60559单精度浮点类型。doubleIEC 60559双精度浮点类型。char表示单个的Unicode字符更确切地说是单个的UTF-16代码单元。string表示Unicode字符串更确切地说是Unicode标量值的字符串。type说明所有UNO类型的元类型。any能够表示其他所有类型值的特殊类型。 2.struct 类型 结构体包括一堆数据成员但不能包括方法。 结构体支持单继承。 struct EventObject{ com::sun::star::uno::XInterface Source; }; struct PropertyChangeEvent : com::sun::star::lang::EventObject { string PropertyName; boolean Further; long PropertyHandle; any OldValue; any NewValue; }; 3.sequence 序列就是一个动态数组。就像c的vector sequence com::sun::star::uno::XInterface sequence string getNamesOfIndex( sequence long indexes ); 4.interface类型 接口就是个抽象类。接口是一系列方法的声明一个接口只有方法的声明没有方法的实现因此这些方法可以在不同的类实现而这些实现可以是不同的行为。 严格说来UNO服务不支持方法方法只在接口中而服务继承了接口。 因为不同的服务会继承相同接口所以如果您熟悉某个接口便可以迅速了解不同服务。 按照约定所有接口名称都以字母X开头以将接口类型与其他类型区分开来。所有接口类型最终都必须继承com.sun.star.uno.XInterface根接口 interface XInterface { any queryInterface( [in] type aType ); [oneway] void acquire(); [oneway] void release();   };   interface XInputStream: com::sun::star::uno::XInterface { long readBytes( [out] sequencebyte aData, [in] long nBytesToRead ) raises( com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException); ... }; 方法 就是接口的成员函数 Document.Save() 5.service 接口定义了方法结构定义了数据服务将它们组合在一起。 服务相当于类不知道为啥非得叫服务。 通过服务可以创建对象实例。 com.sun.star.frame.Desktop类似于一种对象类型但在UNO术语中将其称为“服务”而不是“类型”。按照UNO术语Obj是支持com.sun.star.frame.Desktop服务的对象。因此libreOffice Basic中使用的“服务”术语与其他编程语言中使用的“类型”和“类”术语相对应。 但存在一个主要区别uno可以同时支持多种服务。例如上面提到的obj对象不仅支持com.sun.star.frame.Desktop服务还可以包括用于加载文档和结束程序的其他服务。 服务包括新式服务和旧式服务。 新式服务是通过仅支持一个多继承接口该多继承接口再继承其他接口实现的 旧式服务是直接支持多个单继承接口实现的 新式服务 service SomeService: XSomeInterface; interface XSomeInterface {      interface XInterface1;      interface XInterface2;      interface XInterface3;     ... }; 旧式服务 service SomeService{      interface XInterface1;      interface XInterface2;      interface XInterface3;     ... }; 旧式服务可以包括其他旧式服务。如下例 service Paragraph { service com::sun::star::text::TextContent; [optional] service com::sun::star::text::TextTable; [optional] service com::sun::star::style::ParagraphProperties; [optional] service com::sun::star::style::CharacterProperties; [optional] service com::sun::star::style::CharacterPropertiesAsian; [optional] service com::sun::star::style::CharacterPropertiesComplex; ... }; 如果上面示例中的所有旧式服务都使用多继承接口类型代替则结构类似 service Paragraph: XParagraph; interface XParagraph {      interface XTextContent;      [optional] interface XTextTable;      ... }; 从用户的角度来看无论对象提供一项服务或者多项服务是新式还是旧式服务由于方法仅由接口提供因此用户无需关心如何实现。 属性 属性是服务中的数据 1真实属性 就是服务的数据成员 Document.Title Basic Programmers Guide Document.Filename basguide.odt 2模拟属性 模拟属性就是通过get和set方法模拟的。 所以其实有两种方式访问属性 通过Position属性直接访问。 通过getPosition和setPosition间接访问 旧式服务可直接列出支持的属性。 下面的旧式服务引用了一个接口和三个可选属性。属性可以是任何类型 service TextContent{ interface com::sun::star::text::XTextContent; [optional, property] com::sun::star::text::TextContentAnchorType AnchorType; [optional, readonly, property] sequencecom::sun::star::text::TextContentAnchorType AnchorTypes; [optional, property] com::sun::star::text::WrapTextMode TextWrap; }; 6.预定义值 预定义值有两种不同的数据类型常数和枚举。 const const 定义有效UNO IDL类型的命名值。值取决于指定的类型可以是常值整数、浮点数或字符、另一个const类型的标识符或包含以下运算符的算术项、-、*、/、~、、|、%、^、 、。 由于可以在 const 中广泛选择类型和值因此const 有时用于生成对合并的值进行编码的位矢量。 const short ID 23; const boolean ERROR true; const double PI 3.1415; 通常情况下const定义是常数组的一部分。 constants constants 类型定义的是包含多个 const 值的一个命名组。constants 组中的 const 用组名称加上 const 名称表示。在下面的UNO IDL示例中ImageAlign.RIGHT 指的是值2 constants ImageAlign { const short LEFT 0; const short TOP 1; const short RIGHT 2; const short BOTTOM 3; }; enum enum 类型与C 中的枚举类型相当。它包含一个已排序列表列表中有一个或多个标识符代表 enum 类型的各个值。默认情况下值按顺序编号以0开头每增加一个新值就增加1。如果给某个 enum 值指定了一个值则没有预定义值的所有后续 enum 值都以此指定值为基准来获得值。 // com.sun.star.uno.TypeClass enum TypeClass { VOID, CHAR, BOOLEAN, BYTE, SHORT, ... };   enum Error { SYSTEM 10, // value 10 RUNTIME, // value 11 FATAL, // value 12 USER 30, // value 30 SOFT // value 31 }; 7.module 模块是命名空间与C 中的命名空间或Java中的包类似 模块将服务、接口等类型组合在一起。形成良好的组织结构。 所以完整的类型名称由以下部分组成com.sun.star是共同的模块名称然后是特定模块名称最后是实际的类型名称。 例如服务Desktop的完整名称为com.sun.star.frame.Desktop 接口XTextContent的完整名称为com.sun.star.text.XTextContent 模块 com.sun.star.uno 包含接口 XInterfaceIDL写法如下 module com {module sun {module star {module uno { interface XInterface { ... };};};};}; 二对象 广义的对象就是各种类型的实例。 狭义的对象只是服务的实例。 二、libreoffice basic语言绑定 语言绑定就是如何使用某种语言调用uno。 语言绑定有时称为UNO运行时环境 ( URE)。 uno支持c、java、python、libreoffice basic语言绑定。 我们现在使用libreoffice basic语言所以下面要讲解libreoffice basic绑定。 主要是下面这些   BasicLibrariesccess Basic libraries stored in a document.CreateObject(obj_type)  Able to create any standard type, more flexible than CreateUnoStruct and CreateUnoService.CreateUnoDialog()Create an existing dialog.CreateUnoListener()Create a listener.CreateUnoService()Create a Universal Network Object Service.CreateUnoStruct()Create a Universal Network Object Structure.CreateUnoValue()Create a Universal Network Object value.DialogLibrariesAccess dialog libraries stored in a document.EqualUNOObjects()Determine if two UNO objects reference the same instance.FindObject()Find a named object; do not use.FindPropertyObject()Find object property based on name; do not use.GetDefaultContext()Get a copy of the default context.GetProcessServiceManager()Get service manager.GlobalScopeApplication-level libraries.HasUnoInterfaces()Does an object support specified interfaces?IsUnoStruct()Is this variable a Universal Network Object?StarDesktop  Special variable representing the desktop object.ThisComponentSpecial variable representing the current document. 一类型 Basic和UNO使用不同的类型系统有必要映射这两种类型系统。 下面讲basic定义和使用各种类型变量 1简单类型 UNOBasicvoid内部类型booleanBooleanbyteIntegershortIntegerunsigned short内部类型longLongunsigned long内部类型hyper内部类型unsigned hyper内部类型floatSingledoubleDoublechar内部类型stringStringtypecom.sun.star.reflection.XIdlClassanyVariant Basic类型系统并不严格。与C 和Java不同Basic不要求声明变量未声明的变量为Variant。 在未指定类型的情况下声明的所有变量都为 Variant 类型。可以将任意Basic类型的值指定给类型为 Variant 的变量。 为了方便尽量使用Variant类型而且不必声明变量。 因为Basic会自动转换到uno类型。 当Basic不知道目标uno类型时尤其是类型为any时。在这种情况下Basic会机械地将Basic类型转换成上表中所示的UNO类型。Basic提供的唯一机制是自动向下转换数值 Long和Integer值通常转换为尽可能短的整数类型 如果 -128 Value 127 转换为byte如果 -32768 Value 32767 转换为short 如果Single/Double值不带小数位则以同样的方式转换为整数。 2结构 可以通过Dim As New创建结构实例   Instantiate a Property struct Dim aProperty As New com.sun.star.beans.Property Instantiate an array of Locale structs Dim Locales(10) As New com.sun.star.lang.Locale 也可以使用CreateUnoStruct函数创建UNO结构实例 Dim aProp aProp CreateUnoStruct(com.sun.star.beans.PropertyValue) aProp.Name FirstName Set the Name property aProp.Value Andrew Set the Value property 函数CreateUnoStruct过去是创建UNO结构的唯一方法。自从引入“Dim As New”语法它很少使用了。 CreateObject函数比CreateUnoStruct更通用。它能够创建所有类型的实例。这包括用户定义的类型。 Dim aProp aProp CreateObject(com.sun.star.beans.PropertyValue) aProp.Name FirstName Set the Name property aProp.Value Paterton Set the Value property 创建用户定义类型实例 Type PersonType FirstName As String LastName As String End Type Sub ExampleCreateNewType Dim Person As PersonType Person.FirstName Andrew Person.LastName Pitonyak PrintPerson(Person) Dim Me As Object Me CreateObject(PersonType) Me.FirstName Andy Me.LastName Pitonyak PrintPerson(Me) End Sub Sub PrintPerson(x) Print Person x.FirstName x.LastName End Sub 对于用户定义的类型“Dim As New”和“Dim As”都可以使用。但是对于UNO结构 你必须使用Dim As New CreateObject与CreateUnoStruct有相同的参数但它适用于所有支持的类型 而CreateUnoStruct仅适用于UNO结构。所以尽量使用CreateObject。 可以使用 . 运算符访问结构成员。 结构支持Dbg_Properties属性。不支持属性Dbg_SupportedInterfaces和Dbg_Methods Instantiate a Locale struct Dim aLocale As New com.sun.star.lang.Locale Display properties MsgBox aLocale.Dbg_Properties Access“Language”property aLocale.Language en 服务实例与结构实例不同。服务实例使用引用传递而结构实例使用值传递。 在以下示例中oExample是一个服务实例具有属性MyObject和MyStruct。 MyObject是个服务有一个属性ObjectName。MyStruct是个结构有一个属性StructName。 oExample.MyObject.ObjectName和oExample.MyStruct.StructName都应该修改。 Accessing the object Dim oObject oObject oExample.MyObject oObject.ObjectName “Tim” Ok! or shorter oExample.MyObject.ObjectName “Tim” Ok! Accessing the struct Dim aStruct aStruct oExample.MyStruct aStruct is a copy of oExample.MyStruct! aStruct.StructName “Tim” Affects only the property of the copy! If the code ended here, oExample.MyStruct wouldnt be modified! oExample.MyStruct aStruct Copy back the complete struct! Now its ok! Here the other variant does NOT work at all, because only a temporary copy of the struct is modified! oExample.MyStruct.StructName “Tim” WRONG! oExample.MyStruct is not modified! 测试对象是否为一个结构 使用IsUnoStruct检查对象是否为UNO结构 Dim aProperty As New com.sun.star.beans.Property bIsStruct IsUnoStruct( aProperty ) MsgBox bIsStruct Displays True because aProperty is a struct bIsStruct IsUnoStruct( 42 ) MsgBox bIsStruct Displays False because 42 is NO struct 3序列和数组映射  Basic中与序列相对应的是数组。数组是Basic语言的标准元素。 当UNO需要一个序列时Basic程序员可以使用一个相应的数组。在以下示例中oSequenceContainer是一个对象其具有一个类型为sequenceshort 的属性TheSequence。要将一个长度为10、值为0, 1, 2, ...9的序列指定给该属性可以使用以下代码 Dim i%, a%( 9 ) Maximum index 9 - 10 elements for i% 0 to 9 this loop initializes the array a%(i%) i% next i% oSequenceContainer.TheSequence a%() If“TheSequence”is based on XPropertySet alternatively oSequenceContainer.setPropertyValue( “TheSequence”, a%() ) Basic程序员在编程时需要了解不同的索引语义。在以下示例中程序员传送包含一个元素的序 列但实际上传送了两个元素 Pass a sequence of length 1 to the TheSequence property: Dim a%( 1 ) WRONG: The array has 2 elements, not only 1! a%( 0 ) 3 Only Element 0 is initialized, Element 1 remains 0 as initialized by Dim Now a sequence with two values (3,0) is passed what may result in an error or an unexpected behavior! oSequenceContainer.setPropertyValue( “TheSequence”, a%() )     将Basic数组作为一个整体用于参数或用于属性访问时在Basic代码中数组后面应始终跟有 ()否则某些情况下可能会发生错误。 使用一个称为Array()的Basic函数通过一步就可以创建、初始化数组并将它指定给Variant变量这非常有用尤其是对于小型序列 Dim a should be declared as Variant a Array( 1, 2, 3 ) is the same as Dim a(2) a( 0 ) 1 a( 1 ) 2 a( 2 ) 3 有时有必要将空序列传送到UNO接口。在Basic中可以通过在Dim命令中忽略索引来声明空序列 Dim a%() empty array/sequence of type Integer Dim b$() empty array/sequence of String UNO返回的序列在Basic中也表示为数组但不必事先声明这些数组。应该将用于接受序列的变量声明为Variant。要访问UNO返回的数组需要LBound() 和UBound() 获得元素索引。 函数LBound() 返回下限索引而UBound() 返回上限索引。以下代码示意了一个循环该循环将遍历所返回序列的所有元素 Dim aResultArray should be declared as Variant aResultArray oSequenceContainer.TheSequence dim i%, iFrom%, iTo% iFrom% LBound( aResultArray() ) iTo% UBound( aResultArray() ) for i% iFrom% to iTo% this loop displays all array elements msgbox aResultArray(i%) next i% UNO返回序列的索引通常从0开始。一般仅使用UBound()这时上面的示例可以简化为 Dim aResultArray should be declared as Variant aResultArray oSequenceContainer.TheSequence Dim i%, iTo% iTo% UBound( aResultArray() ) For i% 0 To iTo% this loop displays all array elements MsgBox aResultArray(i%) Next i% 序列/数组的元素数目非常容易计算 u% UBound( aResultArray() ) ElementCount% u% 1 对于空数组/序列UBound返回 -1。这样随后按如下所示计算元素数目时UBound的语义就可以保持一致 ElementCount% u% 1 -1 1 0     UNO序列与Basic数组之间的映射前提二者都使用一个基于零的索引系统。为了避免出现问题不要使用语法Dim a ( IndexMin to IndexMin ) 或Basic命令Option Base 1。这二者使所有Basic数组的索引都不是从0开始。 UNO还支持包含序列的序列。在Basic中这对应于包含数组的数组。不要将包含序列的序列与多维数组相混淆。在多维数组中所有子数组始终具有相同数目的元素而在包含序列的序列中每个序列可以具有不同的大小。示例 Dim aArrayOfArrays should be declared as Variant aArrayOfArrays oExample.ShortSequences returns a sequence of sequences of short Dim i%, NumberOfSequences% Dim j%, NumberOfElements% Dim aElementArray NumberOfSequences% UBound( aArrayOfArrays() ) 1 For i% 0 to NumberOfSequences% - 1 loop over all sequences aElementArray aArrayOfArrays( i% ) NumberOfElements% UBound( aElementArray() ) 1 For j% 0 to NumberOfElements% - 1 loop over all elements MsgBox aElementArray( j% ) Next j% Next i% 要在Basic中创建一个包含数组的数组可以将子数组作为主数组的元素: Declare master array Dim aArrayOfArrays( 2 ) Declare sub arrays Dim aArray0( 3 ) Dim aArray1( 2 ) Dim aArray2( 0 ) Initialise sub arrays aArray0( 0 ) 0 aArray0( 1 ) 1 aArray0( 2 ) 2 aArray0( 3 ) 3 aArray1( 0 ) 42 aArray1( 1 ) 0 aArray1( 2 ) -42 aArray2( 0 ) 1 Assign sub arrays to the master array aArrayOfArrays( 0 ) aArray0() aArrayOfArrays( 1 ) aArray1() aArrayOfArrays( 2 ) aArray2() Assign the master array to the array property oExample.ShortSequences aArrayOfArrays() 在这种情况下运行时函数Array() 非常有用。这样示例代码就可以变得更加简练 Declare master array Dim aArrayOfArrays( 2 ) Create and assign sub arrays aArrayOfArrays( 0 ) Array( 0, 1, 2, 3 ) aArrayOfArrays( 1 ) Array( 42, 0, -42 ) aArrayOfArrays( 2 ) Array( 1 ) Assign the master array to the array property oExample.ShortSequences aArrayOfArrays() 如果嵌套使用Array()就可以编写更简练的代码但会使得人们难以理解将要生成的数组 Declare master array variable as variant Dim aArrayOfArrays Create and assign master array and sub arrays aArrayOfArrays Array( Array( 0, 1, 2, 3 ), Array( 42, 0, -42 ), Array( 1 ) ) Assign the master array to the array property oExample.ShortSequences aArrayOfArrays() 对于更高阶次的序列也可以进行相应处理。 4常数和枚举映射 使用符合命名规则的名称对枚举类型的值进行寻址。以下示例假定oExample和oExample2支持 com.sun.star.beans.XPropertySet并包含一个枚举类型为 com.sun.star.beans.PropertyState 的属性Status Dim EnumValue EnumValue com.sun.star.beans.PropertyState.DEFAULT_VALUE MsgBox EnumValue displays 1 eExample.Status com.sun.star.beans.PropertyState.DEFAULT_VALUE Basic不支持枚举类型。在Basic中来自UNO的枚举值被转换成Long值。只要Basic知道某个属性或某个接口方法参数是否需要一个枚举类型就在内部将Long值转换为适当的枚举类型。当接口访问方法需要一个Any Dim EnumValue EnumValue oExample.Status EnumValue is of type Long Accessing the property implicitly oExample2.Status EnumValue Ok! EnumValue is converted to the right enum type Accessing the property explicitly using XPropertySet methods oExample2.setPropertyValue( Status, EnumValue ) WRONG! Will probably fail! 显式访问会失败因为EnumValue是作为Any类型的参数传递到setPropertyValue()因此Basic不知道实际需要一个PropertyState类型的值。还有一个问题在Basic中com.sun.star.beans.PropertyState 的类型为Long。此问题在 com.sun.star.beans.XPropertySet 接口的实现中得以解决。对于枚举类型使用Basic属性语法Object.Property来访问隐式属性优于使用类型Any来调用普通方法。如果仅存在需要Any类型的enum变量的普通接口方法则没有适用于Basic的解决方案。 常数组用于在IDL中指定一组常数值。在Basic中可以使用其全限定名称访问这些常数。以下代码显示了 com.sun.star.beans.PropertyConcept 中的一些常数 MsgBox com.sun.star.beans.PropertyConcept.DANGEROUS Displays 1 MsgBox com.sun.star.beans.PropertyConcept.PROPERTYSET Displays 2 可以将常数组或枚举指定给对象。如果需要访问多个枚举或常数值使用此方法可以缩短代码 Dim oPropConcept oPropConcept com.sun.star.beans.PropertyConcept msgbox oPropConcept.DANGEROUS Displays 1 msgbox oPropConcept.PROPERTYSET Displays 2 5接口 Basic将UNO接口映射成Basic对象方法 在Java和C中调用接口中的一个方法之前需要获取接口。 在Basic中可以直接调用该对象支持的任何接口的任何方法而无需提前查询相应的接口。 使用的是 . 运算符 Basic oExample getExampleObjectFromSomewhere() oExample.doNothing() Calls method doNothing of XFoo1 oExample.doSomething() Calls method doSomething of XFoo2 oExample.doSomethingElse(42) Calls method doSomethingElse of XFoo2 此外如果UNO对象的get和set方法符合以下模式则Basic将它们映射为Basic对象属性 SomeType getSomeProperty() void setSomeProperty(SomeType aValue) 在此模式中Basic提供了一个类型为SomeType、名称为SomeProperty的属性。 x oExample.getIt() Calls getIt method of XFoo3 is the same as x oExample.It Read property It represented by XFoo3 oExample.setIt( x ) Calls setIt method of XFoo3 is the same as oExample.It x Modify property It represented by XFoo3 如果只有get方法而没有set方法则属性被视为只读。 x oExample.getMore() Calls getMore method of XFoo1 y oExample.getLess() Calls getLess method of XFoo1 is the same as x oExample.More Read property More represented by XFoo1 y oExample.Less Read property Less represented by XFoo1 but oExample.More x Runtime error Property is read only oExample.Less y Runtime error Property is read only 可以直接访问com.sun.star.beans.XPropertySet提供的属性。 也可以使用com.sun.star.beans.XPropertySet中的方法访问属性。 x oExample2.Value1 y oExample2.Value2 z oExample2.Value3 is the same as x oExample2.getPropertyValue( Value1 ) y oExample2.getPropertyValue( Value2 ) z oExample2.getPropertyValue( Value3 ) and oExample2.Value1 x oExample2.Value2 y oExample2.Value3 z is the same as oExample2.setPropertyValue( Value1, x ) oExample2.setPropertyValue( Value2, y ) oExample2.setPropertyValue( Value3, z ) 检查接口 尽管Basic不像C 和Java那样支持queryInterface概念但有一个函数HasUnoInterfaces() 用于进行此项检测。 第一个参数HasUnoInterfaces() 需要的是应该接受测试的对象。接着可以将一个或多个全限定的接口名称参数传送到该函数。如果对象支持所有这些接口则函数返回True否则返回False。 oSimpleFileAccess CreateUnoService( com.sun.star.ucb.SimpleFileAccess ) IfaceName1$ com.sun.star.uno.XInterface IfaceName2$ com.sun.star.ucb.XSimpleFileAccess2 IfaceName3$ com.sun.star.container.XPropertySet bSuccess HasUnoInterfaces( oSimpleFileAccess, IfaceName1$ ) MsgBox bSuccess Displays True because XInterface is supported bSuccess HasUnoInterfaces( oSimpleFileAccess, IfaceName1$, IfaceName2$ ) MsgBox bSuccess Displays True because XInterface and XSimpleFileAccess2 are supported bSuccess HasUnoInterfaces( oSimpleFileAccess, IfaceName3$ ) MsgBox bSuccess Displays False because XPropertySet is NOT supported bSuccess HasUnoInterfaces( oSimpleFileAccess, IfaceName1$, IfaceName2$, IfaceName3$ ) MsgBox bSuccess Displays False because XPropertySet is NOT supported 6服务 每个UNO对象都是服务的实例化。 uno对象映射为basic的variant类型而不是object类型因为object类型为纯粹basic对象。 有两种方法获得对象 a.创建新对象 服务管理器com.sun.star.lang.ServiceManager按服务名称实例化服务。 服务管理器的接口com.sun.star.lang.XMultiServiceFactory 它提供三个方法createInstance()、createInstanceWithArguments() 和getAvailableServiceNames()。 使用GetProcessServiceManager()获取服务管理器 createInstance() 创建一个服务实例 oServiceMgr GetProcessServiceManager() oSimpleFileAccess oServiceMgr.createInstance( com.sun.star.ucb.SimpleFileAccess ) createInstanceWithArguments() 使用参数创建一个服务实例。可能有些服务必须使用参数来实例化。 GetProcessServiceManager() 的优势是使用服务管理器实例化服务时可以接收附加信息和传入的参数。 Dim args(1) args(0) Important information args(1) Even more important information oService oServiceMgr.createInstanceWithArguments(com.sun.star.nowhere.ServiceThatNeedsInitialization, args() ) getAvailableServiceNames() 返回支持的所有服务名称。 sServices GetProcessServiceManager().getAvailableServiceNames() Print sServices CreateUnoService函数是创建UNO服务实例的快捷方式它本质上还是使用服务管理器创建实例。 oSimpleFileAccess CreateUnoService( com.sun.star.ucb.SimpleFileAccess ) 此调用实例化 com.sun.star.ucb.SimpleFileAccess 服务。为确保函数成功可以使用IsNull函数检查返回的对象 oSimpleFileAccess CreateUnoService( com.sun.star.ucb.SimpleFileAccess ) bError IsNull( oSimpleFileAccess ) bError is set to False oNoService CreateUnoService( com.sun.star.nowhere.ThisServiceDoesNotExist ) bError IsNull( oNoService ) bError is set to True CreateUnoServiceWithArguments实例化UNO服务包括补充的可选参数。 dds CreateUnoServiceWithArguments(com.sun.star.security.DocumentDigitalSignatures, Array(1.2, True)) 插入到文档中的对象必须由该文档创建。例如电子表格文档的绘图对象只能在这种文档中使用。 电子表格创建绘图对象 RectangleShape Spreadsheet.createInstance(com.sun.star.drawing.RectangleShape) 文本文档创建段落样式 Style Textdocument.createInstance(com.sun.star.style.ParagraphStyle) b.获得现有对象 上下文是一个名称-值对的集合您可以使用它来通过名称获取这些对象。默认上下文可通过函数GetDefaultContext获得。 MsgBox Join(GetDefaultContext().getElementNames(), CHR$(10)) libreoffice basic提供了一些全局对象可以快捷使用StarDesktop StarDesktop对象代表LibreOffice应用程序。   Dim doc As Object, docProperties() docURL ConvertToURL(C:\My Documents\example.odt) Rem com.sun.star.frame.Desktop doc StarDesktop.LoadComponentFromURL(docURL, _blank, 0, docProperties) GlobalScope To manage personal or shared library containers (Application Macros or My Macros) from within a document, use the GlobalScope specifier. 要从文档中管理个人或共享库容器应用程序宏或我的宏请使用GlobalScope 调用文档库 Standard 中的 Dialog1 oDlgDesc DialogLibraries.Standard.Dialog1 调用应用程序库 Library1 中的 Dialog2 oDlgDesc GlobalScope.DialogLibraries.Library1.Dialog2 可以从活动文档中使用以下对象。BasicLibraries对象DialogLibraries对象ThisComponent对象 ThisComponent表示宏中的当前文档。它寻找活动组件其属性可以读取和设置并且可以调用其方法。ThisComponent提供的属性和方法取决于文档类型。ThisDatabaseDocument对象 ThisDatabaseDocument寻找活动的文档该文档的属性可以读取和设置并且可以调用其方法。 ThisDatabaseDocument返回一个类型为 com.sun.star.sdb.XOfficeDatabaseDocument 的对象。 使用名字访问下级对象 XNameAccess和XNameContainer接口用于包含下级对象的对象可以使用名字访问下级对象 XNameAccess访问各个元素而XNameContainer用于插入、修改和删除元素。 com.sun.star.container.XNameAccess 接口 1getByName 方法 Sheets Spreadsheet.Sheets Sheet Sheets.getByName(Sheet1) 2getElementNames 方法 返回所有元素的名称。 Sheets Spreadsheet.Sheets SheetNames Sheets.getElementNames For ILBound(SheetNames) To UBound(SheetNames)   MsgBox SheetNames(I) Next I 3hasByName 方法 是否存在特定名称的下级对象。 Sheets Spreadsheet.Sheets If Sheets.HasByName(Sheet1) Then   MsgBox Sheet1 available Else   MsgBox Sheet1 not available End If com.sun.star.container.XNameContainer 接口 XNameContainer 接口用于插入、删除和修改对象中的下级对象。负责完成这些操作的函数为insertByName、removeByName、replaceByName。 该示例调用一个文本文档该文档包含一个 StyleFamilies 对象该对象包含段落样式 (ParagraphStyles)。 StyleFamilies Textdoc.StyleFamilies ParagraphStyles StyleFamilies.getByName(ParagraphStyles) ParagraphStyles.insertByName(NewStyle, NewStyle)      ParagraphStyles.replaceByName(ChangingStyle, NewStyle)  ParagraphStyles.removeByName(OldStyle) insertByName 行在 ParagraphStyles 对象中的插入NewStyle样式。 replaceByName 行将 ChangingStyle对象更改为NewStyle。 removeByName 调用将 OldStyle对象从ParagraphStyles中删除。 使用索引访问下级对象 XIndexAccess和XIndexContainer接口用于包含下级对象并可使用索引访问下级对象的对象。 XIndexAccess提供了用于访问单个对象的方法。XIndexContainer 提供了用于插入和删除对象的方法。 com.sun.star.container.XIndexAccess 接口 XIndexAccess 提供了 getByIndex 和 getCount 方法。getByIndex 通过索引获得对象。getCount 返回对象的数目。 Sheets Spreadsheet.Sheets For I 0 to Sheets.getCount() - 1   Sheet Sheets.getByIndex(I)   Editing sheet Next I 该示例说明了一个循环此循环遍历获得所有工作表。在使用索引时请注意 getCount 返回元素的数目。不过getByIndex 中的元素是从0开始编号的。因此循环的计数变量是从0到 getCount()-1。 com.sun.star.container.XIndexContainer 接口 XIndexContainer 接口提供了 insertByIndex 和 removeByIndex 函数。这些参数的结构与 XNameContainer 中相应函数的结构相同。 对下级对象的遍历访问 在某些情况下对象包含一个下级对象列表但无法通过名称或索引访问这些下级对象。此时应使用 XEnumeration 和 XenumerationAccess 接口。它们提供了一种机制来遍历某个对象的所有下级元素而无需进行寻址。 com.sun.star.container.XEnumeration 和com.sun.star.container.XenumerationAccess 接口 对象必须提供 XEnumerationAccess 接口该接口仅包含 createEnumeration 方法。此方法返回一个辅助对象而该对象又提供了包含 hasMoreElements 和 nextElement 方法的 XEnumeration 接口。可通过这些方法来访问下级对象。 以下示例将遍历文本的所有段落 ParagraphEnumeration Textdoc.Text.createEnumeration While ParagraphEnumeration.hasMoreElements()   Paragraph ParagraphEnumeration.nextElement() Wend 该示例首先创建了一个 ParagraphEnumeration 辅助对象。然后借助此对象通过循环逐步返回文本的各个段落。在 hasMoreElements 方法返回 False 值表示已到达文本末尾时将会立即终止循环。 检查对象 可以获取UNO对象的信息。 要查明两个对象是否引用同一个UNO对象可以使用函数EqualUnoObjects()。在Basic中不能对对象类型的参数应用比较运算符 例如If Obj1 Obj2 Then会导致运行时错误。 oSimpleFileAccess CreateUnoService( com.sun.star.ucb.SimpleFileAccess ) oSimpleFileAccess2 oSimpleFileAccess  bIdentical EqualUnoObjects( oSimpleFileAccess, oSimpleFileAccess2 ) MsgBox bIdentical Displays True  oSimpleFileAccess3 CreateUnoService( com.sun.star.ucb.SimpleFileAccess ) bIdentical EqualUnoObjects( oSimpleFileAccess, oSimpleFileAccess3 ) MsgBox bIdentical Displays False Dbg_Properties和Dbg_Methods中使用的表示法是uno类型名称。可以忽略Sbx前缀。其他名称与一般Basic类型表示法对应。SbxEMPTY与Variant的类型相同。 DBG_properties 返回一个字符串包括对象的所有属性 DBG_methods 返回一个字符串包括对象的所有方法 DBG_supportedInterfaces 返回一个字符串包括对象的所有接口 示例 Obj createUnoService(com.sun.star.frame.Desktop) MsgBox Obj.DBG_Properties MsgBox Obj.DBG_methods MsgBox Obj.DBG_supportedInterfaces 请注意在使用DBG_properties时返回理论上可以支持的所有属性。但不保证对象可以使用这些属性。因此在使用属性之前必须使用IsEmpty函数检查该属性是否确实可用。 supportsService方法 可以使用supportsService方法来确定对象是否支持特定服务。 例如TextElement对象是否支持com.sun.star.text.Paragraph服务。 Ok TextElement.supportsService(com.sun.star.text.Paragraph) getsupportedservicenames方法 获取所有支持的服务 msgbox join(TextElement.getsupportedservicenames, chr(10)) 工具 - 开发工具能查看对象的服务接口方法属性。 全局方法CreateUnoDialog函数 创建一个基本Uno对象该对象表示宏运行时的对话框。CreateUnoListener函数 创建监听器实例。CreateUnoValue函数 返回一个对象该对象表示一个涉及Uno类型系统的精确类型值。
http://www.w-s-a.com/news/697640/

相关文章:

  • 网站建设网站多少钱公司名字大全列表
  • 设计企业网站内容wordpress 投稿者 权限
  • seo网站推广免费价格低的成语
  • 做网站建设销售辛苦吗专题页是什么
  • 做网站的软件名字全拼wordpress可以上传文件吗
  • 建品牌网站公司关于asp_sql网站开发的书籍
  • 建网站公司营销型网站建设wordpress自定义登录页
  • 泉州市住房和城乡建设局网站淘宝店网站怎么做
  • 企业网站建设费未付款怎样挂账长春网站制作专业
  • 深圳找网站建设邹城市建设局网站
  • 长春火车站停运了吗网站开发概要设计
  • 网站开发表格整体页面居中网站域名详解
  • 漕泾网站建设赢展网站建设
  • 医院网站建设的要求毕业了智慧团建密码忘了
  • 网站怎么建设在哪里接单坪山商城网站建设哪家便宜
  • 中山企业网站优化易语言wordpress发布
  • 宜昌网站推广自己怎么做彩票网站吗
  • 英文网站建设 招标网站建设中服务器搭建方式
  • 直播网站建设需要什么软件有哪些室内设计效果图怎么做
  • 宁波网站建设电话网络推广外包一年多少钱
  • 检索标准的网站怎么制作企业网站
  • 下列关于网站开发中网页发布wordpress 粘帖图片
  • 网站建设遇到的问题及对策宁波网站建设营销推广
  • 各大招聘网站常州百度快速优化
  • 做网站线稿软件有哪些做门户网站需要注册公司吗
  • 建设企业网站模板下载优化方案怎么写
  • 做像淘宝网的网站网站单页面制作
  • 网站建设流程表龙岩网站建设较好的公司
  • 龙岗建站费用手机免费建立网站吗
  • 江门高端网站建设怎样制作wordpress手机主题