View | Details | Raw Unified | Return to issue 120655
Collapse All | Expand All

(-)C:/Users/IBM_ADMIN/workspace/testuno/source/testlib/uno/SCUtil.java (-118 / +282 lines)
Lines 19-25 Link Here
19
 * 
19
 * 
20
 *************************************************************/
20
 *************************************************************/
21
21
22
23
package testlib.uno;
22
package testlib.uno;
24
23
25
import java.util.HashMap;
24
import java.util.HashMap;
Lines 29-34 Link Here
29
28
30
import com.sun.star.beans.PropertyValue;
29
import com.sun.star.beans.PropertyValue;
31
import com.sun.star.container.XIndexAccess;
30
import com.sun.star.container.XIndexAccess;
31
import com.sun.star.container.XNamed;
32
import com.sun.star.frame.XController;
32
import com.sun.star.frame.XController;
33
import com.sun.star.frame.XModel;
33
import com.sun.star.frame.XModel;
34
import com.sun.star.frame.XStorable;
34
import com.sun.star.frame.XStorable;
Lines 46-161 Link Here
46
import com.sun.star.uno.UnoRuntime;
46
import com.sun.star.uno.UnoRuntime;
47
import com.sun.star.util.XCloseable;
47
import com.sun.star.util.XCloseable;
48
48
49
50
/**
49
/**
51
 * Utilities of Spreadsheet
50
 * Utilities of Spreadsheet
51
 * 
52
 * @author test
52
 * @author test
53
 *
53
 * 
54
 */
54
 */
55
55
56
public class SCUtil {
56
public class SCUtil {
57
	
57
58
	private static HashMap filterName = new HashMap(); 
58
	private static HashMap filterName = new HashMap();
59
	
59
60
	private SCUtil() {
60
	private SCUtil() {
61
		
61
62
	}
62
	}
63
	
63
64
	/**
64
	/**
65
	 * Get spreadsheet document object
65
	 * Get spreadsheet document object
66
	 * 
66
	 * @param xSpreadsheetComponent
67
	 * @param xSpreadsheetComponent
67
	 * @return
68
	 * @return
68
	 * @throws Exception
69
	 * @throws Exception
69
	 */
70
	 */
70
    public static XSpreadsheetDocument getSCDocument(XComponent xSpreadsheetComponent) throws Exception {
71
	public static XSpreadsheetDocument getSCDocument(
71
    	XSpreadsheetDocument xSpreadsheetDocument = 
72
			XComponent xSpreadsheetComponent) throws Exception {
72
        		(XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSpreadsheetComponent);
73
		XSpreadsheetDocument xSpreadsheetDocument = (XSpreadsheetDocument) UnoRuntime
73
        
74
				.queryInterface(XSpreadsheetDocument.class,
74
        return xSpreadsheetDocument;
75
						xSpreadsheetComponent);
75
    }
76
76
	
77
		return xSpreadsheetDocument;
77
    /**
78
	}
78
     * Get sheet object by sheet name
79
79
     * @param xSpreadsheetDocument
80
	/**
80
     * @param sheetName 
81
	 * Get sheet object by sheet name
81
     * @return
82
	 * 
82
     * @throws Exception
83
	 * @param xSpreadsheetDocument
83
     */
84
	 * @param sheetName
84
	public static XSpreadsheet getSCSheetByName(XSpreadsheetDocument xSpreadsheetDocument, String sheetName) throws Exception {
85
	 * @return
86
	 * @throws Exception
87
	 */
88
	public static XSpreadsheet getSCSheetByName(
89
			XSpreadsheetDocument xSpreadsheetDocument, String sheetName)
90
			throws Exception {
85
		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
91
		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
86
		XSpreadsheet xSpreadsheet = 
92
		XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
87
				(XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, xSpreadsheets.getByName(sheetName));
93
				XSpreadsheet.class, xSpreadsheets.getByName(sheetName));
88
		
94
89
		return xSpreadsheet;
95
		return xSpreadsheet;
90
	}
96
	}
91
	
97
92
	/**
98
	/**
93
	 * Get sheet object by sheet index
99
	 * Get sheet object by sheet index
100
	 * 
94
	 * @param xSpreadsheetDocument
101
	 * @param xSpreadsheetDocument
95
	 * @param index   (Short) 0,1,2,...
102
	 * @param index
103
	 *            (Short) 0,1,2,...
96
	 * @return
104
	 * @return
97
	 * @throws Exception
105
	 * @throws Exception
98
	 */
106
	 */
99
	public static XSpreadsheet getSCSheetByIndex(XSpreadsheetDocument xSpreadsheetDocument, short index) throws Exception {
107
	public static XSpreadsheet getSCSheetByIndex(
108
			XSpreadsheetDocument xSpreadsheetDocument, short index)
109
			throws Exception {
100
		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
110
		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
101
		XIndexAccess xIndexAccess = 
111
		XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
102
				(XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
112
				XIndexAccess.class, xSpreadsheets);
103
		XSpreadsheet xSpreadsheet = 
113
		XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
104
				(XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, xIndexAccess.getByIndex(index));
114
				XSpreadsheet.class, xIndexAccess.getByIndex(index));
105
		
115
106
		return xSpreadsheet;
116
		return xSpreadsheet;
107
	}
117
	}
108
	
118
109
	/**
119
	/**
120
	 * Get sheet object by sheet index
121
	 * 
122
	 * @param xSpreadsheetDocument
123
	 * @return
124
	 * @throws Exception
125
	 */
126
	public static XSpreadsheet getSCActiveSheet(
127
			XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
128
		XModel xSpreadsheetModel = (XModel) UnoRuntime.queryInterface(
129
				XModel.class, xSpreadsheetDocument);
130
		XSpreadsheetView xSpeadsheetView = (XSpreadsheetView) UnoRuntime
131
				.queryInterface(XSpreadsheetView.class,
132
						xSpreadsheetModel.getCurrentController());
133
		return xSpeadsheetView.getActiveSheet();
134
	}
135
136
	/**
137
	 * Get sheet object by sheet index
138
	 * 
139
	 * @param xSpreadsheetDocument
140
	 * @return
141
	 * @throws Exception
142
	 */
143
	public static String getSCActiveSheetName(
144
			XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
145
		XModel xSpreadsheetModel = (XModel) UnoRuntime.queryInterface(
146
				XModel.class, xSpreadsheetDocument);
147
		XSpreadsheetView xSpeadsheetView = (XSpreadsheetView) UnoRuntime
148
				.queryInterface(XSpreadsheetView.class,
149
						xSpreadsheetModel.getCurrentController());
150
		XSpreadsheet activesheet = xSpeadsheetView.getActiveSheet();
151
		XNamed activesheetName = (XNamed) UnoRuntime.queryInterface(
152
				XNamed.class, activesheet);
153
		return activesheetName.getName();
154
	}
155
156
	/**
157
	 * Get sheet name by sheet index
158
	 * 
159
	 * @param xSpreadsheetDocument
160
	 * @param index
161
	 *            (Short) 0,1,2,...
162
	 * @return
163
	 * @throws Exception
164
	 */
165
	public static String getSCSheetNameByIndex(
166
			XSpreadsheetDocument xSpreadsheetDocument, short index)
167
			throws Exception {
168
		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
169
		XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
170
				XIndexAccess.class, xSpreadsheets);
171
		XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
172
				XSpreadsheet.class, xIndexAccess.getByIndex(index));
