2 <Template originator = "Michael Hutchinson"
4 lastModified = "2008/05/30">
6 <!-- Template Header -->
7 <TemplateConfiguration>
8 <_Name>Spreadsheet View Sample</_Name>
9 <_Category>C#/OpenOffice Samples</_Category>
10 <Icon>md-project</Icon>
11 <LanguageName>C#</LanguageName>
12 <_Description>Creates a new C# OpenOffice integration sample project.</_Description>
13 </TemplateConfiguration>
17 <Open filename = "Main.cs"/>
20 <!-- Template Content -->
21 <Combine name = "${ProjectName}" directory = ".">
23 <StartupProject>${ProjectName}</StartupProject>
26 <Project name = "${ProjectName}" directory = ".">
29 <Reference type="Gac" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
30 <Reference type="Gac" refto="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
31 <Reference type="Gac" refto="cli_basetypes, Version=1.0.9.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e" />
32 <Reference type="Gac" refto="cli_uno_bridge, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e" />
33 <Reference type="Gac" refto="cli_ure, Version=1.0.12.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e" />
34 <Reference type="Gac" refto="cli_types, Version=1.1.12.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e" />
35 <Reference type="Gac" refto="cli_cppuhelper, Version=1.0.12.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e" />
39 <FileTemplateReference TemplateID="CSharpAssemblyInfo" name="AssemblyInfo.cs" />
40 <FileTemplateReference TemplateID="OpenOfficeSpreadsheetDocHelper" name="SpreadsheetDocHelper.cs" />
41 <File name="Main.cs" AddStandardHeader="False"><![CDATA[//
42 // This library is free software; you can redistribute it and/or
43 // modify it under the terms of the GNU Lesser General Public
44 // License as published by the Free Software Foundation; either
45 // version 2.1 of the License, or (at your option) any later version.
47 // This library is distributed in the hope that it will be useful,
48 // but WITHOUT ANY WARRANTY; without even the implied warranty of
49 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50 // Lesser General Public License for more details.
52 // You should have received a copy of the GNU Lesser General Public
53 // License along with this library. If not, see <http://www.gnu.org/licenses/>.
56 using System.Threading;
57 using unoidl.com.sun.star.sheet;
58 using unoidl.com.sun.star.beans;
59 using unoidl.com.sun.star.container;
60 using unoidl.com.sun.star.table;
61 using unoidl.com.sun.star.view;
62 using unoidl.com.sun.star.frame;
64 namespace OpenOffice.Samples
66 /// <summary> Create and modify a spreadsheet view. </summary>
67 public class ViewSample : SpreadsheetDocHelper
70 public static void Main (String [] args)
73 using (ViewSample sample = new ViewSample (args)) {
74 sample.doSampleFunction ();
76 Console.WriteLine ("\nSamples done.");
77 } catch (Exception ex) {
78 Console.WriteLine ("Sample caught exception! " + ex);
82 public ViewSample (string[] args)
88 /// This sample function performs all changes on the view.
90 public void doSampleFunction()
92 XModel model = (XModel) Document;
93 XController xController = model.getCurrentController();
95 // --- Spreadsheet view ---
96 // freeze the first column and first two rows
97 XViewFreezable xFreeze = (XViewFreezable) xController;
99 Console.WriteLine ("got xFreeze");
100 xFreeze.freezeAtPosition (1, 2);
103 // get the cell range shown in the second pane and assign
104 // a cell background to them
105 XIndexAccess xIndex = (XIndexAccess) xController;
106 uno.Any aPane = xIndex.getByIndex(1);
107 XCellRangeReferrer xRefer = (XCellRangeReferrer) aPane.Value;
108 XCellRange xRange = xRefer.getReferredCells();
109 XPropertySet xRangeProp = (XPropertySet) xRange;
110 xRangeProp.setPropertyValue("IsCellBackgroundTransparent", new uno.Any (false));
111 xRangeProp.setPropertyValue("CellBackColor", new uno.Any ((int) 0xFFFFCC));
113 // --- View settings ---
114 // change the view to display green grid lines
115 XPropertySet xProp = (XPropertySet) xController;
116 xProp.setPropertyValue ("ShowGrid", new uno.Any (true));
117 xProp.setPropertyValue ("GridColor", new uno.Any ((int) 0x00CC00));
119 // --- Range selection ---
120 // let the user select a range and use it as the view's selection
121 XRangeSelection xRngSel = (XRangeSelection) xController;
122 ExampleRangeListener aListener = new ExampleRangeListener();
123 xRngSel.addRangeSelectionListener (aListener);
124 PropertyValue[] aArguments = new PropertyValue[2];
125 aArguments[0] = new PropertyValue ();
126 aArguments[0].Name = "Title";
127 aArguments[0].Value = new uno.Any ("Please select a range");
128 aArguments[1] = new PropertyValue();
129 aArguments[1].Name = "CloseOnMouseRelease";
130 aArguments[1].Value = new uno.Any (true);
131 xRngSel.startRangeSelection (aArguments);
133 Monitor.Enter (aListener);
135 // wait until the selection is done
136 Monitor.Wait (aListener);
138 Monitor.Exit (aListener);
141 xRngSel.removeRangeSelectionListener (aListener);
142 if (aListener.aResult != null && aListener.aResult.Length != 0) {
143 XSelectionSupplier xSel = (XSelectionSupplier) xController;
144 XSpreadsheetView xView = (XSpreadsheetView) xController;
145 XSpreadsheet xSheet = xView.getActiveSheet();
146 XCellRange xResultRange = xSheet.getCellRangeByName (aListener.aResult);
147 xSel.select (new uno.Any (typeof (XCellRange), xResultRange));
151 // listener to react on finished selection
152 private class ExampleRangeListener : XRangeSelectionListener
154 public string aResult;
156 public void done (RangeSelectionEvent evt)
158 aResult = evt.RangeDescriptor;
159 Monitor.Enter (this);
161 Monitor.Pulse (this);
167 public void aborted (RangeSelectionEvent aEvent)
169 Monitor.Enter (this);
171 Monitor.Pulse (this);
177 public void disposing (unoidl.com.sun.star.lang.EventObject aObj)