1*cdf0e10cSrcweir 2*cdf0e10cSrcweir using System; 3*cdf0e10cSrcweir using System.Threading; 4*cdf0e10cSrcweir 5*cdf0e10cSrcweir // __________ implementation ____________________________________ 6*cdf0e10cSrcweir 7*cdf0e10cSrcweir /** Create and modify a spreadsheet view. 8*cdf0e10cSrcweir */ 9*cdf0e10cSrcweir public class ViewSample : SpreadsheetDocHelper 10*cdf0e10cSrcweir { 11*cdf0e10cSrcweir 12*cdf0e10cSrcweir public static void Main( String [] args ) 13*cdf0e10cSrcweir { 14*cdf0e10cSrcweir try 15*cdf0e10cSrcweir { 16*cdf0e10cSrcweir using ( ViewSample aSample = new ViewSample( args ) ) 17*cdf0e10cSrcweir { 18*cdf0e10cSrcweir aSample.doSampleFunction(); 19*cdf0e10cSrcweir } 20*cdf0e10cSrcweir Console.WriteLine( "\nSamples done." ); 21*cdf0e10cSrcweir } 22*cdf0e10cSrcweir catch (Exception ex) 23*cdf0e10cSrcweir { 24*cdf0e10cSrcweir Console.WriteLine( "Sample caught exception! " + ex ); 25*cdf0e10cSrcweir } 26*cdf0e10cSrcweir } 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // ________________________________________________________________ 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir public ViewSample( String[] args ) 31*cdf0e10cSrcweir : base( args ) 32*cdf0e10cSrcweir { 33*cdf0e10cSrcweir } 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir // ________________________________________________________________ 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir /** This sample function performs all changes on the view. */ 38*cdf0e10cSrcweir public void doSampleFunction() 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir unoidl.com.sun.star.sheet.XSpreadsheetDocument xDoc = getDocument(); 41*cdf0e10cSrcweir unoidl.com.sun.star.frame.XModel xModel = 42*cdf0e10cSrcweir (unoidl.com.sun.star.frame.XModel) xDoc; 43*cdf0e10cSrcweir unoidl.com.sun.star.frame.XController xController = 44*cdf0e10cSrcweir xModel.getCurrentController(); 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir // --- Spreadsheet view --- 47*cdf0e10cSrcweir // freeze the first column and first two rows 48*cdf0e10cSrcweir unoidl.com.sun.star.sheet.XViewFreezable xFreeze = 49*cdf0e10cSrcweir (unoidl.com.sun.star.sheet.XViewFreezable) xController; 50*cdf0e10cSrcweir if ( null != xFreeze ) 51*cdf0e10cSrcweir Console.WriteLine( "got xFreeze" ); 52*cdf0e10cSrcweir xFreeze.freezeAtPosition( 1, 2 ); 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir // --- View pane --- 55*cdf0e10cSrcweir // get the cell range shown in the second pane and assign 56*cdf0e10cSrcweir // a cell background to them 57*cdf0e10cSrcweir unoidl.com.sun.star.container.XIndexAccess xIndex = 58*cdf0e10cSrcweir (unoidl.com.sun.star.container.XIndexAccess) xController; 59*cdf0e10cSrcweir uno.Any aPane = xIndex.getByIndex(1); 60*cdf0e10cSrcweir unoidl.com.sun.star.sheet.XCellRangeReferrer xRefer = 61*cdf0e10cSrcweir (unoidl.com.sun.star.sheet.XCellRangeReferrer) aPane.Value; 62*cdf0e10cSrcweir unoidl.com.sun.star.table.XCellRange xRange = xRefer.getReferredCells(); 63*cdf0e10cSrcweir unoidl.com.sun.star.beans.XPropertySet xRangeProp = 64*cdf0e10cSrcweir (unoidl.com.sun.star.beans.XPropertySet) xRange; 65*cdf0e10cSrcweir xRangeProp.setPropertyValue( 66*cdf0e10cSrcweir "IsCellBackgroundTransparent", new uno.Any( false ) ); 67*cdf0e10cSrcweir xRangeProp.setPropertyValue( 68*cdf0e10cSrcweir "CellBackColor", new uno.Any( (Int32) 0xFFFFCC ) ); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // --- View settings --- 71*cdf0e10cSrcweir // change the view to display green grid lines 72*cdf0e10cSrcweir unoidl.com.sun.star.beans.XPropertySet xProp = 73*cdf0e10cSrcweir (unoidl.com.sun.star.beans.XPropertySet) xController; 74*cdf0e10cSrcweir xProp.setPropertyValue( 75*cdf0e10cSrcweir "ShowGrid", new uno.Any( true ) ); 76*cdf0e10cSrcweir xProp.setPropertyValue( 77*cdf0e10cSrcweir "GridColor", new uno.Any( (Int32) 0x00CC00 ) ); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir // --- Range selection --- 80*cdf0e10cSrcweir // let the user select a range and use it as the view's selection 81*cdf0e10cSrcweir unoidl.com.sun.star.sheet.XRangeSelection xRngSel = 82*cdf0e10cSrcweir (unoidl.com.sun.star.sheet.XRangeSelection) xController; 83*cdf0e10cSrcweir ExampleRangeListener aListener = new ExampleRangeListener(); 84*cdf0e10cSrcweir xRngSel.addRangeSelectionListener( aListener ); 85*cdf0e10cSrcweir unoidl.com.sun.star.beans.PropertyValue[] aArguments = 86*cdf0e10cSrcweir new unoidl.com.sun.star.beans.PropertyValue[2]; 87*cdf0e10cSrcweir aArguments[0] = new unoidl.com.sun.star.beans.PropertyValue(); 88*cdf0e10cSrcweir aArguments[0].Name = "Title"; 89*cdf0e10cSrcweir aArguments[0].Value = new uno.Any( "Please select a range" ); 90*cdf0e10cSrcweir aArguments[1] = new unoidl.com.sun.star.beans.PropertyValue(); 91*cdf0e10cSrcweir aArguments[1].Name = "CloseOnMouseRelease"; 92*cdf0e10cSrcweir aArguments[1].Value = new uno.Any( true ); 93*cdf0e10cSrcweir xRngSel.startRangeSelection( aArguments ); 94*cdf0e10cSrcweir Monitor.Enter( aListener ); 95*cdf0e10cSrcweir try 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir Monitor.Wait( aListener ); // wait until the selection is done 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir finally 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir Monitor.Exit( aListener ); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir xRngSel.removeRangeSelectionListener( aListener ); 104*cdf0e10cSrcweir if ( aListener.aResult != null && aListener.aResult.Length != 0 ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir unoidl.com.sun.star.view.XSelectionSupplier xSel = 107*cdf0e10cSrcweir (unoidl.com.sun.star.view.XSelectionSupplier) xController; 108*cdf0e10cSrcweir unoidl.com.sun.star.sheet.XSpreadsheetView xView = 109*cdf0e10cSrcweir (unoidl.com.sun.star.sheet.XSpreadsheetView) xController; 110*cdf0e10cSrcweir unoidl.com.sun.star.sheet.XSpreadsheet xSheet = 111*cdf0e10cSrcweir xView.getActiveSheet(); 112*cdf0e10cSrcweir unoidl.com.sun.star.table.XCellRange xResultRange = 113*cdf0e10cSrcweir xSheet.getCellRangeByName( aListener.aResult ); 114*cdf0e10cSrcweir xSel.select( 115*cdf0e10cSrcweir new uno.Any( 116*cdf0e10cSrcweir typeof (unoidl.com.sun.star.table.XCellRange), 117*cdf0e10cSrcweir xResultRange ) ); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // ________________________________________________________________ 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir // listener to react on finished selection 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir private class ExampleRangeListener 126*cdf0e10cSrcweir : unoidl.com.sun.star.sheet.XRangeSelectionListener 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir public String aResult; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir public void done( unoidl.com.sun.star.sheet.RangeSelectionEvent aEvent ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir aResult = aEvent.RangeDescriptor; 133*cdf0e10cSrcweir Monitor.Enter( this ); 134*cdf0e10cSrcweir try 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir Monitor.Pulse( this ); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir finally 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir Monitor.Exit( this ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir public void aborted( 145*cdf0e10cSrcweir unoidl.com.sun.star.sheet.RangeSelectionEvent aEvent ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir Monitor.Enter( this ); 148*cdf0e10cSrcweir try 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir Monitor.Pulse( this ); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir finally 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir Monitor.Exit( this ); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir public void disposing( unoidl.com.sun.star.lang.EventObject aObj ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir // ________________________________________________________________ 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir } 166