12fa2a90fSLiu Zhe /**************************************************************
22fa2a90fSLiu Zhe  *
32fa2a90fSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
42fa2a90fSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
52fa2a90fSLiu Zhe  * distributed with this work for additional information
62fa2a90fSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
72fa2a90fSLiu Zhe  * to you under the Apache License, Version 2.0 (the
82fa2a90fSLiu Zhe  * "License"); you may not use this file except in compliance
92fa2a90fSLiu Zhe  * with the License.  You may obtain a copy of the License at
102fa2a90fSLiu Zhe  *
112fa2a90fSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
122fa2a90fSLiu Zhe  *
132fa2a90fSLiu Zhe  * Unless required by applicable law or agreed to in writing,
142fa2a90fSLiu Zhe  * software distributed under the License is distributed on an
152fa2a90fSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162fa2a90fSLiu Zhe  * KIND, either express or implied.  See the License for the
172fa2a90fSLiu Zhe  * specific language governing permissions and limitations
182fa2a90fSLiu Zhe  * under the License.
192fa2a90fSLiu Zhe  *
202fa2a90fSLiu Zhe  *************************************************************/
212fa2a90fSLiu Zhe 
222fa2a90fSLiu Zhe 
232fa2a90fSLiu Zhe package testlib.uno;
242fa2a90fSLiu Zhe 
252fa2a90fSLiu Zhe import java.util.HashMap;
262fa2a90fSLiu Zhe 
271ea6643fSLiu Zhe import org.openoffice.test.common.FileUtil;
282fa2a90fSLiu Zhe import org.openoffice.test.common.Testspace;
292fa2a90fSLiu Zhe import org.openoffice.test.uno.UnoApp;
302fa2a90fSLiu Zhe 
31*1dfd36f5SLiu Zhe import com.sun.star.awt.Rectangle;
322fa2a90fSLiu Zhe import com.sun.star.beans.PropertyValue;
331ea6643fSLiu 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;
362fa2a90fSLiu Zhe import com.sun.star.container.XIndexAccess;
37*1dfd36f5SLiu Zhe import com.sun.star.container.XNameAccess;
38d01630b6SLiu Zhe import com.sun.star.container.XNamed;
39*1dfd36f5SLiu Zhe import com.sun.star.document.XEmbeddedObjectSupplier;
402fa2a90fSLiu Zhe import com.sun.star.frame.XController;
412fa2a90fSLiu Zhe import com.sun.star.frame.XModel;
422fa2a90fSLiu Zhe import com.sun.star.frame.XStorable;
432fa2a90fSLiu 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;
462fa2a90fSLiu Zhe import com.sun.star.sheet.XSpreadsheet;
472fa2a90fSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
482fa2a90fSLiu Zhe import com.sun.star.sheet.XSpreadsheetView;
492fa2a90fSLiu Zhe import com.sun.star.sheet.XSpreadsheets;
50*1dfd36f5SLiu Zhe import com.sun.star.table.CellRangeAddress;
512fa2a90fSLiu Zhe import com.sun.star.table.XCell;
522fa2a90fSLiu Zhe import com.sun.star.table.XCellRange;
532fa2a90fSLiu 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;
572fa2a90fSLiu Zhe import com.sun.star.table.XTableColumns;
582fa2a90fSLiu Zhe import com.sun.star.table.XTableRows;
592fa2a90fSLiu Zhe import com.sun.star.text.XText;
602fa2a90fSLiu Zhe import com.sun.star.uno.UnoRuntime;
612fa2a90fSLiu Zhe import com.sun.star.util.XCloseable;
622fa2a90fSLiu Zhe 
632fa2a90fSLiu Zhe 
642fa2a90fSLiu Zhe /**
652fa2a90fSLiu Zhe  * Utilities of Spreadsheet
662fa2a90fSLiu Zhe  *
672fa2a90fSLiu Zhe  */
682fa2a90fSLiu Zhe 
692fa2a90fSLiu Zhe public class SCUtil {
702fa2a90fSLiu Zhe 
711ea6643fSLiu Zhe 	private static final String scTempDir = "output/sc/"; //Spreadsheet temp file directory
722fa2a90fSLiu Zhe 	private static HashMap filterName = new HashMap();
731ea6643fSLiu Zhe 
743908dc91SLiu Zhe 	private SCUtil() {
752fa2a90fSLiu Zhe 
762fa2a90fSLiu Zhe 	}
772fa2a90fSLiu Zhe 
782fa2a90fSLiu Zhe 	/**
792fa2a90fSLiu Zhe 	 * Get spreadsheet document object
802fa2a90fSLiu Zhe 	 * @param xSpreadsheetComponent
812fa2a90fSLiu Zhe 	 * @return
822fa2a90fSLiu Zhe 	 * @throws Exception
832fa2a90fSLiu Zhe 	 */
842fa2a90fSLiu Zhe     public static XSpreadsheetDocument getSCDocument(XComponent xSpreadsheetComponent) throws Exception {
852fa2a90fSLiu Zhe     	XSpreadsheetDocument xSpreadsheetDocument =
862fa2a90fSLiu Zhe         		(XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSpreadsheetComponent);
872fa2a90fSLiu Zhe 
882fa2a90fSLiu Zhe         return xSpreadsheetDocument;
892fa2a90fSLiu Zhe     }
902fa2a90fSLiu Zhe 
912fa2a90fSLiu Zhe     /**
922fa2a90fSLiu Zhe      * Get sheet object by sheet name
932fa2a90fSLiu Zhe      * @param xSpreadsheetDocument
942fa2a90fSLiu Zhe      * @param sheetName
952fa2a90fSLiu Zhe      * @return
962fa2a90fSLiu Zhe      * @throws Exception
972fa2a90fSLiu Zhe      */
982fa2a90fSLiu Zhe 	public static XSpreadsheet getSCSheetByName(XSpreadsheetDocument xSpreadsheetDocument, String sheetName) throws Exception {
992fa2a90fSLiu Zhe 		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
1002fa2a90fSLiu Zhe 		XSpreadsheet xSpreadsheet =
1012fa2a90fSLiu Zhe 				(XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, xSpreadsheets.getByName(sheetName));
1022fa2a90fSLiu Zhe 
1032fa2a90fSLiu Zhe 		return xSpreadsheet;
1042fa2a90fSLiu Zhe 	}
1052fa2a90fSLiu Zhe 
1062fa2a90fSLiu Zhe 	/**
1072fa2a90fSLiu Zhe 	 * Get sheet object by sheet index
1082fa2a90fSLiu Zhe 	 * @param xSpreadsheetDocument
1092fa2a90fSLiu Zhe 	 * @param index   (Short) 0,1,2,...
1102fa2a90fSLiu Zhe 	 * @return
1112fa2a90fSLiu Zhe 	 * @throws Exception
1122fa2a90fSLiu Zhe 	 */
1132fa2a90fSLiu Zhe 	public static XSpreadsheet getSCSheetByIndex(XSpreadsheetDocument xSpreadsheetDocument, short index) throws Exception {
1142fa2a90fSLiu Zhe 		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
1152fa2a90fSLiu Zhe 		XIndexAccess xIndexAccess =
1162fa2a90fSLiu Zhe 				(XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
1172fa2a90fSLiu Zhe 		XSpreadsheet xSpreadsheet =
1182fa2a90fSLiu Zhe 				(XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, xIndexAccess.getByIndex(index));
1192fa2a90fSLiu Zhe 
1202fa2a90fSLiu Zhe 		return xSpreadsheet;
1212fa2a90fSLiu Zhe 	}
1222fa2a90fSLiu Zhe 
123d01630b6SLiu Zhe 	/**
124d01630b6SLiu Zhe 	 * Get sheet name by sheet index
125d01630b6SLiu Zhe 	 *
126d01630b6SLiu Zhe 	 * @param xSpreadsheetDocument
127d01630b6SLiu Zhe 	 * @param index
128d01630b6SLiu Zhe 	 *            (Short) 0,1,2,...
129d01630b6SLiu Zhe 	 * @return
130d01630b6SLiu Zhe 	 * @throws Exception
131d01630b6SLiu Zhe 	 */
132d01630b6SLiu Zhe 	public static String getSCSheetNameByIndex(
133d01630b6SLiu Zhe 			XSpreadsheetDocument xSpreadsheetDocument, short index)
134d01630b6SLiu Zhe 			throws Exception {
135d01630b6SLiu Zhe 		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
136d01630b6SLiu Zhe 		XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
137d01630b6SLiu Zhe 				XIndexAccess.class, xSpreadsheets);
138d01630b6SLiu Zhe 		XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
139d01630b6SLiu Zhe 				XSpreadsheet.class, xIndexAccess.getByIndex(index));
140d01630b6SLiu Zhe 		XNamed xsheetname = (XNamed) UnoRuntime.queryInterface(XNamed.class,
141d01630b6SLiu Zhe 				xSpreadsheet);
142d01630b6SLiu Zhe 		return xsheetname.getName();
143d01630b6SLiu Zhe 	}
144d01630b6SLiu Zhe 
145d01630b6SLiu Zhe 	/**
146d01630b6SLiu Zhe 	 * Set sheet name by sheet index
147d01630b6SLiu Zhe 	 *
148d01630b6SLiu Zhe 	 * @param xSpreadsheetDocument
149d01630b6SLiu Zhe 	 * @param index
150d01630b6SLiu Zhe 	 *            (Short) 0,1,2,...
151d01630b6SLiu Zhe 	 * @return
152d01630b6SLiu Zhe 	 * @throws Exception
153d01630b6SLiu Zhe 	 */
154d01630b6SLiu Zhe 	public static void setSCSheetNameByIndex(
155d01630b6SLiu Zhe 			XSpreadsheetDocument xSpreadsheetDocument, short index,
156d01630b6SLiu Zhe 			String sheetname) throws Exception {
157d01630b6SLiu Zhe 		XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
158d01630b6SLiu Zhe 		XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
159d01630b6SLiu Zhe 				XIndexAccess.class, xSpreadsheets);
160d01630b6SLiu Zhe 		XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(
161d01630b6SLiu Zhe 				XSpreadsheet.class, xIndexAccess.getByIndex(index));
162d01630b6SLiu Zhe 		XNamed xsheetname = (XNamed) UnoRuntime.queryInterface(XNamed.class,
163d01630b6SLiu Zhe 				xSpreadsheet);
164d01630b6SLiu Zhe 		xsheetname.setName(sheetname);
165d01630b6SLiu Zhe 	}
166d01630b6SLiu Zhe 
1672fa2a90fSLiu Zhe 	/**
1682fa2a90fSLiu Zhe 	 * Get rows object
1692fa2a90fSLiu Zhe 	 * @param xSpreadsheet
1702fa2a90fSLiu Zhe 	 * @return
1712fa2a90fSLiu Zhe 	 * @throws Exception
1722fa2a90fSLiu Zhe 	 */
1732fa2a90fSLiu Zhe 	public static XTableRows getSCRows(XSpreadsheet xSpreadsheet) throws Exception {
1742fa2a90fSLiu Zhe 		XColumnRowRange xColumnRowRange =
1752fa2a90fSLiu Zhe 				(XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
1762fa2a90fSLiu Zhe 		XTableRows xTableRows = xColumnRowRange.getRows();
1772fa2a90fSLiu Zhe 
1782fa2a90fSLiu Zhe 		return xTableRows;
1792fa2a90fSLiu Zhe 	}
1802fa2a90fSLiu Zhe 
1812fa2a90fSLiu Zhe 	/**
1822fa2a90fSLiu Zhe 	 * Get columns object
1832fa2a90fSLiu Zhe 	 * @param xSpreadsheet
1842fa2a90fSLiu Zhe 	 * @return
1852fa2a90fSLiu Zhe 	 * @throws Exception
1862fa2a90fSLiu Zhe 	 */
1872fa2a90fSLiu Zhe 	public static XTableColumns getSCColumns(XSpreadsheet xSpreadsheet) throws Exception {
1882fa2a90fSLiu Zhe 		XColumnRowRange xColumnRowRange =
1892fa2a90fSLiu Zhe 				(XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
1902fa2a90fSLiu Zhe 		XTableColumns xTableColumns = xColumnRowRange.getColumns();
1912fa2a90fSLiu Zhe 
1922fa2a90fSLiu Zhe 		return xTableColumns;
1932fa2a90fSLiu Zhe 	}
1942fa2a90fSLiu Zhe 
1952fa2a90fSLiu Zhe 	/**
1962fa2a90fSLiu Zhe 	 * Set floating number into specific cell
1972fa2a90fSLiu Zhe 	 * @param xSpreadsheet
1982fa2a90fSLiu Zhe 	 * @param column
1992fa2a90fSLiu Zhe 	 * @param row
2002fa2a90fSLiu Zhe 	 * @param value
2012fa2a90fSLiu Zhe 	 * @throws Exception
2022fa2a90fSLiu Zhe 	 */
2032fa2a90fSLiu Zhe 	public static void setValueToCell(XSpreadsheet xSpreadsheet, int column, int row, double value) throws Exception {
2042fa2a90fSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
2052fa2a90fSLiu Zhe 		xCell.setValue(value);
2062fa2a90fSLiu Zhe 	}
2072fa2a90fSLiu Zhe 
2082fa2a90fSLiu Zhe 	/**
2092fa2a90fSLiu Zhe 	 * Set text into specific cell
2102fa2a90fSLiu Zhe 	 * @param xSpreadsheet
2112fa2a90fSLiu Zhe 	 * @param column
2122fa2a90fSLiu Zhe 	 * @param row
2132fa2a90fSLiu Zhe 	 * @param text
2142fa2a90fSLiu Zhe 	 * @throws Exception
2152fa2a90fSLiu Zhe 	 */
2162fa2a90fSLiu Zhe 	public static void setTextToCell(XSpreadsheet xSpreadsheet, int column, int row, String text) throws Exception {
2172fa2a90fSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
2182fa2a90fSLiu Zhe 		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
2192fa2a90fSLiu Zhe 		xText.setString(text);
2202fa2a90fSLiu Zhe 	}
2212fa2a90fSLiu Zhe 
2221ea6643fSLiu Zhe 	/**
2231ea6643fSLiu Zhe 	 * Set text into specific cell
2241ea6643fSLiu Zhe 	 * @param xCell
2251ea6643fSLiu Zhe 	 * @param text
2261ea6643fSLiu Zhe 	 * @throws Exception
2271ea6643fSLiu Zhe 	 */
2281ea6643fSLiu Zhe 	public static void setTextToCell(XCell xCell, String text) throws Exception {
2291ea6643fSLiu Zhe 		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
2301ea6643fSLiu Zhe 		xText.setString(text);
2311ea6643fSLiu Zhe 	}
2321ea6643fSLiu Zhe 
2332fa2a90fSLiu Zhe 	/**
2342fa2a90fSLiu Zhe 	 * Set formula into specific cell
2352fa2a90fSLiu Zhe 	 * @param xSpreadsheet
2362fa2a90fSLiu Zhe 	 * @param column
2372fa2a90fSLiu Zhe 	 * @param row
2382fa2a90fSLiu Zhe 	 * @param formula
2392fa2a90fSLiu Zhe 	 * @throws Exception
2402fa2a90fSLiu Zhe 	 */
2412fa2a90fSLiu Zhe 	public static void setFormulaToCell(XSpreadsheet xSpreadsheet, int column, int row, String formula) throws Exception {
2422fa2a90fSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
2432fa2a90fSLiu Zhe 		xCell.setFormula(formula);
2442fa2a90fSLiu Zhe 	}
2452fa2a90fSLiu Zhe 
2462fa2a90fSLiu Zhe 	/**
2472fa2a90fSLiu Zhe 	 * Get value from specific cell
2482fa2a90fSLiu Zhe 	 * @param xSpreadsheet
2492fa2a90fSLiu Zhe 	 * @param column
2502fa2a90fSLiu Zhe 	 * @param row
2512fa2a90fSLiu Zhe 	 * @return
2522fa2a90fSLiu Zhe 	 * @throws Exception
2532fa2a90fSLiu Zhe 	 */
2542fa2a90fSLiu Zhe 	public static double getValueFromCell(XSpreadsheet xSpreadsheet, int column, int row) throws Exception {
2552fa2a90fSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
2562fa2a90fSLiu Zhe 		double cellValue = xCell.getValue();
2572fa2a90fSLiu Zhe 
2582fa2a90fSLiu Zhe 		return cellValue;
2592fa2a90fSLiu Zhe 	}
2602fa2a90fSLiu Zhe 
2612fa2a90fSLiu Zhe 	/**
2622fa2a90fSLiu Zhe 	 * Get text from specific cell
2632fa2a90fSLiu Zhe 	 * @param xSpreadsheet
2642fa2a90fSLiu Zhe 	 * @param column
2652fa2a90fSLiu Zhe 	 * @param row
2662fa2a90fSLiu Zhe 	 *
2672fa2a90fSLiu Zhe 	 * @return
2682fa2a90fSLiu Zhe 	 * @throws Exception
2692fa2a90fSLiu Zhe 	 */
2702fa2a90fSLiu Zhe 	public static String getTextFromCell(XSpreadsheet xSpreadsheet, int column, int row) throws Exception {
2712fa2a90fSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
2722fa2a90fSLiu Zhe 		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
2732fa2a90fSLiu Zhe 
2742fa2a90fSLiu Zhe 		return xText.getString();
2752fa2a90fSLiu Zhe 	}
2762fa2a90fSLiu Zhe 
2772fa2a90fSLiu Zhe 	/**
2782fa2a90fSLiu Zhe 	 * Get formula string from specific cell
2792fa2a90fSLiu Zhe 	 * @param xSpreadsheet
2802fa2a90fSLiu Zhe 	 * @param column
2812fa2a90fSLiu Zhe 	 * @param row
2822fa2a90fSLiu Zhe 	 * @return
2832fa2a90fSLiu Zhe 	 * @throws Exception
2842fa2a90fSLiu Zhe 	 */
2852fa2a90fSLiu Zhe 	public static String getFormulaFromCell(XSpreadsheet xSpreadsheet, int column, int row) throws Exception {
2862fa2a90fSLiu Zhe 		XCell xCell = xSpreadsheet.getCellByPosition(column, row);
2872fa2a90fSLiu Zhe 		String cellFormula = xCell.getFormula();
2882fa2a90fSLiu Zhe 
2892fa2a90fSLiu Zhe 		return cellFormula;
2902fa2a90fSLiu Zhe 	}
2912fa2a90fSLiu Zhe 
2922fa2a90fSLiu Zhe 	/**
2932fa2a90fSLiu Zhe 	 * Set numbers into a cell range
2942fa2a90fSLiu Zhe 	 * @param xSpreadsheet
2952fa2a90fSLiu Zhe 	 * @param start_col
2962fa2a90fSLiu Zhe 	 * @param start_row
2972fa2a90fSLiu Zhe 	 * @param end_col
2982fa2a90fSLiu Zhe 	 * @param end_row
2992fa2a90fSLiu Zhe 	 * @param values
3002fa2a90fSLiu Zhe 	 * @throws Exception
3012fa2a90fSLiu Zhe 	 */
302*1dfd36f5SLiu Zhe 	@Deprecated
3032fa2a90fSLiu Zhe 	public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row,  double[][] values) throws Exception {
3042fa2a90fSLiu Zhe 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
3052fa2a90fSLiu Zhe 		XCell xCell = null;
3062fa2a90fSLiu Zhe 		for (int i = 0; i <= (end_row - start_row); i++ ) {
3072fa2a90fSLiu Zhe 			for(int j = 0; j <= (end_col - start_col); j++) {
3082fa2a90fSLiu Zhe 				xCell = xCellRange.getCellByPosition(j, i);
3092fa2a90fSLiu Zhe 				xCell.setValue(values[i][j]);
3102fa2a90fSLiu Zhe 			}
3112fa2a90fSLiu Zhe 		}
3122fa2a90fSLiu Zhe 	}
3132fa2a90fSLiu 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 
3252fa2a90fSLiu Zhe 	/**
3262fa2a90fSLiu Zhe 	 * Set text into a cell range
3272fa2a90fSLiu Zhe 	 * @param xSpreadsheet
3282fa2a90fSLiu Zhe 	 * @param start_col
3292fa2a90fSLiu Zhe 	 * @param start_row
3302fa2a90fSLiu Zhe 	 * @param end_col
3312fa2a90fSLiu Zhe 	 * @param end_row
3322fa2a90fSLiu Zhe 	 * @param texts
3332fa2a90fSLiu Zhe 	 * @throws Exception
3342fa2a90fSLiu Zhe 	 */
335*1dfd36f5SLiu Zhe 	@Deprecated
3362fa2a90fSLiu Zhe 	public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row,  String[][] texts) throws Exception {
3372fa2a90fSLiu Zhe 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
3382fa2a90fSLiu Zhe 		XCell xCell = null;
3392fa2a90fSLiu Zhe 		XText xText = null;
3402fa2a90fSLiu Zhe 		for (int i = 0; i <= (end_row - start_row); i++ ) {
3412fa2a90fSLiu Zhe 			for(int j = 0; j <= (end_col - start_col); j++) {
3422fa2a90fSLiu Zhe 				xCell = xCellRange.getCellByPosition(j, i);
3432fa2a90fSLiu Zhe 				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
3442fa2a90fSLiu Zhe 				xText.setString(texts[i][j]);
3452fa2a90fSLiu Zhe 			}
3462fa2a90fSLiu Zhe 		}
3472fa2a90fSLiu Zhe 	}
3482fa2a90fSLiu 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 
3622fa2a90fSLiu Zhe 	/**
3632fa2a90fSLiu Zhe 	 * Get number content from a cell range
3642fa2a90fSLiu Zhe 	 * @param xSpreadsheet
3652fa2a90fSLiu Zhe 	 * @param start_col
3662fa2a90fSLiu Zhe 	 * @param start_row
3672fa2a90fSLiu Zhe 	 * @param end_col
3682fa2a90fSLiu Zhe 	 * @param end_row
3692fa2a90fSLiu Zhe 	 * @return
3702fa2a90fSLiu Zhe 	 * @throws Exception
3712fa2a90fSLiu Zhe 	 */
3722fa2a90fSLiu Zhe 	public static double[][] getValueFromCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row) throws Exception {
3732fa2a90fSLiu Zhe 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
3742fa2a90fSLiu Zhe 		XCell xCell = null;
3752fa2a90fSLiu Zhe 		double[][] cellValues = new double[end_row - start_row+1][end_col - start_col +1];
3762fa2a90fSLiu Zhe 
3772fa2a90fSLiu Zhe 		for (int i = 0; i <= (end_row - start_row); i++ ) {
3782fa2a90fSLiu Zhe 			for(int j = 0; j <= (end_col - start_col); j++) {
3792fa2a90fSLiu Zhe 				xCell = xCellRange.getCellByPosition(j, i);
3802fa2a90fSLiu Zhe 				cellValues[i][j] = xCell.getValue();
3812fa2a90fSLiu Zhe 			}
3822fa2a90fSLiu Zhe 		}
3832fa2a90fSLiu Zhe 
3842fa2a90fSLiu Zhe 		return cellValues;
3852fa2a90fSLiu Zhe 	}
3862fa2a90fSLiu Zhe 
3872fa2a90fSLiu Zhe 	/**
3882fa2a90fSLiu Zhe 	 * Get text content from a cell range
3892fa2a90fSLiu Zhe 	 * @param xSpreadsheet
3902fa2a90fSLiu Zhe 	 * @param start_col
3912fa2a90fSLiu Zhe 	 * @param start_row
3922fa2a90fSLiu Zhe 	 * @param end_col
3932fa2a90fSLiu Zhe 	 * @param end_row
3942fa2a90fSLiu Zhe 	 * @return
3952fa2a90fSLiu Zhe 	 * @throws Exception
3962fa2a90fSLiu Zhe 	 */
3972fa2a90fSLiu Zhe 	public static String[][] getTextFromCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row) throws Exception {
3982fa2a90fSLiu Zhe 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row);
3992fa2a90fSLiu Zhe 		XCell xCell = null;
4002fa2a90fSLiu Zhe 		XText xText = null;
4012fa2a90fSLiu Zhe 		String[][] cellTexts = new String[end_row - start_row+1][end_col - start_col +1];
4022fa2a90fSLiu Zhe 
4032fa2a90fSLiu Zhe 		for (int i = 0; i <= (end_row - start_row); i++ ) {
4041ea6643fSLiu Zhe 			for (int j = 0; j <= (end_col - start_col); j++) {
4052fa2a90fSLiu Zhe 				xCell = xCellRange.getCellByPosition(j, i);
4062fa2a90fSLiu Zhe 				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
4072fa2a90fSLiu Zhe 				cellTexts[i][j] = xText.getString();
4082fa2a90fSLiu Zhe 			}
4092fa2a90fSLiu Zhe 		}
4102fa2a90fSLiu Zhe 
4112fa2a90fSLiu Zhe 		return cellTexts;
4122fa2a90fSLiu Zhe 	}
4132fa2a90fSLiu Zhe 
4142fa2a90fSLiu Zhe 	//TODO ZS - public static String[][] getAllFromCellRange
4152fa2a90fSLiu Zhe 
4162fa2a90fSLiu Zhe 	/**
4172fa2a90fSLiu Zhe 	 * Switch to specific sheet
4182fa2a90fSLiu Zhe 	 * @param xSpreadsheetDocument
4192fa2a90fSLiu Zhe 	 * @param xSpreadsheet
4202fa2a90fSLiu Zhe 	 */
4212fa2a90fSLiu Zhe 	public static void setCurrentSheet(XSpreadsheetDocument xSpreadsheetDocument, XSpreadsheet xSpreadsheet) throws Exception {
4222fa2a90fSLiu Zhe 		XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xSpreadsheetDocument);
4232fa2a90fSLiu Zhe 		XController xController = xModel.getCurrentController();
4242fa2a90fSLiu Zhe 		XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, xController);
4252fa2a90fSLiu Zhe 		xSpreadsheetView.setActiveSheet(xSpreadsheet);
4262fa2a90fSLiu Zhe 	}
4272fa2a90fSLiu Zhe 
4282fa2a90fSLiu Zhe 	/**
4292fa2a90fSLiu Zhe 	 * Get sheet object of current active sheet
4302fa2a90fSLiu Zhe 	 * @param xSpreadsheetDocument
4312fa2a90fSLiu Zhe 	 * @return
4322fa2a90fSLiu Zhe 	 */
4332fa2a90fSLiu Zhe 	public static XSpreadsheet getCurrentSheet(XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
4342fa2a90fSLiu Zhe 		XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xSpreadsheetDocument);
4352fa2a90fSLiu Zhe 		XController xController = xModel.getCurrentController();
4362fa2a90fSLiu Zhe 		XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, xController);
4372fa2a90fSLiu Zhe 		XSpreadsheet xSpreadsheet = xSpreadsheetView.getActiveSheet();
4382fa2a90fSLiu Zhe 
4392fa2a90fSLiu Zhe 		return xSpreadsheet;
4402fa2a90fSLiu Zhe 	}
4412fa2a90fSLiu Zhe 
442d01630b6SLiu Zhe 	/**
443d01630b6SLiu Zhe 	 * Get sheet object by sheet index
444d01630b6SLiu Zhe 	 *
445d01630b6SLiu Zhe 	 * @param xSpreadsheetDocument
446d01630b6SLiu Zhe 	 * @return
447d01630b6SLiu Zhe 	 * @throws Exception
448d01630b6SLiu Zhe 	 */
449d01630b6SLiu Zhe 	public static String getSCActiveSheetName(
450d01630b6SLiu Zhe 			XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
451d01630b6SLiu Zhe 		XModel xSpreadsheetModel = (XModel) UnoRuntime.queryInterface(
452d01630b6SLiu Zhe 				XModel.class, xSpreadsheetDocument);
453d01630b6SLiu Zhe 		XSpreadsheetView xSpeadsheetView = (XSpreadsheetView) UnoRuntime
454d01630b6SLiu Zhe 				.queryInterface(XSpreadsheetView.class,
455d01630b6SLiu Zhe 						xSpreadsheetModel.getCurrentController());
456d01630b6SLiu Zhe 		XSpreadsheet activesheet = xSpeadsheetView.getActiveSheet();
457d01630b6SLiu Zhe 		XNamed activesheetName = (XNamed) UnoRuntime.queryInterface(
458d01630b6SLiu Zhe 				XNamed.class, activesheet);
459d01630b6SLiu Zhe 		return activesheetName.getName();
460d01630b6SLiu Zhe 	}
461d01630b6SLiu Zhe 
462*1dfd36f5SLiu 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 
4902fa2a90fSLiu Zhe 	/**
4911ea6643fSLiu Zhe 	 * Set value of specific property from a cell
4921ea6643fSLiu Zhe 	 * @param xCell
4931ea6643fSLiu Zhe 	 * @param propName
4941ea6643fSLiu Zhe 	 * @param value
4951ea6643fSLiu Zhe 	 * @throws Exception
4961ea6643fSLiu Zhe 	 */
4971ea6643fSLiu Zhe 	public static void setCellProperties(XCell xCell, String propName, Object value) throws Exception {
4981ea6643fSLiu Zhe 
499*1dfd36f5SLiu Zhe 		setProperties(xCell, propName, value);
5001ea6643fSLiu Zhe 	}
5011ea6643fSLiu Zhe 
5021ea6643fSLiu Zhe 	/**
5031ea6643fSLiu Zhe 	 * Get value of specific property from a cell
5041ea6643fSLiu Zhe 	 * @param xCell
5051ea6643fSLiu Zhe 	 * @param propName
5061ea6643fSLiu Zhe 	 * @return
5071ea6643fSLiu Zhe 	 * @throws Exception
5081ea6643fSLiu Zhe 	 */
5091ea6643fSLiu Zhe 	public static Object getCellProperties(XCell xCell, String propName) throws Exception {
510*1dfd36f5SLiu Zhe 			return getProperties(xCell, propName);
5111ea6643fSLiu Zhe 	}
5121ea6643fSLiu Zhe 
5131ea6643fSLiu Zhe 	/**
5141ea6643fSLiu Zhe 	 * Clear temp file directory
5151ea6643fSLiu Zhe 	 */
5161ea6643fSLiu Zhe 	public static void clearTempDir() {
5171ea6643fSLiu Zhe 		FileUtil.deleteFile(Testspace.getFile(Testspace.getPath(scTempDir)));
5181ea6643fSLiu Zhe 	}
5191ea6643fSLiu Zhe 
5201ea6643fSLiu Zhe 	/**
5211ea6643fSLiu Zhe 	 * Save file as specific file format into spreadsheet temp file folder.
5222fa2a90fSLiu Zhe 	 * @param scComponent
5232fa2a90fSLiu Zhe 	 * @param fileName  File name string without extension name (e.g. "sampleFile")
5242fa2a90fSLiu Zhe 	 * @param extName ("ods", "ots", "xls", "xlt", "csv")
5252fa2a90fSLiu Zhe 	 * @throws Exception
5262fa2a90fSLiu Zhe 	 */
5272fa2a90fSLiu Zhe 	public static void saveFileAs(XComponent scComponent, String fileName, String extName) throws Exception {
5282fa2a90fSLiu Zhe 
5292fa2a90fSLiu Zhe 		initFilterName();
5302fa2a90fSLiu Zhe 
5311ea6643fSLiu Zhe 		String storeUrl = Testspace.getUrl(scTempDir + fileName + "." + extName);
5322fa2a90fSLiu Zhe 
5332fa2a90fSLiu Zhe 		PropertyValue[] storeProps = new PropertyValue[2];
5342fa2a90fSLiu Zhe 		storeProps[0] = new PropertyValue();
5352fa2a90fSLiu Zhe 		storeProps[0].Name = "FilterName";
5362fa2a90fSLiu Zhe 		storeProps[0].Value = filterName.get(extName);
5372fa2a90fSLiu Zhe 		storeProps[1] = new PropertyValue();
5382fa2a90fSLiu Zhe 		storeProps[1].Name = "Overwrite";
5392fa2a90fSLiu Zhe 		storeProps[1].Value = new Boolean(true);
5402fa2a90fSLiu Zhe 
5412fa2a90fSLiu Zhe 		XStorable scStorable =
5422fa2a90fSLiu Zhe 				(XStorable) UnoRuntime.queryInterface(XStorable.class, scComponent);
5432fa2a90fSLiu Zhe 		scStorable.storeAsURL(storeUrl, storeProps);
5442fa2a90fSLiu Zhe 	}
5452fa2a90fSLiu Zhe 
546d01630b6SLiu Zhe 	/**
547*1dfd36f5SLiu Zhe 	 * Save file after open file.
548d01630b6SLiu Zhe 	 * @param xSpreadsheetDocument
549d01630b6SLiu Zhe 	 * @throws Exception
550d01630b6SLiu Zhe 	 */
551d01630b6SLiu Zhe 	public static void save(XSpreadsheetDocument xSpreadsheetDocument)
552d01630b6SLiu Zhe 			throws Exception {
553d01630b6SLiu Zhe 		XStorable scStorable = (XStorable) UnoRuntime.queryInterface(
554d01630b6SLiu Zhe 				XStorable.class, xSpreadsheetDocument);
555d01630b6SLiu Zhe 		scStorable.store();
556d01630b6SLiu Zhe 	}
557d01630b6SLiu Zhe 
558d01630b6SLiu Zhe 
5592fa2a90fSLiu Zhe 	/**
5602fa2a90fSLiu Zhe 	 * Close specific opening spreadsheet file which has been saved
5612fa2a90fSLiu Zhe 	 * @param xSpreadsheetDocument
5622fa2a90fSLiu Zhe 	 * @throws Exception
5632fa2a90fSLiu Zhe 	 */
5642fa2a90fSLiu Zhe 	public static void closeFile(XSpreadsheetDocument xSpreadsheetDocument) throws Exception {
5652fa2a90fSLiu Zhe 		XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xSpreadsheetDocument);
5662fa2a90fSLiu Zhe 		xCloseable.close(false);
5672fa2a90fSLiu Zhe 	}
5682fa2a90fSLiu Zhe 
5692fa2a90fSLiu Zhe 	/**
5701ea6643fSLiu Zhe 	 * Close a opening file saved in spreadsheet temp file direction and reopen it in Spreadsheet. For save&reload test scenario only.
5712fa2a90fSLiu Zhe 	 * @param unoApp
5722fa2a90fSLiu Zhe 	 * @param xSpreadsheetDocument
5732fa2a90fSLiu Zhe 	 * @param fullFileName   File name with the extension name. (e.g. "sc.ods")
5742fa2a90fSLiu Zhe 	 * @return
5752fa2a90fSLiu Zhe 	 * @throws Exception
5762fa2a90fSLiu Zhe 	 */
5772fa2a90fSLiu Zhe 	public static XSpreadsheetDocument reloadFile(UnoApp unoApp, XSpreadsheetDocument xSpreadsheetDocument, String fullFileName) throws Exception {
5782fa2a90fSLiu Zhe 		closeFile(xSpreadsheetDocument);
5792fa2a90fSLiu Zhe 
5801ea6643fSLiu Zhe 		String filePath = Testspace.getPath(scTempDir + fullFileName);
581cebb507aSLiu Zhe 		XSpreadsheetDocument xScDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, unoApp.loadDocument(filePath));
5822fa2a90fSLiu Zhe 
5832fa2a90fSLiu Zhe 		return xScDocument;
5842fa2a90fSLiu Zhe 	}
5852fa2a90fSLiu Zhe 
5869fdcf9fdSLiu 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 
5972fa2a90fSLiu Zhe 	/**
5982fa2a90fSLiu Zhe 	 * Initial the filter name list
5992fa2a90fSLiu Zhe 	 * @throws Exception
6002fa2a90fSLiu Zhe 	 */
6012fa2a90fSLiu Zhe 	private static void initFilterName() throws Exception {
6022fa2a90fSLiu Zhe 		if (filterName.size() > 0) {
6032fa2a90fSLiu Zhe 			return;
6042fa2a90fSLiu Zhe 		}
6052fa2a90fSLiu Zhe 
6062fa2a90fSLiu Zhe 		filterName.put("ods", "calc8");
6072fa2a90fSLiu Zhe 		filterName.put("ots", "calc8_template");
6082fa2a90fSLiu Zhe 		filterName.put("xls", "MS Excel 97");
6092fa2a90fSLiu Zhe 		filterName.put("xlt", "MS Excel 97 Vorlage/Template");
6102fa2a90fSLiu Zhe 		filterName.put("csv", "Text - txt - csv (StarCalc)");
6112fa2a90fSLiu Zhe 	}
612*1dfd36f5SLiu 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 
7302fa2a90fSLiu Zhe 
7312fa2a90fSLiu Zhe }
732