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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.awt
.Rectangle
;
30 import com
.sun
.star
.container
.XEnumerationAccess
;
31 import com
.sun
.star
.container
.XIndexAccess
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
34 import com
.sun
.star
.sheet
.XSpreadsheet
;
35 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
36 import com
.sun
.star
.sheet
.XSpreadsheets
;
37 import com
.sun
.star
.table
.CellRangeAddress
;
38 import com
.sun
.star
.table
.XCell
;
39 import com
.sun
.star
.table
.XCellRange
;
40 import com
.sun
.star
.table
.XTableCharts
;
41 import com
.sun
.star
.table
.XTableChartsSupplier
;
42 import com
.sun
.star
.uno
.AnyConverter
;
43 import com
.sun
.star
.uno
.Type
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.uno
.XInterface
;
47 public class ScIndexEnumeration_TableChartsEnumeration
extends TestCase
{
48 private XSpreadsheetDocument xSheetDoc
= null;
51 * Creates Spreadsheet document.
54 protected void initialize( TestParameters tParam
, PrintWriter log
) {
55 // get a soffice factory object
56 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
59 log
.println( "creating a sheetdocument" );
60 xSheetDoc
= SOF
.createCalcDoc(null);
61 } catch (com
.sun
.star
.uno
.Exception e
) {
62 // Some exception occurs.FAILED
63 e
.printStackTrace( log
);
64 throw new StatusException( "Couldn't create document", e
);
69 * Disposes Spreadsheet document.
72 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
73 log
.println( " disposing xSheetDoc " );
74 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
);
75 util
.DesktopTools
.closeDoc(oComp
);
79 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
81 XSpreadsheet oSheet
=null;
84 log
.println("Getting spreadsheet") ;
85 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
86 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
87 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
88 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
89 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
90 log
.println("Couldn't get Sheet ");
91 e
.printStackTrace(log
);
92 throw new StatusException("Couldn't get sheet", e
);
93 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
94 log
.println("Couldn't get Sheet ");
95 e
.printStackTrace(log
);
96 throw new StatusException("Couldn't get sheet", e
);
97 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
98 log
.println("Couldn't get Sheet ");
99 e
.printStackTrace(log
);
100 throw new StatusException("Couldn't get sheet", e
);
103 log
.println("Creating the Header") ;
105 insertIntoCell(1,0,"JAN",oSheet
,"");
106 insertIntoCell(2,0,"FEB",oSheet
,"");
107 insertIntoCell(3,0,"MAR",oSheet
,"");
108 insertIntoCell(4,0,"APR",oSheet
,"");
109 insertIntoCell(5,0,"MAI",oSheet
,"");
110 insertIntoCell(6,0,"JUN",oSheet
,"");
111 insertIntoCell(7,0,"JUL",oSheet
,"");
112 insertIntoCell(8,0,"AUG",oSheet
,"");
113 insertIntoCell(9,0,"SEP",oSheet
,"");
114 insertIntoCell(10,0,"OCT",oSheet
,"");
115 insertIntoCell(11,0,"NOV",oSheet
,"");
116 insertIntoCell(12,0,"DEC",oSheet
,"");
117 insertIntoCell(13,0,"SUM",oSheet
,"");
119 log
.println("Fill the lines");
121 insertIntoCell(0,1,"Smith",oSheet
,"");
122 insertIntoCell(1,1,"42",oSheet
,"V");
123 insertIntoCell(2,1,"58.9",oSheet
,"V");
124 insertIntoCell(3,1,"-66.5",oSheet
,"V");
125 insertIntoCell(4,1,"43.4",oSheet
,"V");
126 insertIntoCell(5,1,"44.5",oSheet
,"V");
127 insertIntoCell(6,1,"45.3",oSheet
,"V");
128 insertIntoCell(7,1,"-67.3",oSheet
,"V");
129 insertIntoCell(8,1,"30.5",oSheet
,"V");
130 insertIntoCell(9,1,"23.2",oSheet
,"V");
131 insertIntoCell(10,1,"-97.3",oSheet
,"V");
132 insertIntoCell(11,1,"22.4",oSheet
,"V");
133 insertIntoCell(12,1,"23.5",oSheet
,"V");
134 insertIntoCell(13,1,"=SUM(B2:M2)",oSheet
,"");
136 insertIntoCell(0,2,"Jones",oSheet
,"");
137 insertIntoCell(1,2,"21",oSheet
,"V");
138 insertIntoCell(2,2,"40.9",oSheet
,"V");
139 insertIntoCell(3,2,"-57.5",oSheet
,"V");
140 insertIntoCell(4,2,"-23.4",oSheet
,"V");
141 insertIntoCell(5,2,"34.5",oSheet
,"V");
142 insertIntoCell(6,2,"59.3",oSheet
,"V");
143 insertIntoCell(7,2,"27.3",oSheet
,"V");
144 insertIntoCell(8,2,"-38.5",oSheet
,"V");
145 insertIntoCell(9,2,"43.2",oSheet
,"V");
146 insertIntoCell(10,2,"57.3",oSheet
,"V");
147 insertIntoCell(11,2,"25.4",oSheet
,"V");
148 insertIntoCell(12,2,"28.5",oSheet
,"V");
149 insertIntoCell(13,2,"=SUM(B3:M3)",oSheet
,"");
151 insertIntoCell(0,3,"Brown",oSheet
,"");
152 insertIntoCell(1,3,"31.45",oSheet
,"V");
153 insertIntoCell(2,3,"-20.9",oSheet
,"V");
154 insertIntoCell(3,3,"-117.5",oSheet
,"V");
155 insertIntoCell(4,3,"23.4",oSheet
,"V");
156 insertIntoCell(5,3,"-114.5",oSheet
,"V");
157 insertIntoCell(6,3,"115.3",oSheet
,"V");
158 insertIntoCell(7,3,"-171.3",oSheet
,"V");
159 insertIntoCell(8,3,"89.5",oSheet
,"V");
160 insertIntoCell(9,3,"41.2",oSheet
,"V");
161 insertIntoCell(10,3,"71.3",oSheet
,"V");
162 insertIntoCell(11,3,"25.4",oSheet
,"V");
163 insertIntoCell(12,3,"38.5",oSheet
,"V");
164 insertIntoCell(13,3,"=SUM(A4:L4)",oSheet
,"");
167 Rectangle oRect
= new Rectangle(500, 3000, 25000, 11000);
169 XCellRange oRange
= UnoRuntime
.queryInterface(XCellRange
.class, oSheet
);
170 XCellRange myRange
= oRange
.getCellRangeByName("A1:N4");
171 XCellRangeAddressable oRangeAddr
= UnoRuntime
.queryInterface(XCellRangeAddressable
.class, myRange
);
172 CellRangeAddress myAddr
= oRangeAddr
.getRangeAddress();
174 CellRangeAddress
[] oAddr
= new CellRangeAddress
[1];
176 XTableChartsSupplier oSupp
= UnoRuntime
.queryInterface(XTableChartsSupplier
.class, oSheet
);
179 log
.println("Insert Chart");
180 XTableCharts oCharts
= oSupp
.getCharts();
181 oCharts
.addNewByName("ScChartObj", oRect
, oAddr
, true, true);
183 log
.println("creating a new environment for object");
184 XEnumerationAccess ea
= UnoRuntime
.queryInterface(XEnumerationAccess
.class,oCharts
);
186 XInterface oObj
= ea
.createEnumeration();
188 TestEnvironment tEnv
= new TestEnvironment(oObj
);
194 * Inserts a value or a formula in the cell of the spreasheet.
195 * @param CellX is the column index of the cell
196 * @param CellY is the row index of the cell
197 * @param theValue string representation of the value
198 * @param TT1 specify the spreadsheet, the interface
199 * <code>com.sun.star.sheet.XSpreadsheet</code>
200 * @param flag if it's equal to <code>'V'</code> then the method inserts
201 * a double-value in the cell else it inserts a formula in the cell
203 public static void insertIntoCell(
204 int CellX
, int CellY
, String theValue
, XSpreadsheet TT1
, String flag
) {
209 oCell
= TT1
.getCellByPosition(CellX
, CellY
);
210 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
211 System
.out
.println("Could not get Cell");
214 if (flag
.equals("V")) {
215 oCell
.setValue(Float
.parseFloat(theValue
));
217 oCell
.setFormula(theValue
);
220 } // end of insertIntoCell