1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
<?xml version="1.0"?>
<component>
<?component error="true" debug="true"?>
<registration
description="writerdemo script component"
progid="dcomtest.writerdemo.WSC"
version="1.00"
classid="{90c5ca1a-5e38-4c6d-9634-b0c740c569ad}"
remotable="true"
>
</registration>
<public>
<method name="run">
</method>
</public>
<script language="JScript">
<![CDATA[
var description = new jscripttest;
function jscripttest()
{
this.run = run;
}
function run()
{
//The service manager is always the starting point
//If there is no office running then an office is started up
var objServiceManager= new ActiveXObject("com.sun.star.ServiceManager","\\jl-1036");
//Create the CoreReflection service that is later used to create structs
var objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection");
//Create the Desktop
var objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop");
//Open a new empty writer document
var objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection");
//get a type description class for Size
//var propClass = objCoreReflection.forName( "com.sun.star.beans.PropertyValue" );
//var propParam= new Array();
//propClass.createObject(propParam);
//var prop= propParam[0];
//prop.Name= "Hidden";
//prop.Value= true;
//create the actual object
var args= new Array();
var objDocument= objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args);
//Create a text object
var objText= objDocument.getText();
//Create a cursor object
var objCursor= objText.createTextCursor();
//Inserting some Text
objText.insertString( objCursor, "The first line in the newly created text document.\n", false);
//Inserting a second line
objText.insertString( objCursor, "Now we're in the second line", false);
//Create instance of a text table with 4 columns and 4 rows
var objTable= objDocument.createInstance( "com.sun.star.text.TextTable");
objTable.initialize( 4, 4);
//Insert the table
objText.insertTextContent( objCursor, objTable, false);
//Get first row
var objRows= objTable.getRows();
var objRow= objRows.getByIndex( 0);
//Set the table background color
objTable.setPropertyValue( "BackTransparent", false);
objTable.setPropertyValue( "BackColor", 13421823);
//Set a different background color for the first row
objRow.setPropertyValue( "BackTransparent", false);
objRow.setPropertyValue( "BackColor", 6710932);
//Fill the first table row
insertIntoCell( "A1","FirstColumn", objTable);
insertIntoCell( "B1","SecondColumn", objTable);
insertIntoCell( "C1","ThirdColumn", objTable);
insertIntoCell( "D1","SUM", objTable);
objTable.getCellByName("A2").setValue( 22.5);
objTable.getCellByName("B2").setValue( 5615.3);
objTable.getCellByName("C2").setValue( -2315.7);
objTable.getCellByName("D2").setFormula("sum <A2:C2>");
objTable.getCellByName("A3").setValue( 21.5);
objTable.getCellByName("B3").setValue( 615.3);
objTable.getCellByName("C3").setValue( -315.7);
objTable.getCellByName("D3").setFormula( "sum <A3:C3>");
objTable.getCellByName("A4").setValue( 121.5);
objTable.getCellByName("B4").setValue( -615.3);
objTable.getCellByName("C4").setValue( 415.7);
objTable.getCellByName("D4").setFormula( "sum <A4:C4>");
//Change the CharColor and add a Shadow
objCursor.setPropertyValue( "CharColor", 255);
objCursor.setPropertyValue( "CharShadowed", true);
//Create a paragraph break
//The second argument is a css::text::ControlCharacter::PARAGRAPH_BREAK constant
objText.insertControlCharacter( objCursor, 0 , false);
//Inserting colored Text.
objText.insertString( objCursor, " This is a colored Text - blue with shadow\n", false);
//Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK).
objText.insertControlCharacter( objCursor, 0, false );
//Create a TextFrame.
var objTextFrame= objDocument.createInstance("com.sun.star.text.TextFrame");
//Create a Size struct.
var objSize= createStruct("com.sun.star.awt.Size");
objSize.Width= 15000;
objSize.Height= 400;
objTextFrame.setSize( objSize);
//TextContentAnchorType.AS_CHARACTER = 1
objTextFrame.setPropertyValue( "AnchorType", 1);
//insert the frame
objText.insertTextContent( objCursor, objTextFrame, false);
//Get the text object of the frame
var objFrameText= objTextFrame.getText();
//Create a cursor object
var objFrameTextCursor= objFrameText.createTextCursor();
//Inserting some Text
objFrameText.insertString( objFrameTextCursor, "The first line in the newly created text frame.",
false);
objFrameText.insertString(objFrameTextCursor,
"With this second line the height of the frame raises.", false );
//Create a paragraph break
//The second argument is a css::text::ControlCharacter::PARAGRAPH_BREAK constant
objFrameText.insertControlCharacter( objCursor, 0 , false);
//Change the CharColor and add a Shadow
objCursor.setPropertyValue( "CharColor", 65536);
objCursor.setPropertyValue( "CharShadowed", false);
//Insert another string
objText.insertString( objCursor, " That's all for now !!", false );
function insertIntoCell( strCellName, strText, objTable)
{
var objCellText= objTable.getCellByName( strCellName);
var objCellCursor= objCellText.createTextCursor();
objCellCursor.setPropertyValue( "CharColor",16777215);
objCellText.insertString( objCellCursor, strText, false);
}
function createStruct( strTypeName)
{
var classSize= objCoreReflection.forName( strTypeName);
var aStruct= new Array();
classSize.createObject( aStruct);
return aStruct[0];
}
}
]]>
</script>
</component>
|