4 <?component error="true" debug="true"?>
7 description="writerdemo script component"
8 progid="dcomtest.writerdemo.WSC"
10 classid="{90c5ca1a-5e38-4c6d-9634-b0c740c569ad}"
20 <script language="JScript">
23 var description = new jscripttest;
25 function jscripttest()
33 //The service manager is always the starting point
34 //If there is no office running then an office is started up
36 var objServiceManager= new ActiveXObject("com.sun.star.ServiceManager","\\jl-1036");
38 //Create the CoreReflection service that is later used to create structs
39 var objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection");
42 var objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop");
44 //Open a new empty writer document
45 var objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection");
47 //get a type description class for Size
48 //var propClass = objCoreReflection.forName( "com.sun.star.beans.PropertyValue" );
50 //var propParam= new Array();
51 //propClass.createObject(propParam);
52 //var prop= propParam[0];
53 //prop.Name= "Hidden";
56 //create the actual object
57 var args= new Array();
58 var objDocument= objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args);
60 //Create a text object
61 var objText= objDocument.getText();
63 //Create a cursor object
64 var objCursor= objText.createTextCursor();
67 objText.insertString( objCursor, "The first line in the newly created text document.\n", false);
69 //Inserting a second line
70 objText.insertString( objCursor, "Now we're in the second line", false);
72 //Create instance of a text table with 4 columns and 4 rows
73 var objTable= objDocument.createInstance( "com.sun.star.text.TextTable");
74 objTable.initialize( 4, 4);
77 objText.insertTextContent( objCursor, objTable, false);
80 var objRows= objTable.getRows();
81 var objRow= objRows.getByIndex( 0);
83 //Set the table background color
84 objTable.setPropertyValue( "BackTransparent", false);
85 objTable.setPropertyValue( "BackColor", 13421823);
87 //Set a different background color for the first row
88 objRow.setPropertyValue( "BackTransparent", false);
89 objRow.setPropertyValue( "BackColor", 6710932);
91 //Fill the first table row
92 insertIntoCell( "A1","FirstColumn", objTable);
93 insertIntoCell( "B1","SecondColumn", objTable);
94 insertIntoCell( "C1","ThirdColumn", objTable);
95 insertIntoCell( "D1","SUM", objTable);
98 objTable.getCellByName("A2").setValue( 22.5);
99 objTable.getCellByName("B2").setValue( 5615.3);
100 objTable.getCellByName("C2").setValue( -2315.7);
101 objTable.getCellByName("D2").setFormula("sum <A2:C2>");
103 objTable.getCellByName("A3").setValue( 21.5);
104 objTable.getCellByName("B3").setValue( 615.3);
105 objTable.getCellByName("C3").setValue( -315.7);
106 objTable.getCellByName("D3").setFormula( "sum <A3:C3>");
108 objTable.getCellByName("A4").setValue( 121.5);
109 objTable.getCellByName("B4").setValue( -615.3);
110 objTable.getCellByName("C4").setValue( 415.7);
111 objTable.getCellByName("D4").setFormula( "sum <A4:C4>");
113 //Change the CharColor and add a Shadow
114 objCursor.setPropertyValue( "CharColor", 255);
115 objCursor.setPropertyValue( "CharShadowed", true);
117 //Create a paragraph break
118 //The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant
119 objText.insertControlCharacter( objCursor, 0 , false);
121 //Inserting colored Text.
122 objText.insertString( objCursor, " This is a colored Text - blue with shadow\n", false);
124 //Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK).
125 objText.insertControlCharacter( objCursor, 0, false );
127 //Create a TextFrame.
128 var objTextFrame= objDocument.createInstance("com.sun.star.text.TextFrame");
130 //Create a Size struct.
131 var objSize= createStruct("com.sun.star.awt.Size");
132 objSize.Width= 15000;
134 objTextFrame.setSize( objSize);
136 //TextContentAnchorType.AS_CHARACTER = 1
137 objTextFrame.setPropertyValue( "AnchorType", 1);
140 objText.insertTextContent( objCursor, objTextFrame, false);
142 //Get the text object of the frame
143 var objFrameText= objTextFrame.getText();
145 //Create a cursor object
146 var objFrameTextCursor= objFrameText.createTextCursor();
148 //Inserting some Text
149 objFrameText.insertString( objFrameTextCursor, "The first line in the newly created text frame.",
151 objFrameText.insertString(objFrameTextCursor,
152 "With this second line the height of the frame raises.", false );
154 //Create a paragraph break
155 //The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant
156 objFrameText.insertControlCharacter( objCursor, 0 , false);
158 //Change the CharColor and add a Shadow
159 objCursor.setPropertyValue( "CharColor", 65536);
160 objCursor.setPropertyValue( "CharShadowed", false);
162 //Insert another string
163 objText.insertString( objCursor, " That's all for now !!", false );
165 function insertIntoCell( strCellName, strText, objTable)
167 var objCellText= objTable.getCellByName( strCellName);
168 var objCellCursor= objCellText.createTextCursor();
169 objCellCursor.setPropertyValue( "CharColor",16777215);
170 objCellText.insertString( objCellCursor, strText, false);
172 function createStruct( strTypeName)
174 var classSize= objCoreReflection.forName( strTypeName);
175 var aStruct= new Array();
176 classSize.createObject( aStruct);