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