Lines 28-48
Link Here
|
28 |
import org.openoffice.test.common.Testspace; |
28 |
import org.openoffice.test.common.Testspace; |
29 |
import org.openoffice.test.uno.UnoApp; |
29 |
import org.openoffice.test.uno.UnoApp; |
30 |
|
30 |
|
|
|
31 |
import com.sun.star.awt.Rectangle; |
31 |
import com.sun.star.beans.PropertyValue; |
32 |
import com.sun.star.beans.PropertyValue; |
32 |
import com.sun.star.beans.XPropertySet; |
33 |
import com.sun.star.beans.XPropertySet; |
|
|
34 |
import com.sun.star.chart.XChartDocument; |
35 |
import com.sun.star.chart.XDiagram; |
33 |
import com.sun.star.container.XIndexAccess; |
36 |
import com.sun.star.container.XIndexAccess; |
|
|
37 |
import com.sun.star.container.XNameAccess; |
34 |
import com.sun.star.container.XNamed; |
38 |
import com.sun.star.container.XNamed; |
|
|
39 |
import com.sun.star.document.XEmbeddedObjectSupplier; |
35 |
import com.sun.star.frame.XController; |
40 |
import com.sun.star.frame.XController; |
36 |
import com.sun.star.frame.XModel; |
41 |
import com.sun.star.frame.XModel; |
37 |
import com.sun.star.frame.XStorable; |
42 |
import com.sun.star.frame.XStorable; |
38 |
import com.sun.star.lang.XComponent; |
43 |
import com.sun.star.lang.XComponent; |
|
|
44 |
import com.sun.star.lang.XMultiServiceFactory; |
45 |
import com.sun.star.sheet.XCellRangeAddressable; |
39 |
import com.sun.star.sheet.XSpreadsheet; |
46 |
import com.sun.star.sheet.XSpreadsheet; |
40 |
import com.sun.star.sheet.XSpreadsheetDocument; |
47 |
import com.sun.star.sheet.XSpreadsheetDocument; |
41 |
import com.sun.star.sheet.XSpreadsheetView; |
48 |
import com.sun.star.sheet.XSpreadsheetView; |
42 |
import com.sun.star.sheet.XSpreadsheets; |
49 |
import com.sun.star.sheet.XSpreadsheets; |
|
|
50 |
import com.sun.star.table.CellRangeAddress; |
43 |
import com.sun.star.table.XCell; |
51 |
import com.sun.star.table.XCell; |
44 |
import com.sun.star.table.XCellRange; |
52 |
import com.sun.star.table.XCellRange; |
45 |
import com.sun.star.table.XColumnRowRange; |
53 |
import com.sun.star.table.XColumnRowRange; |
|
|
54 |
import com.sun.star.table.XTableChart; |
55 |
import com.sun.star.table.XTableCharts; |
56 |
import com.sun.star.table.XTableChartsSupplier; |
46 |
import com.sun.star.table.XTableColumns; |
57 |
import com.sun.star.table.XTableColumns; |
47 |
import com.sun.star.table.XTableRows; |
58 |
import com.sun.star.table.XTableRows; |
48 |
import com.sun.star.text.XText; |
59 |
import com.sun.star.text.XText; |
Lines 288-293
Link Here
|
288 |
* @param values |
299 |
* @param values |
289 |
* @throws Exception |
300 |
* @throws Exception |
290 |
*/ |
301 |
*/ |
|
|
302 |
@Deprecated |
291 |
public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row, double[][] values) throws Exception { |
303 |
public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row, double[][] values) throws Exception { |
292 |
XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row); |
304 |
XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row); |
293 |
XCell xCell = null; |
305 |
XCell xCell = null; |
Lines 299-304
Link Here
|
299 |
} |
311 |
} |
300 |
} |
312 |
} |
301 |
|
313 |
|
|
|
314 |
public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, double[][] values) throws Exception { |
315 |
XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, start_col + values[0].length - 1, start_row + values.length - 1); |
316 |
XCell xCell = null; |
317 |
for (int i = 0; i < values.length; i++ ) { |
318 |
for(int j = 0; j < values[0].length; j++) { |
319 |
xCell = xCellRange.getCellByPosition(j, i); |
320 |
xCell.setValue(values[i][j]); |
321 |
} |
322 |
} |
323 |
} |
324 |
|
302 |
/** |
325 |
/** |
303 |
* Set text into a cell range |
326 |
* Set text into a cell range |
304 |
* @param xSpreadsheet |
327 |
* @param xSpreadsheet |
Lines 309-314
Link Here
|
309 |
* @param texts |
332 |
* @param texts |
310 |
* @throws Exception |
333 |
* @throws Exception |
311 |
*/ |
334 |
*/ |
|
|
335 |
@Deprecated |
312 |
public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row, String[][] texts) throws Exception { |
336 |
public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, int end_col, int end_row, String[][] texts) throws Exception { |
313 |
XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row); |
337 |
XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col, end_row); |
314 |
XCell xCell = null; |
338 |
XCell xCell = null; |
Lines 322-327
Link Here
|
322 |
} |
346 |
} |
323 |
} |
347 |
} |
324 |
|
348 |
|
|
|
349 |
public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row, String[][] texts) throws Exception { |
350 |
XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, start_col + texts[0].length - 1, start_row + texts.length - 1); |
351 |
XCell xCell = null; |
352 |
XText xText = null; |
353 |
for (int i = 0; i < texts.length; i++ ) { |
354 |
for(int j = 0; j < texts[0].length; j++) { |
355 |
xCell = xCellRange.getCellByPosition(j, i); |
356 |
xText = (XText) UnoRuntime.queryInterface(XText.class, xCell); |
357 |
xText.setString(texts[i][j]); |
358 |
} |
359 |
} |
360 |
} |
361 |
|
325 |
/** |
362 |
/** |
326 |
* Get number content from a cell range |
363 |
* Get number content from a cell range |
327 |
* @param xSpreadsheet |
364 |
* @param xSpreadsheet |
Lines 423-428
Link Here
|
423 |
} |
460 |
} |
424 |
|
461 |
|
425 |
/** |
462 |
/** |
|
|
463 |
* Set specific property's value for an object |
464 |
* @param obj |
465 |
* @param propName |
466 |
* @param value |
467 |
* @throws Exception |
468 |
*/ |
469 |
public static void setProperties(Object obj, String propName, Object value) throws Exception { |
470 |
XPropertySet xPropertySet = |
471 |
(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, obj); |
472 |
xPropertySet.setPropertyValue(propName, value); |
473 |
} |
474 |
|
475 |
/** |
476 |
* Get specific property's value of an object |
477 |
* @param obj |
478 |
* @param propName |
479 |
* @return |
480 |
* @throws Exception |
481 |
*/ |
482 |
public static Object getProperties(Object obj, String propName) throws Exception { |
483 |
XPropertySet xPropertySet = |
484 |
(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, obj); |
485 |
Object value = xPropertySet.getPropertyValue(propName); |
486 |
|
487 |
return value; |
488 |
} |
489 |
|
490 |
/** |
426 |
* Set value of specific property from a cell |
491 |
* Set value of specific property from a cell |
427 |
* @param xCell |
492 |
* @param xCell |
428 |
* @param propName |
493 |
* @param propName |
Lines 431-438
Link Here
|
431 |
*/ |
496 |
*/ |
432 |
public static void setCellProperties(XCell xCell, String propName, Object value) throws Exception { |
497 |
public static void setCellProperties(XCell xCell, String propName, Object value) throws Exception { |
433 |
|
498 |
|
434 |
XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCell); |
499 |
setProperties(xCell, propName, value); |
435 |
xPropertySet.setPropertyValue(propName, value); |
|
|
436 |
} |
500 |
} |
437 |
|
501 |
|
438 |
/** |
502 |
/** |
Lines 443-452
Link Here
|
443 |
* @throws Exception |
507 |
* @throws Exception |
444 |
*/ |
508 |
*/ |
445 |
public static Object getCellProperties(XCell xCell, String propName) throws Exception { |
509 |
public static Object getCellProperties(XCell xCell, String propName) throws Exception { |
446 |
XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCell); |
510 |
return getProperties(xCell, propName); |
447 |
Object value = xPropertySet.getPropertyValue(propName); |
|
|
448 |
|
449 |
return value; |
450 |
} |
511 |
} |
451 |
|
512 |
|
452 |
/** |
513 |
/** |
Lines 483-500
Link Here
|
483 |
} |
544 |
} |
484 |
|
545 |
|
485 |
/** |
546 |
/** |
486 |
* Save file after open file. |
547 |
* Save file after open file. |
487 |
* |
|
|
488 |
* @param xSpreadsheetDocument |
548 |
* @param xSpreadsheetDocument |
489 |
* @throws Exception |
549 |
* @throws Exception |
490 |
*/ |
550 |
*/ |
491 |
public static void save(XSpreadsheetDocument xSpreadsheetDocument) |
551 |
public static void save(XSpreadsheetDocument xSpreadsheetDocument) |
492 |
throws Exception { |
552 |
throws Exception { |
493 |
|
|
|
494 |
XStorable scStorable = (XStorable) UnoRuntime.queryInterface( |
553 |
XStorable scStorable = (XStorable) UnoRuntime.queryInterface( |
495 |
XStorable.class, xSpreadsheetDocument); |
554 |
XStorable.class, xSpreadsheetDocument); |
496 |
scStorable.store(); |
555 |
scStorable.store(); |
497 |
|
|
|
498 |
} |
556 |
} |
499 |
|
557 |
|
500 |
|
558 |
|
Lines 527-534
Link Here
|
527 |
|
585 |
|
528 |
/** |
586 |
/** |
529 |
* open file in Spreadsheet. |
587 |
* open file in Spreadsheet. |
530 |
* @param unoApp |
588 |
* @param app |
531 |
* @param filtpath File path with the extension name. (e.g. "testcase/uno/sc/data/sample.xls") |
589 |
* @param filePath File path with the extension name. (e.g. "testcase/uno/sc/data/sample.xls") |
532 |
* @return |
590 |
* @return |
533 |
* @throws Exception |
591 |
* @throws Exception |
534 |
*/ |
592 |
*/ |
Lines 551-555
Link Here
|
551 |
filterName.put("xlt", "MS Excel 97 Vorlage/Template"); |
609 |
filterName.put("xlt", "MS Excel 97 Vorlage/Template"); |
552 |
filterName.put("csv", "Text - txt - csv (StarCalc)"); |
610 |
filterName.put("csv", "Text - txt - csv (StarCalc)"); |
553 |
} |
611 |
} |
|
|
612 |
|
613 |
|
614 |
/*************************************************************** |
615 |
* Chart Utility method - using chart interface * |
616 |
****************************************************************/ |
554 |
|
617 |
|
|
|
618 |
/** |
619 |
* Get a CellRangeAddress by cell range reference name |
620 |
* @param xSpreadsheet |
621 |
* @param rangeName a cell range reference name(e.g. "A1:B2") |
622 |
* @return |
623 |
*/ |
624 |
public static CellRangeAddress getChartDataRangeByName(XSpreadsheet xSpreadsheet, String rangeName) { |
625 |
XCellRange cellRange = xSpreadsheet.getCellRangeByName(rangeName); |
626 |
XCellRangeAddressable xCellRangeAddressable = |
627 |
(XCellRangeAddressable) UnoRuntime.queryInterface(XCellRangeAddressable.class, cellRange); |
628 |
|
629 |
CellRangeAddress cellRangeAddress = xCellRangeAddressable.getRangeAddress(); |
630 |
return cellRangeAddress; |
631 |
} |
632 |
|
633 |
/** |
634 |
* Create a spreadsheet chart with data in a specific cell range. |
635 |
* @param xSpreadsheet |
636 |
* @param rec a rectangle shape object |
637 |
* @param dataRangeAddress the CellRangeAddress array of chart data source |
638 |
* @param chartName |
639 |
* @return |
640 |
* @throws Exception |
641 |
*/ |
642 |
public static XChartDocument createChart(XSpreadsheet xSpreadsheet, Rectangle rec, CellRangeAddress[] dataRangeAddress, String chartName) throws Exception { |
643 |
XChartDocument xChartDocument = null; |
644 |
XTableChartsSupplier xTChartSupplier = |
645 |
(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet); |
646 |
XTableCharts xTableCharts = xTChartSupplier.getCharts(); |
647 |
XNameAccess xNameAccess = |
648 |
(XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xTableCharts); |
649 |
if (xNameAccess != null && !xNameAccess.hasByName(chartName)) { |
650 |
|
651 |
xTableCharts.addNewByName(chartName, rec, dataRangeAddress, true, false); |
652 |
XTableChart xTableChart = (XTableChart) UnoRuntime.queryInterface( |
653 |
XTableChart.class, xNameAccess.getByName(chartName)); |
654 |
XEmbeddedObjectSupplier xEmbeddedObjectSupplier = (XEmbeddedObjectSupplier) UnoRuntime.queryInterface( |
655 |
XEmbeddedObjectSupplier.class, xTableChart); |
656 |
xChartDocument = (XChartDocument) UnoRuntime.queryInterface( |
657 |
XChartDocument.class, xEmbeddedObjectSupplier.getEmbeddedObject()); |
658 |
} |
659 |
|
660 |
return xChartDocument; |
661 |
} |
662 |
|
663 |
/** |
664 |
* Get XChartDocument object via the chart name. |
665 |
* @param xSpreadsheet |
666 |
* @param chartName |
667 |
* @return |
668 |
* @throws Exception |
669 |
*/ |
670 |
public static XChartDocument getChartByName(XSpreadsheet xSpreadsheet, String chartName) throws Exception { |
671 |
XChartDocument xChartDocument = null; |
672 |
XTableChartsSupplier xTChartSupplier = |
673 |
(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet); |
674 |
XTableCharts xTableCharts = xTChartSupplier.getCharts(); |
675 |
XNameAccess xNameAccess = |
676 |
(XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xTableCharts); |
677 |
|
678 |
if (xNameAccess != null && xNameAccess.hasByName(chartName)) { |
679 |
XTableChart xTableChart = (XTableChart) UnoRuntime.queryInterface( |
680 |
XTableChart.class, xNameAccess.getByName(chartName)); |
681 |
XEmbeddedObjectSupplier xEmbeddedObjectSupplier = (XEmbeddedObjectSupplier) UnoRuntime.queryInterface( |
682 |
XEmbeddedObjectSupplier.class, xTableChart); |
683 |
xChartDocument = (XChartDocument) UnoRuntime.queryInterface( |
684 |
XChartDocument.class, xEmbeddedObjectSupplier.getEmbeddedObject()); |
685 |
} |
686 |
|
687 |
return xChartDocument; |
688 |
} |
689 |
|
690 |
/** |
691 |
* Set specific basic type to chart |
692 |
* @param xChartDocument |
693 |
* @param chartType |
694 |
* @throws Exception |
695 |
*/ |
696 |
public static void setChartType(XChartDocument xChartDocument, String chartType) throws Exception { |
697 |
XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface( |
698 |
XMultiServiceFactory.class, xChartDocument); |
699 |
XDiagram xDiagram = (XDiagram) UnoRuntime.queryInterface( |
700 |
XDiagram.class, xMultiServiceFactory.createInstance(chartType)); |
701 |
xChartDocument.setDiagram(xDiagram); |
702 |
} |
703 |
|
704 |
/** |
705 |
* Get the type string of a chart |
706 |
* @param xChartDocument |
707 |
* @return |
708 |
* @throws Exception |
709 |
*/ |
710 |
public static String getChartType(XChartDocument xChartDocument) throws Exception { |
711 |
return xChartDocument.getDiagram().getDiagramType(); |
712 |
} |
713 |
|
714 |
/** |
715 |
* Get the names of charts in specific sheet |
716 |
* @param xSpreadsheet |
717 |
* @return |
718 |
* @throws Exception |
719 |
*/ |
720 |
public static String[] getChartNameList(XSpreadsheet xSpreadsheet) throws Exception { |
721 |
XChartDocument xChartDocument = null; |
722 |
XTableChartsSupplier xTChartSupplier = |
723 |
(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet); |
724 |
XTableCharts xTableCharts = xTChartSupplier.getCharts(); |
725 |
String[] chartNames = xTableCharts.getElementNames(); |
726 |
return chartNames; |
727 |
} |
728 |
|
729 |
|
730 |
|
555 |
} |
731 |
} |