SCUtil.java (3908dc91) SCUtil.java (1ea6643f)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 10 unchanged lines hidden (view full) ---

19 *
20 *************************************************************/
21
22
23package testlib.uno;
24
25import java.util.HashMap;
26
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 10 unchanged lines hidden (view full) ---

19 *
20 *************************************************************/
21
22
23package testlib.uno;
24
25import java.util.HashMap;
26
27import org.openoffice.test.common.FileUtil;
27import org.openoffice.test.common.Testspace;
28import org.openoffice.test.uno.UnoApp;
29
30import com.sun.star.beans.PropertyValue;
28import org.openoffice.test.common.Testspace;
29import org.openoffice.test.uno.UnoApp;
30
31import com.sun.star.beans.PropertyValue;
32import com.sun.star.beans.XPropertySet;
31import com.sun.star.container.XIndexAccess;
32import com.sun.star.frame.XController;
33import com.sun.star.frame.XModel;
34import com.sun.star.frame.XStorable;
35import com.sun.star.lang.XComponent;
36import com.sun.star.sheet.XSpreadsheet;
37import com.sun.star.sheet.XSpreadsheetDocument;
38import com.sun.star.sheet.XSpreadsheetView;

--- 5 unchanged lines hidden (view full) ---

44import com.sun.star.table.XTableRows;
45import com.sun.star.text.XText;
46import com.sun.star.uno.UnoRuntime;
47import com.sun.star.util.XCloseable;
48
49
50/**
51 * Utilities of Spreadsheet
33import com.sun.star.container.XIndexAccess;
34import com.sun.star.frame.XController;
35import com.sun.star.frame.XModel;
36import com.sun.star.frame.XStorable;
37import com.sun.star.lang.XComponent;
38import com.sun.star.sheet.XSpreadsheet;
39import com.sun.star.sheet.XSpreadsheetDocument;
40import com.sun.star.sheet.XSpreadsheetView;

--- 5 unchanged lines hidden (view full) ---

46import com.sun.star.table.XTableRows;
47import com.sun.star.text.XText;
48import com.sun.star.uno.UnoRuntime;
49import com.sun.star.util.XCloseable;
50
51
52/**
53 * Utilities of Spreadsheet
52 * @author test
53 *
54 */
55
56public class SCUtil {
57
54 *
55 */
56
57public class SCUtil {
58
59 private static final String scTempDir = "output/sc/"; //Spreadsheet temp file directory
58 private static HashMap filterName = new HashMap();
60 private static HashMap filterName = new HashMap();
59
61
60 private SCUtil() {
61
62 }
63
64 /**
65 * Get spreadsheet document object
66 * @param xSpreadsheetComponent
67 * @return

--- 89 unchanged lines hidden (view full) ---

157 */
158 public static void setTextToCell(XSpreadsheet xSpreadsheet, int column, int row, String text) throws Exception {
159 XCell xCell = xSpreadsheet.getCellByPosition(column, row);
160 XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
161 xText.setString(text);
162 }
163
164 /**
62 private SCUtil() {
63
64 }
65
66 /**
67 * Get spreadsheet document object
68 * @param xSpreadsheetComponent
69 * @return

--- 89 unchanged lines hidden (view full) ---

159 */
160 public static void setTextToCell(XSpreadsheet xSpreadsheet, int column, int row, String text) throws Exception {
161 XCell xCell = xSpreadsheet.getCellByPosition(column, row);
162 XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
163 xText.setString(text);
164 }
165
166 /**
167 * Set text into specific cell
168 * @param xCell
169 * @param text
170 * @throws Exception
171 */
172 public static void setTextToCell(XCell xCell, String text) throws Exception {
173 XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
174 xText.setString(text);
175 }
176
177 /**
165 * Set formula into specific cell
166 * @param xSpreadsheet
167 * @param column
168 * @param row
169 * @param formula
170 * @throws Exception
171 */
172 public static void setFormulaToCell(XSpreadsheet xSpreadsheet, int column, int row, String formula) throws Exception {

--- 128 unchanged lines hidden (view full) ---

301 */
302 public static String[][] getTextFromCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row) throws Exception {
303 XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
304 XCell xCell = null;
305 XText xText = null;
306 String[][] cellTexts = new String[end_row - start_row+1][end_col - start_col +1];
307
308 for (int i = 0; i <= (end_row - start_row); i++ ) {
178 * Set formula into specific cell
179 * @param xSpreadsheet
180 * @param column
181 * @param row
182 * @param formula
183 * @throws Exception
184 */
185 public static void setFormulaToCell(XSpreadsheet xSpreadsheet, int column, int row, String formula) throws Exception {

--- 128 unchanged lines hidden (view full) ---

314 */
315 public static String[][] getTextFromCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row) throws Exception {
316 XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
317 XCell xCell = null;
318 XText xText = null;
319 String[][] cellTexts = new String[end_row - start_row+1][end_col - start_col +1];
320
321 for (int i = 0; i <= (end_row - start_row); i++ ) {
309 for(int j = 0; j <= (end_col - start_col); j++) {
322 for (int j = 0; j <= (end_col - start_col); j++) {
310 xCell = xCellRange.getCellByPosition(j, i);
311 xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
312 cellTexts[i][j] = xText.getString();
313 }
314 }
315
316 return cellTexts;
317 }

--- 22 unchanged lines hidden (view full) ---

340 XController xController = xModel.getCurrentController();
341 XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, xController);
342 XSpreadsheet xSpreadsheet = xSpreadsheetView.getActiveSheet();
343
344 return xSpreadsheet;
345 }
346
347 /**
323 xCell = xCellRange.getCellByPosition(j, i);
324 xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
325 cellTexts[i][j] = xText.getString();
326 }
327 }
328
329 return cellTexts;
330 }

--- 22 unchanged lines hidden (view full) ---

353 XController xController = xModel.getCurrentController();
354 XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, xController);
355 XSpreadsheet xSpreadsheet = xSpreadsheetView.getActiveSheet();
356
357 return xSpreadsheet;
358 }
359
360 /**
348 * Save file as specific file format into testspace/output folder.
361 * Set value of specific property from a cell
362 * @param xCell
363 * @param propName
364 * @param value
365 * @throws Exception
366 */
367 public static void setCellProperties(XCell xCell, String propName, Object value) throws Exception {
368
369 XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCell);
370 xPropertySet.setPropertyValue(propName, value);
371 }
372
373 /**
374 * Get value of specific property from a cell
375 * @param xCell
376 * @param propName
377 * @return
378 * @throws Exception
379 */
380 public static Object getCellProperties(XCell xCell, String propName) throws Exception {
381 XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCell);
382 Object value = xPropertySet.getPropertyValue(propName);
383
384 return value;
385 }
386
387 /**
388 * Clear temp file directory
389 */
390 public static void clearTempDir() {
391 FileUtil.deleteFile(Testspace.getFile(Testspace.getPath(scTempDir)));
392 }
393
394 /**
395 * Save file as specific file format into spreadsheet temp file folder.
349 * @param scComponent
350 * @param fileName File name string without extension name (e.g. "sampleFile")
351 * @param extName ("ods", "ots", "xls", "xlt", "csv")
352 * @throws Exception
353 */
354 public static void saveFileAs(XComponent scComponent, String fileName, String extName) throws Exception {
355
356 initFilterName();
357
396 * @param scComponent
397 * @param fileName File name string without extension name (e.g. "sampleFile")
398 * @param extName ("ods", "ots", "xls", "xlt", "csv")
399 * @throws Exception
400 */
401 public static void saveFileAs(XComponent scComponent, String fileName, String extName) throws Exception {
402
403 initFilterName();
404
358 String storeUrl = Testspace.getUrl("output/" + fileName + "." + extName);
405 String storeUrl = Testspace.getUrl(scTempDir + fileName + "." + extName);
359
360 PropertyValue[] storeProps = new PropertyValue[2];
361 storeProps[0] = new PropertyValue();
362 storeProps[0].Name = "FilterName";
363 storeProps[0].Value = filterName.get(extName);
364 storeProps[1] = new PropertyValue();
365 storeProps[1].Name = "Overwrite";
366 storeProps[1].Value = new Boolean(true);

--- 9 unchanged lines hidden (view full) ---

376 * @throws Exception
377 */
378 public static void closeFile(XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
379 XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xSpreadsheetDocument);
380 xCloseable.close(false);
381 }
382
383 /**
406
407 PropertyValue[] storeProps = new PropertyValue[2];
408 storeProps[0] = new PropertyValue();
409 storeProps[0].Name = "FilterName";
410 storeProps[0].Value = filterName.get(extName);
411 storeProps[1] = new PropertyValue();
412 storeProps[1].Name = "Overwrite";
413 storeProps[1].Value = new Boolean(true);

--- 9 unchanged lines hidden (view full) ---

423 * @throws Exception
424 */
425 public static void closeFile(XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
426 XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xSpreadsheetDocument);
427 xCloseable.close(false);
428 }
429
430 /**
384 * Close a opening file saved in testspace/output direction and reopen it in Spreadsheet. For save&reload test scenario only.
431 * Close a opening file saved in spreadsheet temp file direction and reopen it in Spreadsheet. For save&reload test scenario only.
385 * @param unoApp
386 * @param xSpreadsheetDocument
387 * @param fullFileName File name with the extension name. (e.g. "sc.ods")
388 * @return
389 * @throws Exception
390 */
391 public static XSpreadsheetDocument reloadFile(UnoApp unoApp, XSpreadsheetDocument xSpreadsheetDocument, String fullFileName) throws Exception {
392 closeFile(xSpreadsheetDocument);
393
432 * @param unoApp
433 * @param xSpreadsheetDocument
434 * @param fullFileName File name with the extension name. (e.g. "sc.ods")
435 * @return
436 * @throws Exception
437 */
438 public static XSpreadsheetDocument reloadFile(UnoApp unoApp, XSpreadsheetDocument xSpreadsheetDocument, String fullFileName) throws Exception {
439 closeFile(xSpreadsheetDocument);
440
394 String filePath = Testspace.getPath("output/" + fullFileName);
441 String filePath = Testspace.getPath(scTempDir + fullFileName);
395 XSpreadsheetDocument xScDocument = UnoRuntime.queryInterface(XSpreadsheetDocument.class, unoApp.loadDocument(filePath));
396
397 return xScDocument;
398 }
399
400 /**
401 * Initial the filter name list
402 * @throws Exception

--- 14 unchanged lines hidden ---
442 XSpreadsheetDocument xScDocument = UnoRuntime.queryInterface(XSpreadsheetDocument.class, unoApp.loadDocument(filePath));
443
444 return xScDocument;
445 }
446
447 /**
448 * Initial the filter name list
449 * @throws Exception

--- 14 unchanged lines hidden ---