173
		XNamed xsheetname = (XNamed) UnoRuntime.queryInterface(XNamed.class,
174
				xSpreadsheet);
175
		return xsheetname.getName();
176
	}
177
178
	/**
179
	 * Set sheet name by sheet index
180
	 * 
181
	 * @param xSpreadsheetDocument
182
	 * @param index
183
	 *            (Short) 0,1,2,...
184
	 * @return
185
	 * @throws Exception
186
	 */
187
	public static void setSCSheetNameByIndex(
188
			XSpreadsheetDocument xSpreadsheetDocument, short index,
189
			String sheetname) throws Exception {
190
		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
191
		XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
192
				XIndexAccess.class, xSpreadsheets);
193
		XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
194
				XSpreadsheet.class, xIndexAccess.getByIndex(index));
195
		XNamed xsheetname = (XNamed) UnoRuntime.queryInterface(XNamed.class,
196
				xSpreadsheet);
197
		xsheetname.setName(sheetname);
198
	}
199
200
	/**
110
	 * Get rows object
201
	 * Get rows object
202
	 * 
111
	 * @param xSpreadsheet
203
	 * @param xSpreadsheet
112
	 * @return
204
	 * @return
113
	 * @throws Exception
205
	 * @throws Exception
114
	 */
206
	 */
115
	public static XTableRows getSCRows(XSpreadsheet xSpreadsheet) throws Exception {
207
	public static XTableRows getSCRows(XSpreadsheet xSpreadsheet)
116
		XColumnRowRange xColumnRowRange = 
208
			throws Exception {
117
				(XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
209
		XColumnRowRange xColumnRowRange = (XColumnRowRange) UnoRuntime
210
				.queryInterface(XColumnRowRange.class, xSpreadsheet);
118
		XTableRows xTableRows = xColumnRowRange.getRows();
211
		XTableRows xTableRows = xColumnRowRange.getRows();
119
		
212
120
		return xTableRows;
213
		return xTableRows;
121
	}
214
	}
122
	
215
123
	/**
216
	/**
124
	 * Get columns object
217
	 * Get columns object
218
	 * 
125
	 * @param xSpreadsheet
219
	 * @param xSpreadsheet
126
	 * @return
220
	 * @return
127
	 * @throws Exception
221
	 * @throws Exception
128
	 */
222
	 */
129
	public static XTableColumns getSCColumns(XSpreadsheet xSpreadsheet) throws Exception {
223
	public static XTableColumns getSCColumns(XSpreadsheet xSpreadsheet)
130
		XColumnRowRange xColumnRowRange = 
224
			throws Exception {
131
				(XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
225
		XColumnRowRange xColumnRowRange = (XColumnRowRange) UnoRuntime
226
				.queryInterface(XColumnRowRange.class, xSpreadsheet);
132
		XTableColumns xTableColumns = xColumnRowRange.getColumns();
227
		XTableColumns xTableColumns = xColumnRowRange.getColumns();
133
		
228
134
		return xTableColumns;
229
		return xTableColumns;
135
	}
230
	}
136
	
231
137
	/**
232
	/**
138
	 * Set floating number into specific cell 
233
	 * Set floating number into specific cell
234
	 * 
139
	 * @param xSpreadsheet
235
	 * @param xSpreadsheet
140
	 * @param column
236
	 * @param column
141
	 * @param row
237
	 * @param row
142
	 * @param value
238
	 * @param value
143
	 * @throws Exception
239
	 * @throws Exception
144
	 */
240
	 */
145
	public static void setValueToCell(XSpreadsheet xSpreadsheet, int column, int row, double value) throws Exception {
241
	public static void setValueToCell(XSpreadsheet xSpreadsheet, int column,
242
			int row, double value) throws Exception {
146
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
243
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
147
		xCell.setValue(value);
244
		xCell.setValue(value);
148
	}
245
	}
149
	
246
150
	/**
247
	/**
151
	 * Set text into specific cell
248
	 * Set text into specific cell
249
	 * 
152
	 * @param xSpreadsheet
250
	 * @param xSpreadsheet
153
	 * @param column
251
	 * @param column
154
	 * @param row
252
	 * @param row
155
	 * @param text
253
	 * @param text
156
	 * @throws Exception
254
	 * @throws Exception
157
	 */
255
	 */
158
	public static void setTextToCell(XSpreadsheet xSpreadsheet, int column, int row, String text) throws Exception {
256
	public static void setTextToCell(XSpreadsheet xSpreadsheet, int column,
257
			int row, String text) throws Exception {
159
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
258
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
160
		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
259
		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
161
		xText.setString(text);
260
		xText.setString(text);
Lines 163-196 Link Here
163
262
164
	/**
263
	/**
165
	 * Set formula into specific cell
264
	 * Set formula into specific cell
265
	 * 
166
	 * @param xSpreadsheet
266
	 * @param xSpreadsheet
167
	 * @param column
267
	 * @param column
168
	 * @param row
268
	 * @param row
169
	 * @param formula
269
	 * @param formula
170
	 * @throws Exception
270
	 * @throws Exception
171
	 */
271
	 */
172
	public static void setFormulaToCell(XSpreadsheet xSpreadsheet, int column, int row, String formula) throws Exception {
272
	public static void setFormulaToCell(XSpreadsheet xSpreadsheet, int column,
273
			int row, String formula) throws Exception {
173
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
274
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
174
		xCell.setFormula(formula);
275
		xCell.setFormula(formula);
175
	}
276
	}
176
	
277
177
	/**
278
	/**
178
	 * Get value from specific cell
279
	 * Get value from specific cell
280
	 * 
179
	 * @param xSpreadsheet
281
	 * @param xSpreadsheet
180
	 * @param column
282
	 * @param column
181
	 * @param row
283
	 * @param row
182
	 * @return
284
	 * @return
183
	 * @throws Exception
285
	 * @throws Exception
184
	 */
286
	 */
185
	public static double getValueFromCell(XSpreadsheet xSpreadsheet, int column, int row) throws Exception {
287
	public static double getValueFromCell(XSpreadsheet xSpreadsheet,
288
			int column, int row) throws Exception {
186
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
289
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
187
		double cellValue = xCell.getValue();
290
		double cellValue = xCell.getValue();
188
		
291
189
		return cellValue;
292
		return cellValue;
190
	}
293
	}
191
	
294
192
	/**
295
	/**
193
	 * Get text from specific cell
296
	 * Get text from specific cell
297
	 * 
194
	 * @param xSpreadsheet
298
	 * @param xSpreadsheet
195
	 * @param column
299
	 * @param column
196
	 * @param row
300
	 * @param row
Lines 198-227 Link Here
198
	 * @return
302
	 * @return
199
	 * @throws Exception
303
	 * @throws Exception
200
	 */
304
	 */
201
	public static String getTextFromCell(XSpreadsheet xSpreadsheet, int column, int row) throws Exception {
305
	public static String getTextFromCell(XSpreadsheet xSpreadsheet, int column,
306
			int row) throws Exception {
202
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
307
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
203
		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
308
		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
204
		
309
205
		return xText.getString();
310
		return xText.getString();
206
	}
311
	}
207
	
312
208
	/**
313
	/**
209
	 * Get formula string from specific cell
314
	 * Get formula string from specific cell
315
	 * 
210
	 * @param xSpreadsheet
316
	 * @param xSpreadsheet
211
	 * @param column
317
	 * @param column
212
	 * @param row
318
	 * @param row
213
	 * @return
319
	 * @return
214
	 * @throws Exception
320
	 * @throws Exception
215
	 */
321
	 */
216
	public static String getFormulaFromCell(XSpreadsheet xSpreadsheet, int column, int row) throws Exception {
322
	public static String getFormulaFromCell(XSpreadsheet xSpreadsheet,
323
			int column, int row) throws Exception {
217
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
324
		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
218
		String cellFormula = xCell.getFormula();
325
		String cellFormula = xCell.getFormula();
219
		
326
220
		return cellFormula;
327
		return cellFormula;
221
	}
328
	}
222
	
329
223
	/**
330
	/**
224
	 * Set numbers into a cell range
331
	 * Set numbers into a cell range
332
	 * 
225
	 * @param xSpreadsheet
333
	 * @param xSpreadsheet
226
	 * @param start_col
334
	 * @param start_col
227
	 * @param start_row
335
	 * @param start_row
Lines 230-248 Link Here
230
	 * @param values
338
	 * @param values
231
	 * @throws Exception
339
	 * @throws Exception
232
	 */
340
	 */
233
	public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row,  double[][] values) throws Exception {
341
	public static void setValueToCellRange(XSpreadsheet xSpreadsheet,
234
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
342
			int start_col, int start_row, int end_col, int end_row,
343
			double[][] values) throws Exception {
344
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col,
345
				start_row, end_col, end_row);
235
		XCell xCell = null;
346
		XCell xCell = null;
236
		for (int i = 0; i <= (end_row - start_row); i++ ) {
347
		for (int i = 0; i <= (end_row - start_row); i++) {
237
			for(int j = 0; j <= (end_col - start_col); j++) {
348
			for (int j = 0; j <= (end_col - start_col); j++) {
238
				xCell = xCellRange.getCellByPosition(j, i);
349
				xCell = xCellRange.getCellByPosition(j, i);
239
				xCell.setValue(values[i][j]);
350
				xCell.setValue(values[i][j]);
240
			}
351
			}
241
		}
352
		}
242
	}
353
	}
243
	
354
244
	/**
355
	/**
245
	 * Set text into a cell range
356
	 * Set text into a cell range
357
	 * 
246
	 * @param xSpreadsheet
358
	 * @param xSpreadsheet
247
	 * @param start_col
359
	 * @param start_col
248
	 * @param start_row
360
	 * @param start_row
Lines 251-271 Link Here
251
	 * @param texts
363
	 * @param texts
252
	 * @throws Exception
364
	 * @throws Exception
253
	 */
365
	 */
254
	public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row,  String[][] texts) throws Exception {
366
	public static void setTextToCellRange(XSpreadsheet xSpreadsheet,
255
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
367
			int start_col, int start_row, int end_col, int end_row,
368
			String[][] texts) throws Exception {
369
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col,
370
				start_row, end_col, end_row);
256
		XCell xCell = null;
371
		XCell xCell = null;
257
		XText xText = null;
372
		XText xText = null;
258
		for (int i = 0; i <= (end_row - start_row); i++ ) {
373
		for (int i = 0; i <= (end_row - start_row); i++) {
259
			for(int j = 0; j <= (end_col - start_col); j++) {
374
			for (int j = 0; j <= (end_col - start_col); j++) {
260
				xCell = xCellRange.getCellByPosition(j, i);
375
				xCell = xCellRange.getCellByPosition(j, i);
261
				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
376
				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
262
				xText.setString(texts[i][j]);
377
				xText.setString(texts[i][j]);
263
			}
378
			}
264
		}
379
		}
265
	}
380
	}
