2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 using System
.Threading
;
22 // __________ implementation ____________________________________
24 /** Create and modify a spreadsheet view.
26 public class ViewSample
: SpreadsheetDocHelper
29 public static void Main( String
[] args
)
33 using ( ViewSample aSample
= new ViewSample( args
) )
35 aSample
.doSampleFunction();
37 Console
.WriteLine( "\nSamples done." );
41 Console
.WriteLine( "Sample caught exception! " + ex
);
47 public ViewSample( String
[] args
)
54 /** This sample function performs all changes on the view. */
55 public void doSampleFunction()
57 unoidl
.com
.sun
.star
.sheet
.XSpreadsheetDocument xDoc
= getDocument();
58 unoidl
.com
.sun
.star
.frame
.XModel xModel
=
59 (unoidl
.com
.sun
.star
.frame
.XModel
) xDoc
;
60 unoidl
.com
.sun
.star
.frame
.XController xController
=
61 xModel
.getCurrentController();
63 // --- Spreadsheet view ---
64 // freeze the first column and first two rows
65 unoidl
.com
.sun
.star
.sheet
.XViewFreezable xFreeze
=
66 (unoidl
.com
.sun
.star
.sheet
.XViewFreezable
) xController
;
67 if ( null != xFreeze
)
68 Console
.WriteLine( "got xFreeze" );
69 xFreeze
.freezeAtPosition( 1, 2 );
72 // get the cell range shown in the second pane and assign
73 // a cell background to them
74 unoidl
.com
.sun
.star
.container
.XIndexAccess xIndex
=
75 (unoidl
.com
.sun
.star
.container
.XIndexAccess
) xController
;
76 uno
.Any aPane
= xIndex
.getByIndex(1);
77 unoidl
.com
.sun
.star
.sheet
.XCellRangeReferrer xRefer
=
78 (unoidl
.com
.sun
.star
.sheet
.XCellRangeReferrer
) aPane
.Value
;
79 unoidl
.com
.sun
.star
.table
.XCellRange xRange
= xRefer
.getReferredCells();
80 unoidl
.com
.sun
.star
.beans
.XPropertySet xRangeProp
=
81 (unoidl
.com
.sun
.star
.beans
.XPropertySet
) xRange
;
82 xRangeProp
.setPropertyValue(
83 "IsCellBackgroundTransparent", new uno
.Any( false ) );
84 xRangeProp
.setPropertyValue(
85 "CellBackColor", new uno
.Any( (Int32
) 0xFFFFCC ) );
87 // --- View settings ---
88 // change the view to display green grid lines
89 unoidl
.com
.sun
.star
.beans
.XPropertySet xProp
=
90 (unoidl
.com
.sun
.star
.beans
.XPropertySet
) xController
;
91 xProp
.setPropertyValue(
92 "ShowGrid", new uno
.Any( true ) );
93 xProp
.setPropertyValue(
94 "GridColor", new uno
.Any( (Int32
) 0x00CC00 ) );
96 // --- Range selection ---
97 // let the user select a range and use it as the view's selection
98 unoidl
.com
.sun
.star
.sheet
.XRangeSelection xRngSel
=
99 (unoidl
.com
.sun
.star
.sheet
.XRangeSelection
) xController
;
100 ExampleRangeListener aListener
= new ExampleRangeListener();
101 xRngSel
.addRangeSelectionListener( aListener
);
102 unoidl
.com
.sun
.star
.beans
.PropertyValue
[] aArguments
=
103 new unoidl
.com
.sun
.star
.beans
.PropertyValue
[2];
104 aArguments
[0] = new unoidl
.com
.sun
.star
.beans
.PropertyValue();
105 aArguments
[0].Name
= "Title";
106 aArguments
[0].Value
= new uno
.Any( "Please select a range" );
107 aArguments
[1] = new unoidl
.com
.sun
.star
.beans
.PropertyValue();
108 aArguments
[1].Name
= "CloseOnMouseRelease";
109 aArguments
[1].Value
= new uno
.Any( true );
110 xRngSel
.startRangeSelection( aArguments
);
111 Monitor
.Enter( aListener
);
114 Monitor
.Wait( aListener
); // wait until the selection is done
118 Monitor
.Exit( aListener
);
120 xRngSel
.removeRangeSelectionListener( aListener
);
121 if ( aListener
.aResult
!= null && aListener
.aResult
.Length
!= 0 )
123 unoidl
.com
.sun
.star
.view
.XSelectionSupplier xSel
=
124 (unoidl
.com
.sun
.star
.view
.XSelectionSupplier
) xController
;
125 unoidl
.com
.sun
.star
.sheet
.XSpreadsheetView xView
=
126 (unoidl
.com
.sun
.star
.sheet
.XSpreadsheetView
) xController
;
127 unoidl
.com
.sun
.star
.sheet
.XSpreadsheet xSheet
=
128 xView
.getActiveSheet();
129 unoidl
.com
.sun
.star
.table
.XCellRange xResultRange
=
130 xSheet
.getCellRangeByName( aListener
.aResult
);
133 typeof (unoidl
.com
.sun
.star
.table
.XCellRange
),
140 // listener to react on finished selection
142 private class ExampleRangeListener
143 : unoidl
.com
.sun
.star
.sheet
.XRangeSelectionListener
145 public String aResult
;
147 public void done( unoidl
.com
.sun
.star
.sheet
.RangeSelectionEvent aEvent
)
149 aResult
= aEvent
.RangeDescriptor
;
150 Monitor
.Enter( this );
153 Monitor
.Pulse( this );
157 Monitor
.Exit( this );
162 unoidl
.com
.sun
.star
.sheet
.RangeSelectionEvent aEvent
)
164 Monitor
.Enter( this );
167 Monitor
.Pulse( this );
171 Monitor
.Exit( this );
175 public void disposing( unoidl
.com
.sun
.star
.lang
.EventObject aObj
)