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