266
	
381
267
	/**
382
	/**
268
	 * Get number content from a cell range
383
	 * Get number content from a cell range
384
	 * 
269
	 * @param xSpreadsheet
385
	 * @param xSpreadsheet
270
	 * @param start_col
386
	 * @param start_col
271
	 * @param start_row
387
	 * @param start_row
Lines 274-296 Link Here
274
	 * @return
390
	 * @return
275
	 * @throws Exception
391
	 * @throws Exception
276
	 */
392
	 */
277
	public static double[][] getValueFromCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row) throws Exception {
393
	public static double[][] getValueFromCellRange(XSpreadsheet xSpreadsheet,
278
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
394
			int start_col, int start_row, int end_col, int end_row)
395
			throws Exception {
396
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col,
397
				start_row, end_col, end_row);
279
		XCell xCell = null;
398
		XCell xCell = null;
280
		double[][] cellValues = new double[end_row - start_row+1][end_col - start_col +1];
399
		double[][] cellValues = new double[end_row - start_row + 1][end_col
281
		
400
				- start_col + 1];
282
		for (int i = 0; i <= (end_row - start_row); i++ ) {
401
283
			for(int j = 0; j <= (end_col - start_col); j++) {
402
		for (int i = 0; i <= (end_row - start_row); i++) {
403
			for (int j = 0; j <= (end_col - start_col); j++) {
284
				xCell = xCellRange.getCellByPosition(j, i);
404
				xCell = xCellRange.getCellByPosition(j, i);
285
				cellValues[i][j] = xCell.getValue();
405
				cellValues[i][j] = xCell.getValue();
286
			}
406
			}
287
		}
407
		}
288
		
408
289
		return cellValues;
409
		return cellValues;
290
	}
410
	}
291
	
411
292
	/**
412
	/**
293
	 * Get text content from a cell range
413
	 * Get text content from a cell range
414
	 * 
294
	 * @param xSpreadsheet
415
	 * @param xSpreadsheet
295
	 * @param start_col
416
	 * @param start_col
296
	 * @param start_row
417
	 * @param start_row
Lines 299-362 Link Here
299
	 * @return
420
	 * @return
300
	 * @throws Exception
421
	 * @throws Exception
301
	 */
422
	 */
302
	public static String[][] getTextFromCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row) throws Exception {
423
	public static String[][] getTextFromCellRange(XSpreadsheet xSpreadsheet,
303
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
424
			int start_col, int start_row, int end_col, int end_row)
425
			throws Exception {
426
		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col,
427
				start_row, end_col, end_row);
304
		XCell xCell = null;
428
		XCell xCell = null;
305
		XText xText = null;
429
		XText xText = null;
306
		String[][] cellTexts = new String[end_row - start_row+1][end_col - start_col +1];
430
		String[][] cellTexts = new String[end_row - start_row + 1][end_col
307
		
431
				- start_col + 1];
308
		for (int i = 0; i <= (end_row - start_row); i++ ) {
432
309
			for(int j = 0; j <= (end_col - start_col); j++) {
433
		for (int i = 0; i <= (end_row - start_row); i++) {
434
			for (int j = 0; j <= (end_col - start_col); j++) {
310
				xCell = xCellRange.getCellByPosition(j, i);
435
				xCell = xCellRange.getCellByPosition(j, i);
311
				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
436
				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
312
				cellTexts[i][j] = xText.getString();
437
				cellTexts[i][j] = xText.getString();
313
			}
438
			}
314
		}
439
		}
315
		
440
316
		return cellTexts;
441
		return cellTexts;
317
	}
