xref: /AOO41X/test/testuno/source/testlib/uno/SCUtil.java (revision 1dfd36f533074f5ba0e2d154d2a4b202154362bd)
1e6e6073dSLiu Zhe /**************************************************************
2e6e6073dSLiu Zhe  *
3e6e6073dSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4e6e6073dSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5e6e6073dSLiu Zhe  * distributed with this work for additional information
6e6e6073dSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7e6e6073dSLiu Zhe  * to you under the Apache License, Version 2.0 (the
8e6e6073dSLiu Zhe  * "License"); you may not use this file except in compliance
9e6e6073dSLiu Zhe  * with the License.  You may obtain a copy of the License at
10e6e6073dSLiu Zhe  *
11e6e6073dSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12e6e6073dSLiu Zhe  *
13e6e6073dSLiu Zhe  * Unless required by applicable law or agreed to in writing,
14e6e6073dSLiu Zhe  * software distributed under the License is distributed on an
15e6e6073dSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16e6e6073dSLiu Zhe  * KIND, either express or implied.  See the License for the
17e6e6073dSLiu Zhe  * specific language governing permissions and limitations
18e6e6073dSLiu Zhe  * under the License.
19e6e6073dSLiu Zhe  *
20e6e6073dSLiu Zhe  *************************************************************/
21e6e6073dSLiu Zhe 
22e6e6073dSLiu Zhe 
23e6e6073dSLiu Zhe package testlib.uno;
24e6e6073dSLiu Zhe 
25e6e6073dSLiu Zhe import java.util.HashMap;
26e6e6073dSLiu Zhe 
27e6e6073dSLiu Zhe import org.openoffice.test.common.FileUtil;
28e6e6073dSLiu Zhe import org.openoffice.test.common.Testspace;
29e6e6073dSLiu Zhe import org.openoffice.test.uno.UnoApp;
30e6e6073dSLiu Zhe 
31*1dfd36f5SLiu Zhe import com.sun.star.awt.Rectangle;
32e6e6073dSLiu Zhe import com.sun.star.beans.PropertyValue;
33e6e6073dSLiu Zhe import com.sun.star.beans.XPropertySet;
34*1dfd36f5SLiu Zhe import com.sun.star.chart.XChartDocument;
35*1dfd36f5SLiu Zhe import com.sun.star.chart.XDiagram;
36e6e6073dSLiu Zhe import com.sun.star.container.XIndexAccess;
37*1dfd36f5SLiu Zhe import com.sun.star.container.XNameAccess;
38e6e6073dSLiu Zhe import com.sun.star.container.XNamed;
39*1dfd36f5SLiu Zhe import com.sun.star.document.XEmbeddedObjectSupplier;
40e6e6073dSLiu Zhe import com.sun.star.frame.XController;
41e6e6073dSLiu Zhe import com.sun.star.frame.XModel;
42e6e6073dSLiu Zhe import com.sun.star.frame.XStorable;
43e6e6073dSLiu Zhe import com.sun.star.lang.XComponent;
44*1dfd36f5SLiu Zhe import com.sun.star.lang.XMultiServiceFactory;
45*1dfd36f5SLiu Zhe import com.sun.star.sheet.XCellRangeAddressable;
46e6e6073dSLiu Zhe import com.sun.star.sheet.XSpreadsheet;
47e6e6073dSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
48e6e6073dSLiu Zhe import com.sun.star.sheet.XSpreadsheetView;
49e6e6073dSLiu Zhe import com.sun.star.sheet.XSpreadsheets;
50*1dfd36f5SLiu Zhe import com.sun.star.table.CellRangeAddress;
51e6e6073dSLiu Zhe import com.sun.star.table.XCell;
52e6e6073dSLiu Zhe import com.sun.star.table.XCellRange;
53e6e6073dSLiu Zhe import com.sun.star.table.XColumnRowRange;
54*1dfd36f5SLiu Zhe import com.sun.star.table.XTableChart;
55*1dfd36f5SLiu Zhe import com.sun.star.table.XTableCharts;
56*1dfd36f5SLiu Zhe import com.sun.star.table.XTableChartsSupplier;
57e6e6073dSLiu Zhe import com.sun.star.table.XTableColumns;
58e6e6073dSLiu Zhe import com.sun.star.table.XTableRows;
59e6e6073dSLiu Zhe import com.sun.star.text.XText;
60e6e6073dSLiu Zhe import com.sun.star.uno.UnoRuntime;
61e6e6073dSLiu Zhe import com.sun.star.util.XCloseable;
62e6e6073dSLiu Zhe 
63e6e6073dSLiu Zhe 
64e6e6073dSLiu Zhe /**
65e6e6073dSLiu Zhe  * Utilities of Spreadsheet
66e6e6073dSLiu Zhe  *
67e6e6073dSLiu Zhe  */
68e6e6073dSLiu Zhe 
69e6e6073dSLiu Zhe public class SCUtil {
70e6e6073dSLiu Zhe 
71e6e6073dSLiu Zhe 	private static final String scTempDir = "output/sc/"; //Spreadsheet temp file directory
72e6e6073dSLiu Zhe 	private static HashMap filterName = new HashMap();
73e6e6073dSLiu Zhe 
74e6e6073dSLiu Zhe 	private SCUtil() {
75e6e6073dSLiu Zhe 
76e6e6073dSLiu Zhe 	}
77e6e6073dSLiu Zhe 
78e6e6073dSLiu Zhe 	/**
79e6e6073dSLiu Zhe 	 * Get spreadsheet document object
80e6e6073dSLiu Zhe 	 * @param xSpreadsheetComponent
81e6e6073dSLiu Zhe 	 * @return
82e6e6073dSLiu Zhe 	 * @throws Exception
83e6e6073dSLiu Zhe 	 */
84e6e6073dSLiu Zhe     public static XSpreadsheetDocument getSCDocument(XComponent xSpreadsheetComponent) throws Exception {
85e6e6073dSLiu Zhe     	XSpreadsheetDocument xSpreadsheetDocument =
86e6e6073dSLiu Zhe         		(XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSpreadsheetComponent);
87e6e6073dSLiu Zhe 
88e6e6073dSLiu Zhe         return xSpreadsheetDocument;
89e6e6073dSLiu Zhe     }
90e6e6073dSLiu Zhe 
91e6e6073dSLiu Zhe     /**
92e6e6073dSLiu Zhe      * Get sheet object by sheet name
93e6e6073dSLiu Zhe      * @param xSpreadsheetDocument
94e6e6073dSLiu Zhe      * @param sheetName
95e6e6073dSLiu Zhe      * @return
96e6e6073dSLiu Zhe      * @throws Exception
97e6e6073dSLiu Zhe      */
98e6e6073dSLiu Zhe 	public static XSpreadsheet getSCSheetByName(XSpreadsheetDocument xSpreadsheetDocument, String sheetName) throws Exception {
99e6e6073dSLiu Zhe 		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
100e6e6073dSLiu Zhe 		XSpreadsheet xSpreadsheet =
101e6e6073dSLiu Zhe 				(XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, xSpreadsheets.getByName(sheetName));
102e6e6073dSLiu Zhe 
103e6e6073dSLiu Zhe 		return xSpreadsheet;
104e6e6073dSLiu Zhe 	}
105e6e6073dSLiu Zhe 
106e6e6073dSLiu Zhe 	/**
107e6e6073dSLiu Zhe 	 * Get sheet object by sheet index
108e6e6073dSLiu Zhe 	 * @param xSpreadsheetDocument
109e6e6073dSLiu Zhe 	 * @param index   (Short) 0,1,2,...
110e6e6073dSLiu Zhe 	 * @return
111e6e6073dSLiu Zhe 	 * @throws Exception
112e6e6073dSLiu Zhe 	 */
113e6e6073dSLiu Zhe 	public static XSpreadsheet getSCSheetByIndex(XSpreadsheetDocument xSpreadsheetDocument, short index) throws Exception {
114e6e6073dSLiu Zhe 		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
115e6e6073dSLiu Zhe 		XIndexAccess xIndexAccess =
116e6e6073dSLiu Zhe 				(XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
117e6e6073dSLiu Zhe 		XSpreadsheet xSpreadsheet =
118e6e6073dSLiu Zhe 				(XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, xIndexAccess.getByIndex(index));
119e6e6073dSLiu Zhe 
120e6e6073dSLiu Zhe 		return xSpreadsheet;
121e6e6073dSLiu Zhe 	}
122e6e6073dSLiu Zhe 
123e6e6073dSLiu Zhe 	/**
124e6e6073dSLiu Zhe 	 * Get sheet name by sheet index
125e6e6073dSLiu Zhe 	 *
126e6e6073dSLiu Zhe 	 * @param xSpreadsheetDocument
127e6e6073dSLiu Zhe 	 * @param index
128e6e6073dSLiu Zhe 	 *            (Short) 0,1,2,...
129e6e6073dSLiu Zhe 	 * @return
130e6e6073dSLiu Zhe 	 * @throws Exception
131e6e6073dSLiu Zhe 	 */
132e6e6073dSLiu Zhe 	public static String getSCSheetNameByIndex(
133e6e6073dSLiu Zhe 			XSpreadsheetDocument xSpreadsheetDocument, short index)
134e6e6073dSLiu Zhe 			throws Exception {
135e6e6073dSLiu Zhe 		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
136e6e6073dSLiu Zhe 		XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
137e6e6073dSLiu Zhe 				XIndexAccess.class, xSpreadsheets);
138e6e6073dSLiu Zhe 		XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
139e6e6073dSLiu Zhe 				XSpreadsheet.class, xIndexAccess.getByIndex(index));
140e6e6073dSLiu Zhe 		XNamed xsheetname = (XNamed) UnoRuntime.queryInterface(XNamed.class,
141e6e6073dSLiu Zhe 				xSpreadsheet);
142e6e6073dSLiu Zhe 		return xsheetname.getName();
143e6e6073dSLiu Zhe 	}
144e6e6073dSLiu Zhe 
145e6e6073dSLiu Zhe 	/**
146e6e6073dSLiu Zhe 	 * Set sheet name by sheet index
147e6e6073dSLiu Zhe 	 *
148e6e6073dSLiu Zhe 	 * @param xSpreadsheetDocument
149e6e6073dSLiu Zhe 	 * @param index
150e6e6073dSLiu Zhe 	 *            (Short) 0,1,2,...
151e6e6073dSLiu Zhe 	 * @return
152e6e6073dSLiu Zhe 	 * @throws Exception
153e6e6073dSLiu Zhe 	 */
154e6e6073dSLiu Zhe 	public static void setSCSheetNameByIndex(
155e6e6073dSLiu Zhe 			XSpreadsheetDocument xSpreadsheetDocument, short index,
156e6e6073dSLiu Zhe 			String sheetname) throws Exception {
157e6e6073dSLiu Zhe 		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
158e6e6073dSLiu Zhe 		XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
159e6e6073dSLiu Zhe 				XIndexAccess.class, xSpreadsheets);
160e6e6073dSLiu Zhe 		XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
161e6e6073dSLiu Zhe 				XSpreadsheet.class, xIndexAccess.getByIndex(index));
162e6e6073dSLiu Zhe 		XNamed xsheetname = (XNamed) UnoRuntime.queryInterface(XNamed.class,
163e6e6073dSLiu Zhe 				xSpreadsheet);
164e6e6073dSLiu Zhe 		xsheetname.setName(sheetname);
165e6e6073dSLiu Zhe 	}
166e6e6073dSLiu Zhe 
167e6e6073dSLiu Zhe 	/**
168e6e6073dSLiu Zhe 	 * Get rows object
169e6e6073dSLiu Zhe 	 * @param xSpreadsheet
170e6e6073dSLiu Zhe 	 * @return
171e6e6073dSLiu Zhe 	 * @throws Exception
172e6e6073dSLiu Zhe 	 */
173e6e6073dSLiu Zhe 	public static XTableRows getSCRows(XSpreadsheet xSpreadsheet) throws Exception {
174e6e6073dSLiu Zhe 		XColumnRowRange xColumnRowRange =
175e6e6073dSLiu Zhe 				(XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
176e6e6073dSLiu Zhe 		XTableRows xTableRows = xColumnRowRange.getRows();
177e6e6073dSLiu Zhe 
178e6e6073dSLiu Zhe 		return xTableRows;
179e6e6073dSLiu Zhe 	}
180e6e6073dSLiu Zhe 
181e6e6073dSLiu Zhe 	/**
182e6e6073dSLiu Zhe 	 * Get columns object
183e6e6073dSLiu Zhe 	 * @param xSpreadsheet
184e6e6073dSLiu Zhe 	 * @return
185e6e6073dSLiu Zhe 	 * @throws Exception
186e6e6073dSLiu Zhe 	 */
187e6e6073dSLiu Zhe 	public static XTableColumns getSCColumns(XSpreadsheet xSpreadsheet) throws Exception {
188e6e6073dSLiu Zhe 		XColumnRowRange xColumnRowRange =
189e6e6073dSLiu Zhe 				(XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
190e6e6073dSLiu Zhe 		XTableColumns xTableColumns = xColumnRowRange.getColumns();
191e6e6073dSLiu Zhe 
192e6e6073dSLiu Zhe 		return xTableColumns;
193e6e6073dSLiu Zhe 	}
194e6e6073dSLiu Zhe 
195e6e6073dSLiu Zhe 	/**
196e6e6073dSLiu Zhe 	 * Set floating number into specific cell
197e6e6073dSLiu Zhe 	 * @param xSpreadsheet
198e6e6073dSLiu Zhe 	 * @param column
199e6e6073dSLiu Zhe 	 * @param row
200e6e6073dSLiu Zhe 	 * @param value
201e6e6073dSLiu Zhe 	 * @throws Exception
202e6e6073dSLiu Zhe 	 */
203e6e6073dSLiu Zhe 	public static void setValueToCell(XSpreadsheet xSpreadsheet, int column, int row, double value) throws Exception {
204e6e6073dSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
205e6e6073dSLiu Zhe 		xCell.setValue(value);
206e6e6073dSLiu Zhe 	}
207e6e6073dSLiu Zhe 
208e6e6073dSLiu Zhe 	/**
209e6e6073dSLiu Zhe 	 * Set text into specific cell
210e6e6073dSLiu Zhe 	 * @param xSpreadsheet
211e6e6073dSLiu Zhe 	 * @param column
212e6e6073dSLiu Zhe 	 * @param row
213e6e6073dSLiu Zhe 	 * @param text
214e6e6073dSLiu Zhe 	 * @throws Exception
215e6e6073dSLiu Zhe 	 */
216e6e6073dSLiu Zhe 	public static void setTextToCell(XSpreadsheet xSpreadsheet, int column, int row, String text) throws Exception {
217e6e6073dSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
218e6e6073dSLiu Zhe 		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
219e6e6073dSLiu Zhe 		xText.setString(text);
220e6e6073dSLiu Zhe 	}
221e6e6073dSLiu Zhe 
222e6e6073dSLiu Zhe 	/**
223e6e6073dSLiu Zhe 	 * Set text into specific cell
224e6e6073dSLiu Zhe 	 * @param xCell
225e6e6073dSLiu Zhe 	 * @param text
226e6e6073dSLiu Zhe 	 * @throws Exception
227e6e6073dSLiu Zhe 	 */
228e6e6073dSLiu Zhe 	public static void setTextToCell(XCell xCell, String text) throws Exception {
229e6e6073dSLiu Zhe 		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
230e6e6073dSLiu Zhe 		xText.setString(text);
231e6e6073dSLiu Zhe 	}
232e6e6073dSLiu Zhe 
233e6e6073dSLiu Zhe 	/**
234e6e6073dSLiu Zhe 	 * Set formula into specific cell
235e6e6073dSLiu Zhe 	 * @param xSpreadsheet
236e6e6073dSLiu Zhe 	 * @param column
237e6e6073dSLiu Zhe 	 * @param row
238e6e6073dSLiu Zhe 	 * @param formula
239e6e6073dSLiu Zhe 	 * @throws Exception
240e6e6073dSLiu Zhe 	 */
241e6e6073dSLiu Zhe 	public static void setFormulaToCell(XSpreadsheet xSpreadsheet, int column, int row, String formula) throws Exception {
242e6e6073dSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
243e6e6073dSLiu Zhe 		xCell.setFormula(formula);
244e6e6073dSLiu Zhe 	}
245e6e6073dSLiu Zhe 
246e6e6073dSLiu Zhe 	/**
247e6e6073dSLiu Zhe 	 * Get value from specific cell
248e6e6073dSLiu Zhe 	 * @param xSpreadsheet
249e6e6073dSLiu Zhe 	 * @param column
250e6e6073dSLiu Zhe 	 * @param row
251e6e6073dSLiu Zhe 	 * @return
252e6e6073dSLiu Zhe 	 * @throws Exception
253e6e6073dSLiu Zhe 	 */
254e6e6073dSLiu Zhe 	public static double getValueFromCell(XSpreadsheet xSpreadsheet, int column, int row) throws Exception {
255e6e6073dSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
256e6e6073dSLiu Zhe 		double cellValue = xCell.getValue();
257e6e6073dSLiu Zhe 
258e6e6073dSLiu Zhe 		return cellValue;
259e6e6073dSLiu Zhe 	}
260e6e6073dSLiu Zhe 
261e6e6073dSLiu Zhe 	/**
262e6e6073dSLiu Zhe 	 * Get text from specific cell
263e6e6073dSLiu Zhe 	 * @param xSpreadsheet
264e6e6073dSLiu Zhe 	 * @param column
265e6e6073dSLiu Zhe 	 * @param row
266e6e6073dSLiu Zhe 	 *
267e6e6073dSLiu Zhe 	 * @return
268e6e6073dSLiu Zhe 	 * @throws Exception
269e6e6073dSLiu Zhe 	 */
270e6e6073dSLiu Zhe 	public static String getTextFromCell(XSpreadsheet xSpreadsheet, int column, int row) throws Exception {
271e6e6073dSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
272e6e6073dSLiu Zhe 		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
273e6e6073dSLiu Zhe 
274e6e6073dSLiu Zhe 		return xText.getString();
275e6e6073dSLiu Zhe 	}
276e6e6073dSLiu Zhe 
277e6e6073dSLiu Zhe 	/**
278e6e6073dSLiu Zhe 	 * Get formula string from specific cell
279e6e6073dSLiu Zhe 	 * @param xSpreadsheet
280e6e6073dSLiu Zhe 	 * @param column
281e6e6073dSLiu Zhe 	 * @param row
282e6e6073dSLiu Zhe 	 * @return
283e6e6073dSLiu Zhe 	 * @throws Exception
284e6e6073dSLiu Zhe 	 */
285e6e6073dSLiu Zhe 	public static String getFormulaFromCell(XSpreadsheet xSpreadsheet, int column, int row) throws Exception {
286e6e6073dSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
287e6e6073dSLiu Zhe 		String cellFormula = xCell.getFormula();
288e6e6073dSLiu Zhe 
289e6e6073dSLiu Zhe 		return cellFormula;
290e6e6073dSLiu Zhe 	}
291e6e6073dSLiu Zhe 
292e6e6073dSLiu Zhe 	/**
293e6e6073dSLiu Zhe 	 * Set numbers into a cell range
294e6e6073dSLiu Zhe 	 * @param xSpreadsheet
295e6e6073dSLiu Zhe 	 * @param start_col
296e6e6073dSLiu Zhe 	 * @param start_row
297e6e6073dSLiu Zhe 	 * @param end_col
298e6e6073dSLiu Zhe 	 * @param end_row
299e6e6073dSLiu Zhe 	 * @param values
300e6e6073dSLiu Zhe 	 * @throws Exception
301e6e6073dSLiu Zhe 	 */
302*1dfd36f5SLiu Zhe 	@Deprecated
303e6e6073dSLiu Zhe 	public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row,  double[][] values) throws Exception {
304e6e6073dSLiu Zhe 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
305e6e6073dSLiu Zhe 		XCell xCell = null;
306e6e6073dSLiu Zhe 		for (int i = 0; i <= (end_row - start_row); i++ ) {
307e6e6073dSLiu Zhe 			for(int j = 0; j <= (end_col - start_col); j++) {
308e6e6073dSLiu Zhe 				xCell = xCellRange.getCellByPosition(j, i);
309e6e6073dSLiu Zhe 				xCell.setValue(values[i][j]);
310e6e6073dSLiu Zhe 			}
311e6e6073dSLiu Zhe 		}
312e6e6073dSLiu Zhe 	}
313e6e6073dSLiu Zhe 
314*1dfd36f5SLiu Zhe 	public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, double[][] values) throws Exception {
315*1dfd36f5SLiu Zhe 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, start_col + values[0].length - 1, start_row + values.length - 1);
316*1dfd36f5SLiu Zhe 		XCell xCell = null;
317*1dfd36f5SLiu Zhe 		for (int i = 0; i < values.length; i++ ) {
318*1dfd36f5SLiu Zhe 			for(int j = 0; j < values[0].length; j++) {
319*1dfd36f5SLiu Zhe 				xCell = xCellRange.getCellByPosition(j, i);
320*1dfd36f5SLiu Zhe 				xCell.setValue(values[i][j]);
321*1dfd36f5SLiu Zhe 			}
322*1dfd36f5SLiu Zhe 		}
323*1dfd36f5SLiu Zhe 	}
324*1dfd36f5SLiu Zhe 
325e6e6073dSLiu Zhe 	/**
326e6e6073dSLiu Zhe 	 * Set text into a cell range
327e6e6073dSLiu Zhe 	 * @param xSpreadsheet
328e6e6073dSLiu Zhe 	 * @param start_col
329e6e6073dSLiu Zhe 	 * @param start_row
330e6e6073dSLiu Zhe 	 * @param end_col
331e6e6073dSLiu Zhe 	 * @param end_row
332e6e6073dSLiu Zhe 	 * @param texts
333e6e6073dSLiu Zhe 	 * @throws Exception
334e6e6073dSLiu Zhe 	 */
335*1dfd36f5SLiu Zhe 	@Deprecated
336e6e6073dSLiu Zhe 	public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row,  String[][] texts) throws Exception {
337e6e6073dSLiu Zhe 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
338e6e6073dSLiu Zhe 		XCell xCell = null;
339e6e6073dSLiu Zhe 		XText xText = null;
340e6e6073dSLiu Zhe 		for (int i = 0; i <= (end_row - start_row); i++ ) {
341e6e6073dSLiu Zhe 			for(int j = 0; j <= (end_col - start_col); j++) {
342e6e6073dSLiu Zhe 				xCell = xCellRange.getCellByPosition(j, i);
343e6e6073dSLiu Zhe 				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
344e6e6073dSLiu Zhe 				xText.setString(texts[i][j]);
345e6e6073dSLiu Zhe 			}
346e6e6073dSLiu Zhe 		}
347e6e6073dSLiu Zhe 	}
348e6e6073dSLiu Zhe 
349*1dfd36f5SLiu Zhe 	public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, String[][] texts) throws Exception {
350*1dfd36f5SLiu Zhe 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, start_col + texts[0].length - 1, start_row + texts.length - 1);
351*1dfd36f5SLiu Zhe 		XCell xCell = null;
352*1dfd36f5SLiu Zhe 		XText xText = null;
353*1dfd36f5SLiu Zhe 		for (int i = 0; i < texts.length; i++ ) {
354*1dfd36f5SLiu Zhe 			for(int j = 0; j < texts[0].length; j++) {
355*1dfd36f5SLiu Zhe 				xCell = xCellRange.getCellByPosition(j, i);
356*1dfd36f5SLiu Zhe 				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
357*1dfd36f5SLiu Zhe 				xText.setString(texts[i][j]);
358*1dfd36f5SLiu Zhe 			}
359*1dfd36f5SLiu Zhe 		}
360*1dfd36f5SLiu Zhe 	}
361*1dfd36f5SLiu Zhe 
362e6e6073dSLiu Zhe 	/**
363e6e6073dSLiu Zhe 	 * Get number content from a cell range
364e6e6073dSLiu Zhe 	 * @param xSpreadsheet
365e6e6073dSLiu Zhe 	 * @param start_col
366e6e6073dSLiu Zhe 	 * @param start_row
367e6e6073dSLiu Zhe 	 * @param end_col
368e6e6073dSLiu Zhe 	 * @param end_row
369e6e6073dSLiu Zhe 	 * @return
370e6e6073dSLiu Zhe 	 * @throws Exception
371e6e6073dSLiu Zhe 	 */
372e6e6073dSLiu Zhe 	public static double[][] getValueFromCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row) throws Exception {
373e6e6073dSLiu Zhe 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
374e6e6073dSLiu Zhe 		XCell xCell = null;
375e6e6073dSLiu Zhe 		double[][] cellValues = new double[end_row - start_row+1][end_col - start_col +1];
376e6e6073dSLiu Zhe 
377e6e6073dSLiu Zhe 		for (int i = 0; i <= (end_row - start_row); i++ ) {
378e6e6073dSLiu Zhe 			for(int j = 0; j <= (end_col - start_col); j++) {
379e6e6073dSLiu Zhe 				xCell = xCellRange.getCellByPosition(j, i);
380e6e6073dSLiu Zhe 				cellValues[i][j] = xCell.getValue();
381e6e6073dSLiu Zhe 			}
382e6e6073dSLiu Zhe 		}
383e6e6073dSLiu Zhe 
384e6e6073dSLiu Zhe 		return cellValues;
385e6e6073dSLiu Zhe 	}
386e6e6073dSLiu Zhe 
387e6e6073dSLiu Zhe 	/**
388e6e6073dSLiu Zhe 	 * Get text content from a cell range
389e6e6073dSLiu Zhe 	 * @param xSpreadsheet
390e6e6073dSLiu Zhe 	 * @param start_col
391e6e6073dSLiu Zhe 	 * @param start_row
392e6e6073dSLiu Zhe 	 * @param end_col
393e6e6073dSLiu Zhe 	 * @param end_row
394e6e6073dSLiu Zhe 	 * @return
395e6e6073dSLiu Zhe 	 * @throws Exception
396e6e6073dSLiu Zhe 	 */
397e6e6073dSLiu Zhe 	public static String[][] getTextFromCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row) throws Exception {
398e6e6073dSLiu Zhe 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
399e6e6073dSLiu Zhe 		XCell xCell = null;
400e6e6073dSLiu Zhe 		XText xText = null;
401e6e6073dSLiu Zhe 		String[][] cellTexts = new String[end_row - start_row+1][end_col - start_col +1];
402e6e6073dSLiu Zhe 
403e6e6073dSLiu Zhe 		for (int i = 0; i <= (end_row - start_row); i++ ) {
404e6e6073dSLiu Zhe 			for (int j = 0; j <= (end_col - start_col); j++) {
405e6e6073dSLiu Zhe 				xCell = xCellRange.getCellByPosition(j, i);
406e6e6073dSLiu Zhe 				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
407e6e6073dSLiu Zhe 				cellTexts[i][j] = xText.getString();
408e6e6073dSLiu Zhe 			}
409e6e6073dSLiu Zhe 		}
410e6e6073dSLiu Zhe 
411e6e6073dSLiu Zhe 		return cellTexts;
412e6e6073dSLiu Zhe 	}
413e6e6073dSLiu Zhe 
414e6e6073dSLiu Zhe 	//TODO ZS - public static String[][] getAllFromCellRange
415e6e6073dSLiu Zhe 
416e6e6073dSLiu Zhe 	/**
417e6e6073dSLiu Zhe 	 * Switch to specific sheet
418e6e6073dSLiu Zhe 	 * @param xSpreadsheetDocument
419e6e6073dSLiu Zhe 	 * @param xSpreadsheet
420e6e6073dSLiu Zhe 	 */
421e6e6073dSLiu Zhe 	public static void setCurrentSheet(XSpreadsheetDocument xSpreadsheetDocument, XSpreadsheet xSpreadsheet) throws Exception {
422e6e6073dSLiu Zhe 		XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xSpreadsheetDocument);
423e6e6073dSLiu Zhe 		XController xController = xModel.getCurrentController();
424e6e6073dSLiu Zhe 		XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, xController);
425e6e6073dSLiu Zhe 		xSpreadsheetView.setActiveSheet(xSpreadsheet);
426e6e6073dSLiu Zhe 	}
427e6e6073dSLiu Zhe 
428e6e6073dSLiu Zhe 	/**
429e6e6073dSLiu Zhe 	 * Get sheet object of current active sheet
430e6e6073dSLiu Zhe 	 * @param xSpreadsheetDocument
431e6e6073dSLiu Zhe 	 * @return
432e6e6073dSLiu Zhe 	 */
433e6e6073dSLiu Zhe 	public static XSpreadsheet getCurrentSheet(XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
434e6e6073dSLiu Zhe 		XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xSpreadsheetDocument);
435e6e6073dSLiu Zhe 		XController xController = xModel.getCurrentController();
436e6e6073dSLiu Zhe 		XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, xController);
437e6e6073dSLiu Zhe 		XSpreadsheet xSpreadsheet = xSpreadsheetView.getActiveSheet();
438e6e6073dSLiu Zhe 
439e6e6073dSLiu Zhe 		return xSpreadsheet;
440e6e6073dSLiu Zhe 	}
441e6e6073dSLiu Zhe 
442e6e6073dSLiu Zhe 	/**
443e6e6073dSLiu Zhe 	 * Get sheet object by sheet index
444e6e6073dSLiu Zhe 	 *
445e6e6073dSLiu Zhe 	 * @param xSpreadsheetDocument
446e6e6073dSLiu Zhe 	 * @return
447e6e6073dSLiu Zhe 	 * @throws Exception
448e6e6073dSLiu Zhe 	 */
449e6e6073dSLiu Zhe 	public static String getSCActiveSheetName(
450e6e6073dSLiu Zhe 			XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
451e6e6073dSLiu Zhe 		XModel xSpreadsheetModel = (XModel) UnoRuntime.queryInterface(
452e6e6073dSLiu Zhe 				XModel.class, xSpreadsheetDocument);
453e6e6073dSLiu Zhe 		XSpreadsheetView xSpeadsheetView = (XSpreadsheetView) UnoRuntime
454e6e6073dSLiu Zhe 				.queryInterface(XSpreadsheetView.class,
455e6e6073dSLiu Zhe 						xSpreadsheetModel.getCurrentController());
456e6e6073dSLiu Zhe 		XSpreadsheet activesheet = xSpeadsheetView.getActiveSheet();
457e6e6073dSLiu Zhe 		XNamed activesheetName = (XNamed) UnoRuntime.queryInterface(
458e6e6073dSLiu Zhe 				XNamed.class, activesheet);
459e6e6073dSLiu Zhe 		return activesheetName.getName();
460e6e6073dSLiu Zhe 	}
461e6e6073dSLiu Zhe 
462e6e6073dSLiu Zhe 	/**
463*1dfd36f5SLiu Zhe 	 * Set specific property's value for an object
464*1dfd36f5SLiu Zhe 	 * @param obj
465*1dfd36f5SLiu Zhe 	 * @param propName
466*1dfd36f5SLiu Zhe 	 * @param value
467*1dfd36f5SLiu Zhe 	 * @throws Exception
468*1dfd36f5SLiu Zhe 	 */
469*1dfd36f5SLiu Zhe 	public static void setProperties(Object obj, String propName, Object value) throws Exception {
470*1dfd36f5SLiu Zhe 		XPropertySet xPropertySet =
471*1dfd36f5SLiu Zhe 				(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, obj);
472*1dfd36f5SLiu Zhe 		xPropertySet.setPropertyValue(propName, value);
473*1dfd36f5SLiu Zhe 	}
474*1dfd36f5SLiu Zhe 
475*1dfd36f5SLiu Zhe 	/**
476*1dfd36f5SLiu Zhe 	 * Get specific property's value of an object
477*1dfd36f5SLiu Zhe 	 * @param obj
478*1dfd36f5SLiu Zhe 	 * @param propName
479*1dfd36f5SLiu Zhe 	 * @return
480*1dfd36f5SLiu Zhe 	 * @throws Exception
481*1dfd36f5SLiu Zhe 	 */
482*1dfd36f5SLiu Zhe 	public static Object getProperties(Object obj, String propName) throws Exception {
483*1dfd36f5SLiu Zhe 		XPropertySet xPropertySet =
484*1dfd36f5SLiu Zhe 				(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, obj);
485*1dfd36f5SLiu Zhe 		Object value = xPropertySet.getPropertyValue(propName);
486*1dfd36f5SLiu Zhe 
487*1dfd36f5SLiu Zhe 		return value;
488*1dfd36f5SLiu Zhe 	}
489*1dfd36f5SLiu Zhe 
490*1dfd36f5SLiu Zhe 	/**
491e6e6073dSLiu Zhe 	 * Set value of specific property from a cell
492e6e6073dSLiu Zhe 	 * @param xCell
493e6e6073dSLiu Zhe 	 * @param propName
494e6e6073dSLiu Zhe 	 * @param value
495e6e6073dSLiu Zhe 	 * @throws Exception
496e6e6073dSLiu Zhe 	 */
497e6e6073dSLiu Zhe 	public static void setCellProperties(XCell xCell, String propName, Object value) throws Exception {
498e6e6073dSLiu Zhe 
499*1dfd36f5SLiu Zhe 		setProperties(xCell, propName, value);
500e6e6073dSLiu Zhe 	}
501e6e6073dSLiu Zhe 
502e6e6073dSLiu Zhe 	/**
503e6e6073dSLiu Zhe 	 * Get value of specific property from a cell
504e6e6073dSLiu Zhe 	 * @param xCell
505e6e6073dSLiu Zhe 	 * @param propName
506e6e6073dSLiu Zhe 	 * @return
507e6e6073dSLiu Zhe 	 * @throws Exception
508e6e6073dSLiu Zhe 	 */
509e6e6073dSLiu Zhe 	public static Object getCellProperties(XCell xCell, String propName) throws Exception {
510*1dfd36f5SLiu Zhe 			return getProperties(xCell, propName);
511e6e6073dSLiu Zhe 	}
512e6e6073dSLiu Zhe 
513e6e6073dSLiu Zhe 	/**
514e6e6073dSLiu Zhe 	 * Clear temp file directory
515e6e6073dSLiu Zhe 	 */
516e6e6073dSLiu Zhe 	public static void clearTempDir() {
517e6e6073dSLiu Zhe 		FileUtil.deleteFile(Testspace.getFile(Testspace.getPath(scTempDir)));
518e6e6073dSLiu Zhe 	}
519e6e6073dSLiu Zhe 
520e6e6073dSLiu Zhe 	/**
521e6e6073dSLiu Zhe 	 * Save file as specific file format into spreadsheet temp file folder.
522e6e6073dSLiu Zhe 	 * @param scComponent
523e6e6073dSLiu Zhe 	 * @param fileName  File name string without extension name (e.g. "sampleFile")
524e6e6073dSLiu Zhe 	 * @param extName ("ods", "ots", "xls", "xlt", "csv")
525e6e6073dSLiu Zhe 	 * @throws Exception
526e6e6073dSLiu Zhe 	 */
527e6e6073dSLiu Zhe 	public static void saveFileAs(XComponent scComponent, String fileName, String extName) throws Exception {
528e6e6073dSLiu Zhe 
529e6e6073dSLiu Zhe 		initFilterName();
530e6e6073dSLiu Zhe 
531e6e6073dSLiu Zhe 		String storeUrl = Testspace.getUrl(scTempDir + fileName + "." + extName);
532e6e6073dSLiu Zhe 
533e6e6073dSLiu Zhe 		PropertyValue[] storeProps = new PropertyValue[2];
534e6e6073dSLiu Zhe 		storeProps[0] = new PropertyValue();
535e6e6073dSLiu Zhe 		storeProps[0].Name = "FilterName";
536e6e6073dSLiu Zhe 		storeProps[0].Value = filterName.get(extName);
537e6e6073dSLiu Zhe 		storeProps[1] = new PropertyValue();
538e6e6073dSLiu Zhe 		storeProps[1].Name = "Overwrite";
539e6e6073dSLiu Zhe 		storeProps[1].Value = new Boolean(true);
540e6e6073dSLiu Zhe 
541e6e6073dSLiu Zhe 		XStorable scStorable =
542e6e6073dSLiu Zhe 				(XStorable) UnoRuntime.queryInterface(XStorable.class, scComponent);
543e6e6073dSLiu Zhe 		scStorable.storeAsURL(storeUrl, storeProps);
544e6e6073dSLiu Zhe 	}
545e6e6073dSLiu Zhe 
546e6e6073dSLiu Zhe 	/**
547e6e6073dSLiu Zhe 	 * Save file after open file.
548e6e6073dSLiu Zhe 	 * @param xSpreadsheetDocument
549e6e6073dSLiu Zhe 	 * @throws Exception
550e6e6073dSLiu Zhe 	 */
551e6e6073dSLiu Zhe 	public static void save(XSpreadsheetDocument xSpreadsheetDocument)
552e6e6073dSLiu Zhe 			throws Exception {
553e6e6073dSLiu Zhe 		XStorable scStorable = (XStorable) UnoRuntime.queryInterface(
554e6e6073dSLiu Zhe 				XStorable.class, xSpreadsheetDocument);
555e6e6073dSLiu Zhe 		scStorable.store();
556e6e6073dSLiu Zhe 	}
557e6e6073dSLiu Zhe 
558e6e6073dSLiu Zhe 
559e6e6073dSLiu Zhe 	/**
560e6e6073dSLiu Zhe 	 * Close specific opening spreadsheet file which has been saved
561e6e6073dSLiu Zhe 	 * @param xSpreadsheetDocument
562e6e6073dSLiu Zhe 	 * @throws Exception
563e6e6073dSLiu Zhe 	 */
564e6e6073dSLiu Zhe 	public static void closeFile(XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
565e6e6073dSLiu Zhe 		XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xSpreadsheetDocument);
566e6e6073dSLiu Zhe 		xCloseable.close(false);
567e6e6073dSLiu Zhe 	}
568e6e6073dSLiu Zhe 
569e6e6073dSLiu Zhe 	/**
570e6e6073dSLiu Zhe 	 * Close a opening file saved in spreadsheet temp file direction and reopen it in Spreadsheet. For save&reload test scenario only.
571e6e6073dSLiu Zhe 	 * @param unoApp
572e6e6073dSLiu Zhe 	 * @param xSpreadsheetDocument
573e6e6073dSLiu Zhe 	 * @param fullFileName   File name with the extension name. (e.g. "sc.ods")
574e6e6073dSLiu Zhe 	 * @return
575e6e6073dSLiu Zhe 	 * @throws Exception
576e6e6073dSLiu Zhe 	 */
577e6e6073dSLiu Zhe 	public static XSpreadsheetDocument reloadFile(UnoApp unoApp, XSpreadsheetDocument xSpreadsheetDocument, String fullFileName) throws Exception {
578e6e6073dSLiu Zhe 		closeFile(xSpreadsheetDocument);
579e6e6073dSLiu Zhe 
580e6e6073dSLiu Zhe 		String filePath = Testspace.getPath(scTempDir + fullFileName);
581cebb507aSLiu Zhe 		XSpreadsheetDocument xScDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, unoApp.loadDocument(filePath));
582e6e6073dSLiu Zhe 
583e6e6073dSLiu Zhe 		return xScDocument;
584e6e6073dSLiu Zhe 	}
585e6e6073dSLiu Zhe 
586e6e6073dSLiu Zhe 	/**
5879fdcf9fdSLiu Zhe 	 * open file in Spreadsheet.
588*1dfd36f5SLiu Zhe 	 * @param app
589*1dfd36f5SLiu Zhe 	 * @param filePath   File path with the extension name. (e.g. "testcase/uno/sc/data/sample.xls")
5909fdcf9fdSLiu Zhe 	 * @return
5919fdcf9fdSLiu Zhe 	 * @throws Exception
5929fdcf9fdSLiu Zhe 	 */
5939fdcf9fdSLiu Zhe 	public static XSpreadsheetDocument openFile(String filePath, UnoApp app) throws Exception {
5949fdcf9fdSLiu Zhe 		return (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, app.loadDocument(filePath));
5959fdcf9fdSLiu Zhe 	}
5969fdcf9fdSLiu Zhe 
5979fdcf9fdSLiu Zhe 	/**
598e6e6073dSLiu Zhe 	 * Initial the filter name list
599e6e6073dSLiu Zhe 	 * @throws Exception
600e6e6073dSLiu Zhe 	 */
601e6e6073dSLiu Zhe 	private static void initFilterName() throws Exception {
602e6e6073dSLiu Zhe 		if (filterName.size() > 0) {
603e6e6073dSLiu Zhe 			return;
604e6e6073dSLiu Zhe 		}
605e6e6073dSLiu Zhe 
606e6e6073dSLiu Zhe 		filterName.put("ods", "calc8");
607e6e6073dSLiu Zhe 		filterName.put("ots", "calc8_template");
608e6e6073dSLiu Zhe 		filterName.put("xls", "MS Excel 97");
609e6e6073dSLiu Zhe 		filterName.put("xlt", "MS Excel 97 Vorlage/Template");
610e6e6073dSLiu Zhe 		filterName.put("csv", "Text - txt - csv (StarCalc)");
611e6e6073dSLiu Zhe 	}
612e6e6073dSLiu Zhe 
613*1dfd36f5SLiu Zhe 
614*1dfd36f5SLiu Zhe 	/***************************************************************
615*1dfd36f5SLiu Zhe 	 *      Chart Utility method - using chart interface           *
616*1dfd36f5SLiu Zhe 	****************************************************************/
617*1dfd36f5SLiu Zhe 
618*1dfd36f5SLiu Zhe 	/**
619*1dfd36f5SLiu Zhe 	 * Get a CellRangeAddress by cell range reference name
620*1dfd36f5SLiu Zhe 	 * @param xSpreadsheet
621*1dfd36f5SLiu Zhe 	 * @param rangeName    a cell range reference name(e.g. "A1:B2")
622*1dfd36f5SLiu Zhe 	 * @return
623*1dfd36f5SLiu Zhe 	 */
624*1dfd36f5SLiu Zhe 	public static CellRangeAddress getChartDataRangeByName(XSpreadsheet xSpreadsheet, String rangeName) {
625*1dfd36f5SLiu Zhe 		XCellRange cellRange = xSpreadsheet.getCellRangeByName(rangeName);
626*1dfd36f5SLiu Zhe 		XCellRangeAddressable xCellRangeAddressable =
627*1dfd36f5SLiu Zhe 			(XCellRangeAddressable) UnoRuntime.queryInterface(XCellRangeAddressable.class, cellRange);
628*1dfd36f5SLiu Zhe 
629*1dfd36f5SLiu Zhe 		CellRangeAddress cellRangeAddress = xCellRangeAddressable.getRangeAddress();
630*1dfd36f5SLiu Zhe 		return cellRangeAddress;
631*1dfd36f5SLiu Zhe 	}
632*1dfd36f5SLiu Zhe 
633*1dfd36f5SLiu Zhe 	/**
634*1dfd36f5SLiu Zhe 	 * Create a spreadsheet chart with data in a specific cell range.
635*1dfd36f5SLiu Zhe 	 * @param xSpreadsheet
636*1dfd36f5SLiu Zhe 	 * @param rec   a rectangle shape object
637*1dfd36f5SLiu Zhe 	 * @param dataRangeAddress   the CellRangeAddress array of chart data source
638*1dfd36f5SLiu Zhe 	 * @param chartName
639*1dfd36f5SLiu Zhe 	 * @return
640*1dfd36f5SLiu Zhe 	 * @throws Exception
641*1dfd36f5SLiu Zhe 	 */
642*1dfd36f5SLiu Zhe 	public static XChartDocument createChart(XSpreadsheet xSpreadsheet, Rectangle rec, CellRangeAddress[] dataRangeAddress, String chartName) throws Exception {
643*1dfd36f5SLiu Zhe 		XChartDocument xChartDocument = null;
644*1dfd36f5SLiu Zhe 		XTableChartsSupplier xTChartSupplier =
645*1dfd36f5SLiu Zhe 				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
646*1dfd36f5SLiu Zhe 		XTableCharts xTableCharts = xTChartSupplier.getCharts();
647*1dfd36f5SLiu Zhe 		XNameAccess xNameAccess =
648*1dfd36f5SLiu Zhe 				(XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xTableCharts);
649*1dfd36f5SLiu Zhe 		if (xNameAccess != null && !xNameAccess.hasByName(chartName)) {
650*1dfd36f5SLiu Zhe 
651*1dfd36f5SLiu Zhe 			xTableCharts.addNewByName(chartName, rec, dataRangeAddress, true, false);
652*1dfd36f5SLiu Zhe 			XTableChart xTableChart = (XTableChart) UnoRuntime.queryInterface(
653*1dfd36f5SLiu Zhe 					XTableChart.class, xNameAccess.getByName(chartName));
654*1dfd36f5SLiu Zhe 			XEmbeddedObjectSupplier xEmbeddedObjectSupplier = (XEmbeddedObjectSupplier) UnoRuntime.queryInterface(
655*1dfd36f5SLiu Zhe 					XEmbeddedObjectSupplier.class, xTableChart);
656*1dfd36f5SLiu Zhe 			xChartDocument = (XChartDocument) UnoRuntime.queryInterface(
657*1dfd36f5SLiu Zhe 					XChartDocument.class, xEmbeddedObjectSupplier.getEmbeddedObject());
658*1dfd36f5SLiu Zhe 		}
659*1dfd36f5SLiu Zhe 
660*1dfd36f5SLiu Zhe 		return xChartDocument;
661*1dfd36f5SLiu Zhe 	}
662*1dfd36f5SLiu Zhe 
663*1dfd36f5SLiu Zhe 	/**
664*1dfd36f5SLiu Zhe 	 * Get XChartDocument object via the chart name.
665*1dfd36f5SLiu Zhe 	 * @param xSpreadsheet
666*1dfd36f5SLiu Zhe 	 * @param chartName
667*1dfd36f5SLiu Zhe 	 * @return
668*1dfd36f5SLiu Zhe 	 * @throws Exception
669*1dfd36f5SLiu Zhe 	 */
670*1dfd36f5SLiu Zhe 	public static XChartDocument getChartByName(XSpreadsheet xSpreadsheet, String chartName) throws Exception {
671*1dfd36f5SLiu Zhe 		XChartDocument xChartDocument = null;
672*1dfd36f5SLiu Zhe 		XTableChartsSupplier xTChartSupplier =
673*1dfd36f5SLiu Zhe 				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
674*1dfd36f5SLiu Zhe 		XTableCharts xTableCharts = xTChartSupplier.getCharts();
675*1dfd36f5SLiu Zhe 		XNameAccess xNameAccess =
676*1dfd36f5SLiu Zhe 				(XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xTableCharts);
677*1dfd36f5SLiu Zhe 
678*1dfd36f5SLiu Zhe 		if (xNameAccess != null && xNameAccess.hasByName(chartName)) {
679*1dfd36f5SLiu Zhe 			XTableChart xTableChart = (XTableChart) UnoRuntime.queryInterface(
680*1dfd36f5SLiu Zhe 					XTableChart.class, xNameAccess.getByName(chartName));
681*1dfd36f5SLiu Zhe 			XEmbeddedObjectSupplier xEmbeddedObjectSupplier = (XEmbeddedObjectSupplier) UnoRuntime.queryInterface(
682*1dfd36f5SLiu Zhe 					XEmbeddedObjectSupplier.class, xTableChart);
683*1dfd36f5SLiu Zhe 			xChartDocument = (XChartDocument) UnoRuntime.queryInterface(
684*1dfd36f5SLiu Zhe 					XChartDocument.class, xEmbeddedObjectSupplier.getEmbeddedObject());
685*1dfd36f5SLiu Zhe 		}
686*1dfd36f5SLiu Zhe 
687*1dfd36f5SLiu Zhe 		return xChartDocument;
688*1dfd36f5SLiu Zhe 	}
689*1dfd36f5SLiu Zhe 
690*1dfd36f5SLiu Zhe 	/**
691*1dfd36f5SLiu Zhe 	 * Set specific basic type to chart
692*1dfd36f5SLiu Zhe 	 * @param xChartDocument
693*1dfd36f5SLiu Zhe 	 * @param chartType
694*1dfd36f5SLiu Zhe 	 * @throws Exception
695*1dfd36f5SLiu Zhe 	 */
696*1dfd36f5SLiu Zhe 	public static void setChartType(XChartDocument xChartDocument, String chartType) throws Exception {
697*1dfd36f5SLiu Zhe 		XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
698*1dfd36f5SLiu Zhe 			XMultiServiceFactory.class, xChartDocument);
699*1dfd36f5SLiu Zhe 		XDiagram xDiagram = (XDiagram) UnoRuntime.queryInterface(
700*1dfd36f5SLiu Zhe 			XDiagram.class, xMultiServiceFactory.createInstance(chartType));
701*1dfd36f5SLiu Zhe 		xChartDocument.setDiagram(xDiagram);
702*1dfd36f5SLiu Zhe 	}
703*1dfd36f5SLiu Zhe 
704*1dfd36f5SLiu Zhe 	/**
705*1dfd36f5SLiu Zhe 	 * Get the type string of a chart
706*1dfd36f5SLiu Zhe 	 * @param xChartDocument
707*1dfd36f5SLiu Zhe 	 * @return
708*1dfd36f5SLiu Zhe 	 * @throws Exception
709*1dfd36f5SLiu Zhe 	 */
710*1dfd36f5SLiu Zhe 	public static String getChartType(XChartDocument xChartDocument) throws Exception {
711*1dfd36f5SLiu Zhe 		return xChartDocument.getDiagram().getDiagramType();
712*1dfd36f5SLiu Zhe 	}
713*1dfd36f5SLiu Zhe 
714*1dfd36f5SLiu Zhe 	/**
715*1dfd36f5SLiu Zhe 	 * Get the names of charts in specific sheet
716*1dfd36f5SLiu Zhe 	 * @param xSpreadsheet
717*1dfd36f5SLiu Zhe 	 * @return
718*1dfd36f5SLiu Zhe 	 * @throws Exception
719*1dfd36f5SLiu Zhe 	 */
720*1dfd36f5SLiu Zhe 	public static String[] getChartNameList(XSpreadsheet xSpreadsheet) throws Exception {
721*1dfd36f5SLiu Zhe 		XChartDocument xChartDocument = null;
722*1dfd36f5SLiu Zhe 		XTableChartsSupplier xTChartSupplier =
723*1dfd36f5SLiu Zhe 				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
724*1dfd36f5SLiu Zhe 		XTableCharts xTableCharts = xTChartSupplier.getCharts();
725*1dfd36f5SLiu Zhe 		String[] chartNames = xTableCharts.getElementNames();
726*1dfd36f5SLiu Zhe 		return chartNames;
727*1dfd36f5SLiu Zhe 	}
728*1dfd36f5SLiu Zhe 
729*1dfd36f5SLiu Zhe 
730*1dfd36f5SLiu Zhe 
731e6e6073dSLiu Zhe }
732