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