442
	}
318
		
443
319
	//TODO ZS - public static String[][] getAllFromCellRange
444
	// TODO ZS - public static String[][] getAllFromCellRange
320
	
445
321
	/**
446
	/**
322
	 * Switch to specific sheet
447
	 * Switch to specific sheet
448
	 * 
323
	 * @param xSpreadsheetDocument
449
	 * @param xSpreadsheetDocument
324
	 * @param xSpreadsheet
450
	 * @param xSpreadsheet
325
	 */
451
	 */
326
	public static void setCurrentSheet(XSpreadsheetDocument xSpreadsheetDocument, XSpreadsheet xSpreadsheet) throws Exception {
452
	public static void setCurrentSheet(
327
		XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xSpreadsheetDocument);
453
			XSpreadsheetDocument xSpreadsheetDocument, XSpreadsheet xSpreadsheet)
454
			throws Exception {
455
		XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class,
456
				xSpreadsheetDocument);
328
		XController xController = xModel.getCurrentController();
457
		XController xController = xModel.getCurrentController();
329
		XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, xController);
458
		XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) UnoRuntime
459
				.queryInterface(XSpreadsheetView.class, xController);
330
		xSpreadsheetView.setActiveSheet(xSpreadsheet);
460
		xSpreadsheetView.setActiveSheet(xSpreadsheet);
331
	}
461
	}
332
	
462
333
	/**
463
	/**
334
	 * Get sheet object of current active sheet
464
	 * Get sheet object of current active sheet
465
	 * 
335
	 * @param xSpreadsheetDocument
466
	 * @param xSpreadsheetDocument
336
	 * @return
467
	 * @return
337
	 */
468
	 */
338
	public static XSpreadsheet getCurrentSheet(XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
469
	public static XSpreadsheet getCurrentSheet(
339
		XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xSpreadsheetDocument);
470
			XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
471
		XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class,
472
				xSpreadsheetDocument);
340
		XController xController = xModel.getCurrentController();
473
		XController xController = xModel.getCurrentController();
341
		XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, xController);
474
		XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) UnoRuntime
475
				.queryInterface(XSpreadsheetView.class, xController);
342
		XSpreadsheet xSpreadsheet = xSpreadsheetView.getActiveSheet();
476
		XSpreadsheet xSpreadsheet = xSpreadsheetView.getActiveSheet();
343
		
477
344
		return xSpreadsheet;
478
		return xSpreadsheet;
345
	}
479
	}
346
	
480
347
	/**
481
	/**
482
	 * Save file after open file.
483
	 * 
484
	 * @param xSpreadsheetDocument
485
	 * @throws Exception
486
	 */
487
	public static void save(XSpreadsheetDocument xSpreadsheetDocument)
488
			throws Exception {
489
490
		XStorable scStorable = (XStorable) UnoRuntime.queryInterface(
491
				XStorable.class, xSpreadsheetDocument);
492
		scStorable.store();
493
494
	}
495
496
	/**
348
	 * Save file as specific file format into testspace/output folder.
497
	 * Save file as specific file format into testspace/output folder.
498
	 * 
349
	 * @param scComponent
499
	 * @param scComponent
350
	 * @param fileName  File name string without extension name (e.g. "sampleFile")
500
	 * @param fileName
351
	 * @param extName ("ods", "ots", "xls", "xlt", "csv")
501
	 *            File name string without extension name (e.g. "sampleFile")
502
	 * @param extName
503
	 *            ("ods", "ots", "xls", "xlt", "csv")
352
	 * @throws Exception
504
	 * @throws Exception
353
	 */
505
	 */
354
	public static void saveFileAs(XComponent scComponent, String fileName, String extName) throws Exception {
506
	public static void saveFileAs(XComponent scComponent, String fileName,
355
		
507
			String extName) throws Exception {
508
356
		initFilterName();
509
		initFilterName();
357
510
358
		String storeUrl = Testspace.getUrl("output/" + fileName + "." + extName);
511
		String storeUrl = Testspace
359
		
512
				.getUrl("output/" + fileName + "." + extName);
513
360
		PropertyValue[] storeProps = new PropertyValue[2];
514
		PropertyValue[] storeProps = new PropertyValue[2];
361
		storeProps[0] = new PropertyValue();
515
		storeProps[0] = new PropertyValue();
362
		storeProps[0].Name = "FilterName";
516
		storeProps[0].Name = "FilterName";
Lines 364-411 Link Here
364
		storeProps[1] = new PropertyValue();
518
		storeProps[1] = new PropertyValue();
365
		storeProps[1].Name = "Overwrite";
519
		storeProps[1].Name = "Overwrite";
366
		storeProps[1].Value = new Boolean(true);
520
		storeProps[1].Value = new Boolean(true);
367
		
521
368
		XStorable scStorable = 
522
		XStorable scStorable = (XStorable) UnoRuntime.queryInterface(
369
				(XStorable) UnoRuntime.queryInterface(XStorable.class, scComponent);
523
				XStorable.class, scComponent);
370
		scStorable.storeAsURL(storeUrl, storeProps);
524
		scStorable.storeAsURL(storeUrl, storeProps);
371
	}
525
	}
372
	
526
373
	/**
527
	/**
374
	 * Close specific opening spreadsheet file which has been saved
528
	 * Close specific opening spreadsheet file which has been saved
529
	 * 
375
	 * @param xSpreadsheetDocument
530
	 * @param xSpreadsheetDocument
376
	 * @throws Exception
531
	 * @throws Exception
377
	 */
532
	 */
378
	public static void closeFile(XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
533
	public static void closeFile(XSpreadsheetDocument xSpreadsheetDocument)
379
		XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xSpreadsheetDocument);
534
			throws Exception {
535
		XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(
536
				XCloseable.class, xSpreadsheetDocument);
380
		xCloseable.close(false);
537
		xCloseable.close(false);
381
	}
538
	}
382
	
539
383
	/**
540
	/**
384
	 * Close a opening file saved in testspace/output direction and reopen it in Spreadsheet. For save&reload test scenario only.
541
	 * Close a opening file saved in testspace/output direction and reopen it in
542
	 * Spreadsheet. For save&reload test scenario only.
543
	 * 
385
	 * @param unoApp
544
	 * @param unoApp
386
	 * @param xSpreadsheetDocument
545
	 * @param xSpreadsheetDocument
387
	 * @param fullFileName   File name with the extension name. (e.g. "sc.ods")
546
	 * @param fullFileName
547
	 *            File name with the extension name. (e.g. "sc.ods")
388
	 * @return
548
	 * @return
389
	 * @throws Exception
549
	 * @throws Exception
390
	 */
550
	 */
391
	public static XSpreadsheetDocument reloadFile(UnoApp unoApp, XSpreadsheetDocument xSpreadsheetDocument, String fullFileName) throws Exception {
551
	public static XSpreadsheetDocument reloadFile(UnoApp unoApp,
552
			XSpreadsheetDocument xSpreadsheetDocument, String fullFileName)
553
			throws Exception {
392
		closeFile(xSpreadsheetDocument);
554
		closeFile(xSpreadsheetDocument);
393
		
555
394
		String filePath = Testspace.getPath("output/" + fullFileName);
556
		String filePath = Testspace.getPath("output/" + fullFileName);
395
		XSpreadsheetDocument xScDocument = UnoRuntime.queryInterface(XSpreadsheetDocument.class, unoApp.loadDocument(filePath));
557
		XSpreadsheetDocument xScDocument = UnoRuntime.queryInterface(
396
		
558
				XSpreadsheetDocument.class, unoApp.loadDocument(filePath));
559
397
		return xScDocument;
560
		return xScDocument;
398
	}
561
	}
399
	
562
400
	/**
563
	/**
401
	 * Initial the filter name list
564
	 * Initial the filter name list
565
	 * 
402
	 * @throws Exception
566
	 * @throws Exception
403
	 */
567
	 */
404
	private static void initFilterName() throws Exception {
568
	private static void initFilterName() throws Exception {
405
		if (filterName.size() > 0) {
569
		if (filterName.size() > 0) {
406
			return;
570
			return;
407
		}
571
		}
408
		
572
409
		filterName.put("ods", "calc8");
573
		filterName.put("ods", "calc8");
410
		filterName.put("ots", "calc8_template");
574
		filterName.put("ots", "calc8_template");
411
		filterName.put("xls", "MS Excel 97");
575
		filterName.put("xls", "MS Excel 97");
(-)C:/Users/IBM_ADMIN/workspace/testuno/source/testcase/uno/sc/sheet/SheetBasicTest.java (-132 / +241 lines)
Lines 28-35 Link Here
28
import org.openoffice.test.common.FileUtil;
28
import org.openoffice.test.common.FileUtil;
29
import org.openoffice.test.common.Testspace;
29
import org.openoffice.test.common.Testspace;
30
import org.openoffice.test.uno.UnoApp;
30
import org.openoffice.test.uno.UnoApp;
31
31
import testlib.uno.SCUtil;
32
import com.sun.star.beans.Property;
33
import com.sun.star.beans.PropertyAttribute;
32
import com.sun.star.beans.PropertyValue;
34
import com.sun.star.beans.PropertyValue;
35
import com.sun.star.beans.XPropertySet;
36
import com.sun.star.beans.XPropertySetInfo;
33
import com.sun.star.container.XIndexAccess;
37
import com.sun.star.container.XIndexAccess;
34
import com.sun.star.container.XNamed;
38
import com.sun.star.container.XNamed;
35
import com.sun.star.frame.XModel;
39
import com.sun.star.frame.XModel;
Lines 38-43 Link Here
38
import com.sun.star.lang.IndexOutOfBoundsException;
42
import com.sun.star.lang.IndexOutOfBoundsException;
39
import com.sun.star.lang.WrappedTargetException;
43
import com.sun.star.lang.WrappedTargetException;
40
import com.sun.star.lang.XComponent;
44
import com.sun.star.lang.XComponent;
45
import com.sun.star.sheet.SheetLinkMode;
46
import com.sun.star.sheet.XExternalDocLink;
47
import com.sun.star.sheet.XExternalDocLinks;
48
import com.sun.star.sheet.XSheetLinkable;
41
import com.sun.star.sheet.XSpreadsheet;
49
import com.sun.star.sheet.XSpreadsheet;
42
import com.sun.star.sheet.XSpreadsheetDocument;
50
import com.sun.star.sheet.XSpreadsheetDocument;
43
import com.sun.star.sheet.XSpreadsheetView;
51
import com.sun.star.sheet.XSpreadsheetView;
Lines 77-278 Link Here
77
	public void insertRenameDeleteSheet() throws Exception {
85
	public void insertRenameDeleteSheet() throws Exception {
78
		// Insert a sheet named aa after first sheet
86
		// Insert a sheet named aa after first sheet
79
		String sheetname = "aa";
87
		String sheetname = "aa";
80
		scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(
88
		scDocument = SCUtil.getSCDocument(scComponent);
81
				XSpreadsheetDocument.class, scComponent);
82
		XSpreadsheets spreadsheets = scDocument.getSheets();
89
		XSpreadsheets spreadsheets = scDocument.getSheets();
83
		spreadsheets.insertNewByName(sheetname, (short) 1);
90
		spreadsheets.insertNewByName(sheetname, (short) 1);
84
91
85
		// active the sheet second sheet aa
92
		// active the sheet second sheet aa
86
		XIndexAccess xspreadsheetIndex = (XIndexAccess) UnoRuntime
93
		XSpreadsheet newSpreadSheet = SCUtil.getSCSheetByIndex(scDocument,
87
				.queryInterface(XIndexAccess.class, spreadsheets);
94
				(short) 1);
88
		XSpreadsheet newSpreadSheet = (XSpreadsheet) UnoRuntime.queryInterface(
95
		SCUtil.setCurrentSheet(scDocument, newSpreadSheet);
89
				XSpreadsheet.class, xspreadsheetIndex.getByIndex(1));
90
		XModel xSpreadsheetModel = (XModel) UnoRuntime.queryInterface(
91
				XModel.class, scDocument);
92
		XSpreadsheetView xSpeadsheetView = (XSpreadsheetView) UnoRuntime
93
				.queryInterface(XSpreadsheetView.class,
94
						xSpreadsheetModel.getCurrentController());
95
		xSpeadsheetView.setActiveSheet(newSpreadSheet);
96
96
97
		// get the new speadsheet name
97
		// get the new speadsheet name
98
		XNamed xsheetname = (XNamed) UnoRuntime.queryInterface(XNamed.class,
98
		assertEquals("actual should equals aa", sheetname,
99
				newSpreadSheet);
99
				SCUtil.getSCSheetNameByIndex(scDocument, (short) 1));
100
		assertEquals("actual should equals aa", sheetname, xsheetname.getName());
101
100
102
		// Change the Spreadsheet name
101
		// Change the Spreadsheet name
103
		String changedname = "SpeadsheetAfterChange";
102
		String changedname = "SpeadsheetAfterChange";
104
		xsheetname.setName(changedname);
103
		SCUtil.setSCSheetNameByIndex(scDocument, (short) 1, changedname);
105
104
106
		// Save and reload document
105
		// Save and reload document
107
		reloadSpreadsheet("TestSpreadsheet.xls");
106
		SCUtil.saveFileAs(scComponent, "TestSpreadsheet", "ods");
107
		XSpreadsheetDocument scDocumentTemp = SCUtil.reloadFile(unoApp,
108
				scDocument, "TestSpreadsheet.ods");
108
109
110
		scDocument = scDocumentTemp;
111
		String sheetnameaftermove = SCUtil.getSCSheetNameByIndex(scDocument,
112
				(short) 1);
113
109
		// Verify the changed Spreadsheet name
114
		// Verify the changed Spreadsheet name
110
		assertEquals("actual should equals SpeadsheetAfterChange", changedname,
115
		assertEquals("actual should equals SpeadsheetAfterChange", changedname,
111
				xsheetname.getName());
116
				sheetnameaftermove);
112
117
113
		spreadsheets.removeByName(changedname);
118
		scDocument.getSheets().removeByName(changedname);
114
119
115
		assertFalse("actual should equals false",
120
		assertFalse("actual should equals false",
116
				spreadsheets.hasByName(changedname));
121
				spreadsheets.hasByName(changedname));
117
122
		SCUtil.save(scDocumentTemp);
118
	}
123
	}
119
124
120
	@Test
125
	@Test
121
	public void copypastesheet() throws Exception {
126
	public void copypastesheet() throws Exception {
122
		// Insert some value into cells
127
		// Insert some value into cells
123
		scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(
128
		scDocument = SCUtil.getSCDocument(scComponent);
124
				XSpreadsheetDocument.class, scComponent);
129
		String souceSheetName = "sourcesheet";
125
		XSpreadsheets spreadsheets = scDocument.getSheets();
130
		SCUtil.setSCSheetNameByIndex(scDocument, (short) 0, souceSheetName);
126
		XIndexAccess xspreadsheetIndex = (XIndexAccess) UnoRuntime
127
				.queryInterface(XIndexAccess.class, spreadsheets);
128
		XSpreadsheet spreadSheet = (XSpreadsheet) UnoRuntime.queryInterface(
129
				XSpreadsheet.class, xspreadsheetIndex.getByIndex(0));
130
		XNamed xsheetname = (XNamed) UnoRuntime.queryInterface(XNamed.class,
131
				spreadSheet);
132
		xsheetname.setName("sourcesheet");
133
		String[][] stringValues = { { "", "Jan", "Feb", "Mar", "Apr", "Mai" },
131
		String[][] stringValues = { { "", "Jan", "Feb", "Mar", "Apr", "Mai" },
134
				{ "Profit", "12.3", "43.2", "5.1", "76", "56.8" },
132
				{ "Profit", "12.3", "43.2", "5.1", "76", "56.8" },
135
				{ "Rival in business", "12.2", "12.6", "17.7", "20.4", "100" }, };
133
				{ "Rival in business", "12.2", "12.6", "17.7", "20.4", "100" }, };
134
		XSpreadsheet sourceSpreadSheet = SCUtil.getSCSheetByName(scDocument,
135
				souceSheetName);
136
		// input strings into sheet1
136
		// input strings into sheet1
137
		for (int intY = 0; intY < stringValues.length; intY++) {
137
		SCUtil.setTextToCellRange(sourceSpreadSheet, 0, 0, 5, 2, stringValues);
138
			for (int intX = 0; intX < stringValues[intY].length; intX++) {
139
				// Insert the value to the cell, specified by intY and intX.
140
				this.insertIntoCell(intY, intX, stringValues[intY][intX],
141
						spreadSheet, "");
142
			}
143
		}
144
145
		// copy the sheet from sourcesheet to copysheet
138
		// copy the sheet from sourcesheet to copysheet
146
		String newcopysheet = "copysheet";
139
		String newcopysheet = "copysheet";
147
		spreadsheets.copyByName(xsheetname.getName(), newcopysheet, (short) 2);
140
		XSpreadsheets spreadsheets = scDocument.getSheets();
141
		spreadsheets.copyByName(souceSheetName, newcopysheet, (short) 2);
148
142
149
		// Save and reload document
143
		// Save and reload document
150
		reloadSpreadsheet("TestCopysheet.xls");
144
		SCUtil.saveFileAs(scComponent, "TestCopysheet", "xls");
151
		XModel xSpreadsheetModel = (XModel) UnoRuntime.queryInterface(
145
		XSpreadsheetDocument scDocumentTemp = SCUtil.reloadFile(unoApp,
152
				XModel.class, scDocument);
146
				scDocument, "TestCopysheet.xls");
153
		XSpreadsheetView xSpeadsheetView = (XSpreadsheetView) UnoRuntime
147
		scDocument = scDocumentTemp;
154
				.queryInterface(XSpreadsheetView.class,
155
						xSpreadsheetModel.getCurrentController());
156
		XSpreadsheet copysheet = (XSpreadsheet) UnoRuntime.queryInterface(
157
				XSpreadsheet.class, xspreadsheetIndex.getByIndex(2));
158
		for (int intY = 0; intY < stringValues.length; intY++) {
159
			for (int intX = 0; intX < stringValues[intY].length; intX++) {
160
				XCell xcell = null;
161
				xcell = copysheet.getCellByPosition(intY, intX);
162
				assertEquals(stringValues[intY][intX], xcell.getFormula());
163
			}
164
		}
165
148
149
		XSpreadsheet copysheet = SCUtil
150
				.getSCSheetByIndex(scDocument, (short) 2);
151
		String[][] CopystringValues = SCUtil.getTextFromCellRange(copysheet, 0,
152
				0, 5, 2);
153
		assertArrayEquals("Expect string value should be stringValues",
154
				stringValues, CopystringValues);
155
166
	}
156
	}
167
157
168
	@Test
158
	@Test
169
	public void movesheet() throws Exception {
159
	public void movesheet() throws Exception {
170
160
171
		// new sc document
161
		// new sc document
172
		scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(
162
		scDocument = SCUtil.getSCDocument(scComponent);
173
				XSpreadsheetDocument.class, scComponent);
163
		XSpreadsheets spreadsheets = scDocument.getSheets();
174
164
175
		// change the first sheet name and input same value into the sheet cell
165
		// change the first sheet name and input same value into the sheet cell
176
		XSpreadsheets spreadsheets = scDocument.getSheets();
177
		XIndexAccess xspreadsheetIndex = (XIndexAccess) UnoRuntime
178
				.queryInterface(XIndexAccess.class, spreadsheets);
179
		XSpreadsheet spreadSheet = (XSpreadsheet) UnoRuntime.queryInterface(
180
				XSpreadsheet.class, xspreadsheetIndex.getByIndex(0));
181
		XNamed xsheetname = (XNamed) UnoRuntime.queryInterface(XNamed.class,
182
				spreadSheet);
183
		String sheetname = "sourcesheet";
166
		String sheetname = "sourcesheet";
184
		xsheetname.setName(sheetname);
167
		SCUtil.setSCSheetNameByIndex(scDocument, (short) 0, sheetname);
185
		String[][] stringValues = { { "", "Jan", "Feb", "Mar", "Apr", "Mai" },
168
		String[][] stringValues = { { "", "Jan", "Feb", "Mar", "Apr", "Mai" },
186
				{ "Profit", "12.3", "43.2", "5.1", "76", "56.8" },
169
				{ "Profit", "12.3", "43.2", "5.1", "76", "56.8" },
187
				{ "Rival in business", "12.2", "12.6", "17.7", "20.4", "100" }, };
170
				{ "Rival in business", "12.2", "12.6", "17.7", "20.4", "100" }, };
171
		XSpreadsheet movesheet = SCUtil
172
				.getSCSheetByIndex(scDocument, (short) 0);
173
		SCUtil.setTextToCellRange(movesheet, 0, 0, 5, 2, stringValues);
188
174
189
		for (int intY = 0; intY < stringValues.length; intY++) {
190
			for (int intX = 0; intX < stringValues[intY].length; intX++) {
191
				// Insert the value to the cell, specified by intY and intX.
192
				this.insertIntoCell(intY, intX, stringValues[intY][intX],
193
						spreadSheet, "");
194
			}
195
		}
196
197
		// Before move, get the 2nd sheet name
175
		// Before move, get the 2nd sheet name
198
		XSpreadsheet secondSheetBeforeMove = (XSpreadsheet) UnoRuntime
176
		String secondSheetNameBeforeMove = SCUtil.getSCSheetNameByIndex(
199
				.queryInterface(XSpreadsheet.class,
177
				scDocument, (short) 1);
200
						xspreadsheetIndex.getByIndex(1));
201
		XNamed secondSheetNameBeforeMove = (XNamed) UnoRuntime.queryInterface(
202
				XNamed.class, secondSheetBeforeMove);
203
178
204
		// move the first sheet
179
		// move the first sheet
205
		spreadsheets.moveByName(sheetname, (short) 2);
180
		spreadsheets.moveByName(sheetname, (short) 2);
206
181
207
		// Save and reload document
182
		// Save and reload document
208
		reloadSpreadsheet("Testmovesheet.xls");
183
		SCUtil.saveFileAs(scComponent, "Testmovesheet", "xls");
184
		XSpreadsheetDocument scDocumentTemp = SCUtil.reloadFile(unoApp,
185
				scDocument, "Testmovesheet.xls");
186
		scDocument = scDocumentTemp;
209
187
210
		// After move, get the first sheet name, and verify it same as 2nd sheet
188
		// After move, get the first sheet name, and verify it same as 2nd sheet
211
		// name before move
189
		// name before move
212
		XSpreadsheet firstSheetAfterMove = (XSpreadsheet) UnoRuntime
190
		String firstsheetnameAfterMove = SCUtil.getSCSheetNameByIndex(
213
				.queryInterface(XSpreadsheet.class,
191
				scDocument, (short) 0);
214
						xspreadsheetIndex.getByIndex(0));
215
		XNamed xfirstsheetnameAfterMove = (XNamed) UnoRuntime.queryInterface(
216
				XNamed.class, firstSheetAfterMove);
217
		assertEquals("Expect result should be Sheet2",
192
		assertEquals("Expect result should be Sheet2",
218
				secondSheetNameBeforeMove.getName(),
193
				secondSheetNameBeforeMove, firstsheetnameAfterMove);
219
				xfirstsheetnameAfterMove.getName());
220
194
221
		// Get the target sheet name after move
195
		// Get the target sheet name after move
222
		XSpreadsheet sheetAfterMove = (XSpreadsheet) UnoRuntime.queryInterface(
196
		String sheetnameAfterMove = SCUtil.getSCSheetNameByIndex(scDocument,
223
				XSpreadsheet.class, xspreadsheetIndex.getByIndex(1));
197
				(short) 1);
224
		XNamed xsheetnameAfterMove = (XNamed) UnoRuntime.queryInterface(
225
				XNamed.class, sheetAfterMove);
226
		assertEquals("Expect result should be sourcesheet", sheetname,
198
		assertEquals("Expect result should be sourcesheet", sheetname,
227
				xsheetnameAfterMove.getName());
199
				sheetnameAfterMove);
228
200
229
		// Check the cell value after move
201
		// Check the cell value after move
230
		XModel xSpreadsheetModel = (XModel) UnoRuntime.queryInterface(
202
		XSpreadsheet sheetaftermove = SCUtil.getSCSheetByIndex(scDocument,
231
				XModel.class, scDocument);
203
				(short) 1);
232
		XSpreadsheetView xSpeadsheetView = (XSpreadsheetView) UnoRuntime
204
		String[][] stringValuesaftermove = SCUtil.getTextFromCellRange(
233
				.queryInterface(XSpreadsheetView.class,
205
				sheetaftermove, 0, 0, 5, 2);
234
						xSpreadsheetModel.getCurrentController());
235
		XSpreadsheet movesheet = (XSpreadsheet) UnoRuntime.queryInterface(
236
				XSpreadsheet.class, xspreadsheetIndex.getByIndex(1));
237
		for (int intY = 0; intY < stringValues.length; intY++) {
238
			for (int intX = 0; intX < stringValues[intY].length; intX++) {
239
				XCell xcell = null;
240
				xcell = movesheet.getCellByPosition(intY, intX);
241
				assertEquals(stringValues[intY][intX], xcell.getFormula());
242
			}
243
		}
244
206
207
		assertArrayEquals("Expect result should be stringValues", stringValues,
208
				stringValuesaftermove);
209
245
	}
210
	}
246
211
247
	// input value into sheet cell
212
	@Test
248
	public static void insertIntoCell(int intX, int intY, String stringValue,
213
	public void hideShowSheet() throws Exception {
249
			XSpreadsheet xspreadsheet, String stringFlag)
214
		// Insert a sheet named hide sheet after first sheet
250
			throws IndexOutOfBoundsException {
215
		String sheetname = "hide sheet";
251
		XCell xcell = null;
216
		scDocument = SCUtil.getSCDocument(scComponent);
252
		xcell = xspreadsheet.getCellByPosition(intX, intY);
217
		XSpreadsheets spreadsheets = scDocument.getSheets();
253
		if (stringFlag.equals("V")) {
218
		spreadsheets.insertNewByName(sheetname, (short) 1);
254
			xcell.setValue((new Float(stringValue)).floatValue());
219
255
		} else {
220
		// active the sheet second sheet "hide sheet"
256
			xcell.setFormula(stringValue);
221
		XSpreadsheet secondSpreadSheet = SCUtil.getSCSheetByIndex(scDocument,
257
		}
222
				(short) 1);
223
		SCUtil.setCurrentSheet(scDocument, secondSpreadSheet);
224
		// get second sheet name and verify it should be "hide sheet"
225
		assertEquals("expect active sheet name will be hide sheet", sheetname,
226
				SCUtil.getSCSheetNameByIndex(scDocument, (short) 1));
227
228
		// hide the sheet you insert
229
		XPropertySet sheetPropertySet = (XPropertySet) UnoRuntime
230
				.queryInterface(XPropertySet.class, secondSpreadSheet);
231
		boolean isvisiable = false;
232
		sheetPropertySet.setPropertyValue("IsVisible", isvisiable);
233
234
		// Save and reload document
235
		SCUtil.saveFileAs(scComponent, "Testhideshowsheet", "xls");
236
		XSpreadsheetDocument scDocumentTemp = SCUtil.reloadFile(unoApp,
237
				scDocument, "Testhideshowsheet.xls");
238
		scDocument = scDocumentTemp;
239
240
		// get the active sheet name after hide sheet, it should be Sheet2
241
		String sheet2Name = SCUtil.getSCSheetNameByIndex(scDocument, (short) 2);
242
		String activesheetname = SCUtil.getSCActiveSheetName(scDocument);
243
		assertEquals("Expect sheet name should be Sheet2", sheet2Name,
244
				activesheetname);
245
246
		// show sheet "hide sheet"
247
		sheetPropertySet = (XPropertySet) UnoRuntime.queryInterface(
248
				XPropertySet.class,
249
				SCUtil.getSCSheetByIndex(scDocument, (short) 1));
250
		isvisiable = true;
251
		sheetPropertySet.setPropertyValue("IsVisible", isvisiable);
252
253
		// active sheet "hide sheet"
254
		secondSpreadSheet = SCUtil.getSCSheetByIndex(scDocument, (short) 1);
255
		SCUtil.setCurrentSheet(scDocument, secondSpreadSheet);
256
257
		// Get current active sheet name, verify it same as "hide sheet"
258
		String currentactivesheetname = SCUtil.getSCActiveSheetName(scDocument);
259
		assertEquals("Expect active sheet name is hidesheet", sheetname,
260
				currentactivesheetname);
261
		SCUtil.save(scDocument);
258
	}
262
	}
259
263
260
	// Save and load the document
264
	@Test
261
	public XSpreadsheetDocument reloadSpreadsheet(String spreadSheetname)
265
	public void sheetColor() throws Exception {
262
			throws Exception {
266
		// get first sheet propertyset
263
		String filePath = Testspace.getPath("output/" + spreadSheetname);
267
		scDocument = SCUtil.getSCDocument(scComponent);
264
		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
268
		XSpreadsheets spreadsheets = scDocument.getSheets();
265
				XStorable.class, scDocument);
269
		XSpreadsheet firstSpreadSheet = SCUtil.getSCSheetByIndex(scDocument,
266
		PropertyValue[] aStoreProperties = new PropertyValue[2];
270
				(short) 0);
267
		aStoreProperties[0] = new PropertyValue();
271
		XPropertySet sheet1PropertySet = (XPropertySet) UnoRuntime
268
		aStoreProperties[1] = new PropertyValue();
272
				.queryInterface(XPropertySet.class, firstSpreadSheet);
269
		aStoreProperties[0].Name = "Override";
270
		aStoreProperties[0].Value = true;
271
		aStoreProperties[1].Name = "FilterName";
272
		aStoreProperties[1].Value = "MS Excel 97";
273
		xStorable.storeAsURL(FileUtil.getUrl(filePath), aStoreProperties);
274
273
275
		return UnoRuntime.queryInterface(XSpreadsheetDocument.class,
274
		// Set tabcolor to 111
276
				unoApp.loadDocument(filePath));
275
		sheet1PropertySet.setPropertyValue("TabColor", 111);
276
277
		// copy the color sheet to new sheet
278
		spreadsheets.copyByName(
279
				SCUtil.getSCSheetNameByIndex(scDocument, (short) 0),
280
				"newsheet", (short) 3);
281
282
		// Save and reopen the document
283
		SCUtil.saveFileAs(scComponent, "Testcolorsheet", "ods");
284
		XSpreadsheetDocument scDocumentTemp = SCUtil.reloadFile(unoApp,
285
				scDocument, "Testcolorsheet.ods");
286
		scDocument = scDocumentTemp;
287
288
		// Get first sheet color
289
		sheet1PropertySet = (XPropertySet) UnoRuntime.queryInterface(
290
				XPropertySet.class,
291
				SCUtil.getSCSheetByIndex(scDocument, (short) 0));
292
		int firstSheetcolorid = (int) sheet1PropertySet
293
				.getPropertyValue("TabColor");
294
295
		// Get the copyed sheet color
296
		XPropertySet newsheetPropertySet = (XPropertySet) UnoRuntime
297
				.queryInterface(XPropertySet.class,
298
						SCUtil.getSCSheetByIndex(scDocument, (short) 3));
299
		int copySheetcolorid = (int) newsheetPropertySet
300
				.getPropertyValue("TabColor");
301
302
		// Verify first sheet color changed successfully
303
		assertEquals("Expect color should be 111", 111, firstSheetcolorid);
304
305
		// Verify first sheet color same as copy sheet color
306
		assertEquals("Expect color should be 111", firstSheetcolorid,
307
				copySheetcolorid);
277
	}
308
	}
309
310
	@Test
311
	public void insertSheetFromfile() throws Exception {
312
		// New a document source.xls, add value to 3 sheet
313
		scDocument = SCUtil.getSCDocument(scComponent);
314
		XSpreadsheets spreadsheets = scDocument.getSheets();
315
		XSpreadsheet firstSheet = SCUtil.getSCSheetByIndex(scDocument,
316
				(short) 0);
317
		XSpreadsheet secondSheet = SCUtil.getSCSheetByIndex(scDocument,
318
				(short) 1);
319
		SCUtil.setFormulaToCell(firstSheet, 1, 2, "=2*2");
320
		SCUtil.setFormulaToCell(secondSheet, 1, 2, "=2*2");
321
322
		// Save and close this document
323
		SCUtil.saveFileAs(scComponent, "source", "xls");
324
		SCUtil.closeFile(scDocument);
325
326
		// get source document URL
327
		String SourcestoreUrl = Testspace.getUrl("output/" + "source" + "."
328
				+ "xls");
329
330
		// New a document
331
		scComponent = unoApp.newDocument("scalc");
332
		scDocument = SCUtil.getSCDocument(scComponent);
333
		spreadsheets = scDocument.getSheets();
334
		// Insert firstexternalsheet sheet, link with Sheet1 in source document
335
		// and the link mode is NORMAL
336
		spreadsheets.insertNewByName("firstexternalsheet", (short) 3);
337
		XSpreadsheet firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument,
338
				(short) 3);
339
		XSheetLinkable xfirstSheetLineable = (XSheetLinkable) UnoRuntime
340
				.queryInterface(XSheetLinkable.class, firstexternalsheet);
341
		xfirstSheetLineable.link(SourcestoreUrl, "", "MS Excel 97", "",
342
				SheetLinkMode.NORMAL);
343
344
		// Insert secondexternalsheet sheet, link with Sheet2 in source document
345
		// and the link mode is NONE
346
		spreadsheets.insertNewByName("secondexternalsheet", (short) 4);
347
		XSpreadsheet secondexternalsheet = SCUtil.getSCSheetByIndex(scDocument,
348
				(short) 4);
349
		XSheetLinkable xsecondSheetLineable = (XSheetLinkable) UnoRuntime
350
				.queryInterface(XSheetLinkable.class, secondexternalsheet);
351
		xsecondSheetLineable.link(SourcestoreUrl, "Sheet2", "MS Excel 97", "",
352
				SheetLinkMode.VALUE);
353
354
		// Verify firstexternalsheet
355
		assertEquals("Expect formula should be =2*2", "=2*2",
356
				SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
357
		assertEquals("Expect formula result should be 4", "4",
358
				SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
359
360
		// Verify secondexternalsheet
361
		assertEquals("Expect formula should be 4", "4",
362
				SCUtil.getFormulaFromCell(secondexternalsheet, 1, 2));
363
		assertEquals("Expect formula result should be 4", "4",
364
				SCUtil.getTextFromCell(secondexternalsheet, 1, 2));
365
366
		// save document and verify the linked sheet again
367
		SCUtil.saveFileAs(scComponent, "linked", "ods");
368
		XSpreadsheetDocument tempscDocument = SCUtil.reloadFile(unoApp,
369
				scDocument, "linked.ods");
370
		scDocument = tempscDocument;
371
		firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 3);
372
		secondexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 4);
373
374
		// Verify firstexternalsheet
375
		assertEquals("Expect formula should be =2*2", "=2*2",
376
				SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
377
		assertEquals("Expect formula result should be 4", "4",
378
				SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
379
380
		// Verify secondexternalsheet
381
		assertEquals("Expect formula should be 4", "4",
382
				SCUtil.getFormulaFromCell(secondexternalsheet, 1, 2));
383
		assertEquals("Expect formula result should be 4", "4",
384
				SCUtil.getTextFromCell(secondexternalsheet, 1, 2));
385
	}
386
278
}
387
}

Return to issue 120655