1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "vbarange.hxx"
#include <vbahelper/helperdecl.hxx>
#include <comphelper/unwrapargs.hxx>
#include <comphelper/processfactory.hxx>
#include <sfx2/objsh.hxx>
#include <com/sun/star/script/ArrayWrapper.hpp>
#include <com/sun/star/script/vba/VBAEventId.hpp>
#include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
#include <com/sun/star/sheet/XDatabaseRange.hpp>
#include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
#include <com/sun/star/sheet/XGoalSeek.hpp>
#include <com/sun/star/sheet/XSheetOperation.hpp>
#include <com/sun/star/sheet/CellFlags.hpp>
#include <com/sun/star/table/XColumnRowRange.hpp>
#include <com/sun/star/sheet/XCellAddressable.hpp>
#include <com/sun/star/table/CellContentType.hpp>
#include <com/sun/star/sheet/XCellSeries.hpp>
#include <com/sun/star/text/XTextRange.hpp>
#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
#include <com/sun/star/table/CellRangeAddress.hpp>
#include <com/sun/star/sheet/XSpreadsheetView.hpp>
#include <com/sun/star/sheet/XCellRangeReferrer.hpp>
#include <com/sun/star/sheet/XSheetCellRange.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
#include <com/sun/star/sheet/XSheetCellCursor.hpp>
#include <com/sun/star/sheet/XArrayFormulaRange.hpp>
#include <com/sun/star/sheet/XNamedRange.hpp>
#include <com/sun/star/sheet/XNamedRanges.hpp>
#include <com/sun/star/sheet/XPrintAreas.hpp>
#include <com/sun/star/sheet/XCellRangesQuery.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/sheet/XFunctionAccess.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <com/sun/star/table/XCellCursor.hpp>
#include <com/sun/star/table/XTableRows.hpp>
#include <com/sun/star/table/XTableColumns.hpp>
#include <com/sun/star/table/TableSortField.hpp>
#include <com/sun/star/util/XMergeable.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
#include <com/sun/star/util/XNumberFormats.hpp>
#include <com/sun/star/util/NumberFormat.hpp>
#include <com/sun/star/util/XNumberFormatTypes.hpp>
#include <com/sun/star/util/XReplaceable.hpp>
#include <com/sun/star/util/XSortable.hpp>
#include <com/sun/star/sheet/XCellRangeMovement.hpp>
#include <com/sun/star/sheet/XCellRangeData.hpp>
#include <com/sun/star/sheet/FormulaResult.hpp>
#include <com/sun/star/sheet/FilterOperator2.hpp>
#include <com/sun/star/sheet/TableFilterField.hpp>
#include <com/sun/star/sheet/TableFilterField2.hpp>
#include <com/sun/star/sheet/XSheetFilterDescriptor2.hpp>
#include <com/sun/star/sheet/XSheetFilterable.hpp>
#include <com/sun/star/sheet/FilterConnection.hpp>
#include <com/sun/star/util/CellProtection.hpp>
#include <com/sun/star/util/TriState.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/awt/XDevice.hpp>
#include <com/sun/star/sheet/XCellRangeMovement.hpp>
#include <com/sun/star/sheet/XSubTotalCalculatable.hpp>
#include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
#include <com/sun/star/sheet/GeneralFunction.hdl>
#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
#include <com/sun/star/sheet/XSheetAnnotations.hpp>
#include <com/sun/star/sheet/XDataPilotTable.hpp>
#include <com/sun/star/sheet/XDataPilotTable2.hpp>
#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
#include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
#include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
#include <ooo/vba/excel/XlPasteSpecialOperation.hpp>
#include <ooo/vba/excel/XlPasteType.hpp>
#include <ooo/vba/excel/Constants.hpp>
#include <ooo/vba/excel/XlFindLookIn.hpp>
#include <ooo/vba/excel/XlLookAt.hpp>
#include <ooo/vba/excel/XlSearchOrder.hpp>
#include <ooo/vba/excel/XlSortOrder.hpp>
#include <ooo/vba/excel/XlYesNoGuess.hpp>
#include <ooo/vba/excel/XlSortOrientation.hpp>
#include <ooo/vba/excel/XlSortMethod.hpp>
#include <ooo/vba/excel/XlDirection.hpp>
#include <ooo/vba/excel/XlSortDataOption.hpp>
#include <ooo/vba/excel/XlDeleteShiftDirection.hpp>
#include <ooo/vba/excel/XlInsertShiftDirection.hpp>
#include <ooo/vba/excel/XlReferenceStyle.hpp>
#include <ooo/vba/excel/XlBordersIndex.hpp>
#include <ooo/vba/excel/XlPageBreak.hpp>
#include <ooo/vba/excel/XlAutoFilterOperator.hpp>
#include <ooo/vba/excel/XlAutoFillType.hpp>
#include <ooo/vba/excel/XlTextParsingType.hpp>
#include <ooo/vba/excel/XlTextQualifier.hpp>
#include <ooo/vba/excel/XlCellType.hpp>
#include <ooo/vba/excel/XlSpecialCellsValue.hpp>
#include <ooo/vba/excel/XlConsolidationFunction.hpp>
#include <ooo/vba/excel/XlSearchDirection.hpp>
#include <ooo/vba/excel/XlColumnDataType.hpp>
#include <ooo/vba/excel/XlFilterAction.hpp>
#include <scitems.hxx>
#include <svl/srchitem.hxx>
#include <cellsuno.hxx>
#include <dbdata.hxx>
#include "docfunc.hxx"
#include <docuno.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/app.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/request.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/itemwrapper.hxx>
#include <sc.hrc>
#include <globstr.hrc>
#include <unonames.hxx>
#include <tools/stream.hxx>
#include "vbaapplication.hxx"
#include "vbafont.hxx"
#include "vbacomment.hxx"
#include "vbainterior.hxx"
#include "vbacharacters.hxx"
#include "vbaborders.hxx"
#include "vbaworksheet.hxx"
#include "vbavalidation.hxx"
#include "vbahyperlinks.hxx"
#include "vbapivottable.hxx"
#include "asciiopt.hxx"
#include "impex.hxx"
#include "tabvwsh.hxx"
#include "rangelst.hxx"
#include "rangenam.hxx"
#include "convuno.hxx"
#include "compiler.hxx"
#include "attrib.hxx"
#include "undodat.hxx"
#include "dbdocfun.hxx"
#include "patattr.hxx"
#include "olinetab.hxx"
#include "transobj.hxx"
#include "queryentry.hxx"
#include "markdata.hxx"
#include <comphelper/anytostring.hxx>
#include <global.hxx>
#include "vbaglobals.hxx"
#include "vbastyle.hxx"
#include "vbaname.hxx"
#include "vbanames.hxx"
#include <vector>
#include <vbahelper/vbacollectionimpl.hxx>
// begin test includes
#include <com/sun/star/sheet/FunctionArgument.hpp>
// end test includes
#include <ooo/vba/excel/Range.hpp>
#include <com/sun/star/bridge/oleautomation/Date.hpp>
using namespace ::ooo::vba;
using namespace ::com::sun::star;
using ::std::vector;
// difference between VBA and file format width, in character units
const double fExtraWidth = 182.0 / 256.0;
// * 1 point = 1/72 inch = 20 twips
// * 1 inch = 72 points = 1440 twips
// * 1 cm = 567 twips
double lcl_hmmToPoints( double nVal ) { return ( (double)((nVal /1000 ) * 567 ) / 20 ); }
static const sal_Int16 supportedIndexTable[] = { excel::XlBordersIndex::xlEdgeLeft, excel::XlBordersIndex::xlEdgeTop, excel::XlBordersIndex::xlEdgeBottom, excel::XlBordersIndex::xlEdgeRight, excel::XlBordersIndex::xlDiagonalDown, excel::XlBordersIndex::xlDiagonalUp, excel::XlBordersIndex::xlInsideVertical, excel::XlBordersIndex::xlInsideHorizontal };
sal_uInt16 lcl_pointsToTwips( double nVal )
{
nVal = nVal * static_cast<double>(20);
short nTwips = static_cast<short>(nVal);
return nTwips;
}
double lcl_TwipsToPoints( sal_uInt16 nVal )
{
double nPoints = nVal;
return nPoints / 20;
}
double lcl_Round2DecPlaces( double nVal )
{
nVal = (nVal * (double)100);
long tmp = static_cast<long>(nVal);
if ( ( ( nVal - tmp ) >= 0.5 ) )
++tmp;
nVal = tmp;
nVal = nVal/100;
return nVal;
}
uno::Any lcl_makeRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Any aAny, bool bIsRows, bool bIsColumns )
{
uno::Reference< table::XCellRange > xCellRange( aAny, uno::UNO_QUERY_THROW );
return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( xParent, xContext, xCellRange, bIsRows, bIsColumns ) ) );
}
uno::Reference< excel::XRange > lcl_makeXRangeFromSheetCellRanges( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSheetCellRanges >& xLocSheetCellRanges, ScDocShell* pDoc )
{
uno::Reference< excel::XRange > xRange;
uno::Sequence< table::CellRangeAddress > sAddresses = xLocSheetCellRanges->getRangeAddresses();
ScRangeList aCellRanges;
sal_Int32 nLen = sAddresses.getLength();
if ( nLen )
{
for ( sal_Int32 index = 0; index < nLen; ++index )
{
ScRange refRange;
ScUnoConversion::FillScRange( refRange, sAddresses[ index ] );
aCellRanges.Append( refRange );
}
// Single range
if ( aCellRanges.size() == 1 )
{
uno::Reference< table::XCellRange > xTmpRange( new ScCellRangeObj( pDoc, *aCellRanges.front() ) );
xRange = new ScVbaRange( xParent, xContext, xTmpRange );
}
else
{
uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDoc, aCellRanges ) );
xRange = new ScVbaRange( xParent, xContext, xRanges );
}
}
return xRange;
}
ScCellRangesBase* ScVbaRange::getCellRangesBase() throw ( uno::RuntimeException )
{
if( mxRanges.is() )
return ScCellRangesBase::getImplementation( mxRanges );
if( mxRange.is() )
return ScCellRangesBase::getImplementation( mxRange );
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("General Error creating range - Unknown" )), uno::Reference< uno::XInterface >() );
}
ScCellRangeObj* ScVbaRange::getCellRangeObj() throw ( uno::RuntimeException )
{
return dynamic_cast< ScCellRangeObj* >( getCellRangesBase() );
}
SfxItemSet* ScVbaRange::getCurrentDataSet( ) throw ( uno::RuntimeException )
{
SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
if ( !pDataSet )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't access Itemset for range" ) ), uno::Reference< uno::XInterface >() );
return pDataSet;
}
void ScVbaRange::fireChangeEvent()
{
if( ScVbaApplication::getDocumentEventsEnabled() )
{
if( ScDocument* pDoc = getScDocument() )
{
uno::Reference< script::vba::XVBAEventProcessor > xVBAEvents = pDoc->GetVbaEventProcessor();
if( xVBAEvents.is() ) try
{
uno::Sequence< uno::Any > aArgs( 1 );
aArgs[ 0 ] <<= uno::Reference< excel::XRange >( this );
xVBAEvents->processVbaEvent( script::vba::VBAEventId::WORKSHEET_CHANGE, aArgs );
}
catch( uno::Exception& )
{
}
}
}
}
class SingleRangeEnumeration : public EnumerationHelper_BASE
{
uno::Reference< XHelperInterface > m_xParent;
uno::Reference< table::XCellRange > m_xRange;
uno::Reference< uno::XComponentContext > mxContext;
bool bHasMore;
public:
SingleRangeEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException ) : m_xParent( xParent ), m_xRange( xRange ), mxContext( xContext ), bHasMore( true ) { }
virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) { return bHasMore; }
virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
{
if ( !bHasMore )
throw container::NoSuchElementException();
bHasMore = false;
return uno::makeAny( m_xRange );
}
};
// very simple class to pass to ScVbaCollectionBaseImpl containing
// just one item
typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > SingleRange_BASE;
class SingleRangeIndexAccess : public SingleRange_BASE
{
private:
uno::Reference< XHelperInterface > mxParent;
uno::Reference< table::XCellRange > m_xRange;
uno::Reference< uno::XComponentContext > mxContext;
SingleRangeIndexAccess(); // not defined
public:
SingleRangeIndexAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange ):mxParent( xParent ), m_xRange( xRange ), mxContext( xContext ) {}
// XIndexAccess
virtual ::sal_Int32 SAL_CALL getCount() throw (::uno::RuntimeException) { return 1; }
virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
{
if ( Index != 0 )
throw lang::IndexOutOfBoundsException();
return uno::makeAny( m_xRange );
}
// XElementAccess
virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException){ return table::XCellRange::static_type(0); }
virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException) { return sal_True; }
// XEnumerationAccess
virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration() throw (uno::RuntimeException) { return new SingleRangeEnumeration( mxParent, mxContext, m_xRange ); }
};
class RangesEnumerationImpl : public EnumerationHelperImpl
{
bool mbIsRows;
bool mbIsColumns;
public:
RangesEnumerationImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, bool bIsRows, bool bIsColumns ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {}
virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
{
return lcl_makeRange( m_xParent, m_xContext, m_xEnumeration->nextElement(), mbIsRows, mbIsColumns );
}
};
class ScVbaRangeAreas : public ScVbaCollectionBaseImpl
{
bool mbIsRows;
bool mbIsColumns;
public:
ScVbaRangeAreas( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess, bool bIsRows, bool bIsColumns ) : ScVbaCollectionBaseImpl( xParent, xContext, xIndexAccess ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {}
// XEnumerationAccess
virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration() throw (uno::RuntimeException);
// XElementAccess
virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException){ return excel::XRange::static_type(0); }
virtual uno::Any createCollectionObject( const uno::Any& aSource );
virtual rtl::OUString& getServiceImplName() { static rtl::OUString sDummy; return sDummy; }
virtual uno::Sequence< rtl::OUString > getServiceNames() { return uno::Sequence< rtl::OUString >(); }
};
uno::Reference< container::XEnumeration > SAL_CALL
ScVbaRangeAreas::createEnumeration() throw (uno::RuntimeException)
{
uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
return new RangesEnumerationImpl( mxParent, mxContext, xEnumAccess->createEnumeration(), mbIsRows, mbIsColumns );
}
uno::Any
ScVbaRangeAreas::createCollectionObject( const uno::Any& aSource )
{
return lcl_makeRange( mxParent, mxContext, aSource, mbIsRows, mbIsColumns );
}
ScDocument*
ScVbaRange::getScDocument() throw (uno::RuntimeException)
{
if ( mxRanges.is() )
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
return excel::GetDocumentFromRange( xRange );
}
return excel::GetDocumentFromRange( mxRange );
}
ScDocShell*
ScVbaRange::getScDocShell() throw (uno::RuntimeException)
{
if ( mxRanges.is() )
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
return excel::GetDocShellFromRange( xRange );
}
return excel::GetDocShellFromRange( mxRange );
}
ScVbaRange* ScVbaRange::getImplementation( const uno::Reference< excel::XRange >& rxRange )
{
// FIXME: always save to use dynamic_cast? Or better to (implement and) use XTunnel?
return dynamic_cast< ScVbaRange* >( rxRange.get() );
}
uno::Reference< frame::XModel > ScVbaRange::getUnoModel() throw (uno::RuntimeException)
{
if( ScDocShell* pDocShell = getScDocShell() )
return pDocShell->GetModel();
throw uno::RuntimeException();
}
uno::Reference< frame::XModel > ScVbaRange::getUnoModel( const uno::Reference< excel::XRange >& rxRange ) throw (uno::RuntimeException)
{
if( ScVbaRange* pScVbaRange = getImplementation( rxRange ) )
return pScVbaRange->getUnoModel();
throw uno::RuntimeException();
}
const ScRangeList& ScVbaRange::getScRangeList() throw (uno::RuntimeException)
{
if( ScCellRangesBase* pScRangesBase = getCellRangesBase() )
return pScRangesBase->GetRangeList();
throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain UNO range implementation object" ) ), uno::Reference< uno::XInterface >() );
}
const ScRangeList& ScVbaRange::getScRangeList( const uno::Reference< excel::XRange >& rxRange ) throw (uno::RuntimeException)
{
if( ScVbaRange* pScVbaRange = getImplementation( rxRange ) )
return pScVbaRange->getScRangeList();
throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain VBA range implementation object" ) ), uno::Reference< uno::XInterface >() );
}
class NumFormatHelper
{
uno::Reference< util::XNumberFormatsSupplier > mxSupplier;
uno::Reference< beans::XPropertySet > mxRangeProps;
uno::Reference< util::XNumberFormats > mxFormats;
public:
NumFormatHelper( const uno::Reference< table::XCellRange >& xRange )
{
mxSupplier.set( excel::GetModelFromRange( xRange ), uno::UNO_QUERY_THROW );
mxRangeProps.set( xRange, uno::UNO_QUERY_THROW);
mxFormats = mxSupplier->getNumberFormats();
}
uno::Reference< beans::XPropertySet > getNumberProps()
{
long nIndexKey = 0;
uno::Any aValue = mxRangeProps->getPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberFormat")));
aValue >>= nIndexKey;
if ( mxFormats.is() )
return mxFormats->getByKey( nIndexKey );
return uno::Reference< beans::XPropertySet > ();
}
bool isBooleanType()
{
if ( getNumberFormat() & util::NumberFormat::LOGICAL )
return true;
return false;
}
bool isDateType()
{
sal_Int16 nType = getNumberFormat();
if(( nType & util::NumberFormat::DATETIME ))
{
return true;
}
return false;
}
rtl::OUString getNumberFormatString()
{
uno::Reference< uno::XInterface > xIf( mxRangeProps, uno::UNO_QUERY_THROW );
ScCellRangesBase* pUnoCellRange = ScCellRangesBase::getImplementation( xIf );
if ( pUnoCellRange )
{
SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( pUnoCellRange );
SfxItemState eState = pDataSet->GetItemState( ATTR_VALUE_FORMAT, true, NULL);
// one of the cells in the range is not like the other ;-)
// so return a zero length format to indicate that
if ( eState == SFX_ITEM_DONTCARE )
return rtl::OUString();
}
uno::Reference< beans::XPropertySet > xNumberProps( getNumberProps(), uno::UNO_QUERY_THROW );
::rtl::OUString aFormatString;
uno::Any aString = xNumberProps->getPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FormatString")));
aString >>= aFormatString;
return aFormatString;
}
sal_Int16 getNumberFormat()
{
uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps();
sal_Int16 nType = ::comphelper::getINT16(
xNumberProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Type" )) ) );
return nType;
}
bool setNumberFormat( const rtl::OUString& rFormat )
{
// #163288# treat "General" as "Standard" format
sal_Int32 nNewIndex = 0;
if( !rFormat.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "General" ) ) )
{
lang::Locale aLocale;
uno::Reference< beans::XPropertySet > xNumProps = getNumberProps();
xNumProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Locale" ) ) ) >>= aLocale;
nNewIndex = mxFormats->queryKey( rFormat, aLocale, false );
if ( nNewIndex == -1 ) // format not defined
nNewIndex = mxFormats->addNew( rFormat, aLocale );
}
mxRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberFormat") ), uno::makeAny( nNewIndex ) );
return true;
}
bool setNumberFormat( sal_Int16 nType )
{
uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps();
lang::Locale aLocale;
xNumberProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Locale" )) ) >>= aLocale;
uno::Reference<util::XNumberFormatTypes> xTypes( mxFormats, uno::UNO_QUERY );
if ( xTypes.is() )
{
sal_Int32 nNewIndex = xTypes->getStandardFormat( nType, aLocale );
mxRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberFormat") ), uno::makeAny( nNewIndex ) );
return true;
}
return false;
}
};
struct CellPos
{
CellPos():m_nRow(-1), m_nCol(-1), m_nArea(0) {};
CellPos( sal_Int32 nRow, sal_Int32 nCol, sal_Int32 nArea ):m_nRow(nRow), m_nCol(nCol), m_nArea( nArea ) {};
sal_Int32 m_nRow;
sal_Int32 m_nCol;
sal_Int32 m_nArea;
};
typedef ::cppu::WeakImplHelper1< container::XEnumeration > CellsEnumeration_BASE;
typedef ::std::vector< CellPos > vCellPos;
// #FIXME - QUICK
// we could probably could and should modify CellsEnumeration below
// to handle rows and columns ( but I do this seperately for now
// and.. this class only handles singe areas ( does it have to handle
// multi area ranges?? )
class ColumnsRowEnumeration: public CellsEnumeration_BASE
{
uno::Reference< uno::XComponentContext > mxContext;
uno::Reference< excel::XRange > mxRange;
sal_Int32 mMaxElems;
sal_Int32 mCurElem;
public:
ColumnsRowEnumeration( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< excel::XRange >& xRange, sal_Int32 nElems ) : mxContext( xContext ), mxRange( xRange ), mMaxElems( nElems ), mCurElem( 0 )
{
}
virtual ::sal_Bool SAL_CALL hasMoreElements() throw (::uno::RuntimeException){ return mCurElem < mMaxElems; }
virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
{
if ( !hasMoreElements() )
throw container::NoSuchElementException();
sal_Int32 vbaIndex = 1 + mCurElem++;
return uno::makeAny( mxRange->Item( uno::makeAny( vbaIndex ), uno::Any() ) );
}
};
class CellsEnumeration : public CellsEnumeration_BASE
{
uno::WeakReference< XHelperInterface > mxParent;
uno::Reference< uno::XComponentContext > mxContext;
uno::Reference< XCollection > m_xAreas;
vCellPos m_CellPositions;
vCellPos::const_iterator m_it;
uno::Reference< table::XCellRange > getArea( sal_Int32 nVBAIndex ) throw ( uno::RuntimeException )
{
if ( nVBAIndex < 1 || nVBAIndex > m_xAreas->getCount() )
throw uno::RuntimeException();
uno::Reference< excel::XRange > xRange( m_xAreas->Item( uno::makeAny(nVBAIndex), uno::Any() ), uno::UNO_QUERY_THROW );
uno::Reference< table::XCellRange > xCellRange( ScVbaRange::getCellRange( xRange ), uno::UNO_QUERY_THROW );
return xCellRange;
}
void populateArea( sal_Int32 nVBAIndex )
{
uno::Reference< table::XCellRange > xRange = getArea( nVBAIndex );
uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, uno::UNO_QUERY_THROW );
sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount();
sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
for ( sal_Int32 i=0; i<nRowCount; ++i )
{
for ( sal_Int32 j=0; j<nColCount; ++j )
m_CellPositions.push_back( CellPos( i,j,nVBAIndex ) );
}
}
public:
CellsEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XCollection >& xAreas ): mxParent( xParent ), mxContext( xContext ), m_xAreas( xAreas )
{
sal_Int32 nItems = m_xAreas->getCount();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
populateArea( index );
}
m_it = m_CellPositions.begin();
}
virtual ::sal_Bool SAL_CALL hasMoreElements() throw (::uno::RuntimeException){ return m_it != m_CellPositions.end(); }
virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
{
if ( !hasMoreElements() )
throw container::NoSuchElementException();
CellPos aPos = *(m_it)++;
uno::Reference< table::XCellRange > xRangeArea = getArea( aPos.m_nArea );
uno::Reference< table::XCellRange > xCellRange( xRangeArea->getCellByPosition( aPos.m_nCol, aPos.m_nRow ), uno::UNO_QUERY_THROW );
return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( mxParent, mxContext, xCellRange ) ) );
}
};
const static ::rtl::OUString ISVISIBLE( RTL_CONSTASCII_USTRINGPARAM( "IsVisible"));
const static ::rtl::OUString WIDTH( RTL_CONSTASCII_USTRINGPARAM( "Width"));
const static ::rtl::OUString HEIGHT( RTL_CONSTASCII_USTRINGPARAM( "Height"));
const static ::rtl::OUString POSITION( RTL_CONSTASCII_USTRINGPARAM( "Position"));
const static rtl::OUString EQUALS( RTL_CONSTASCII_USTRINGPARAM("=") );
const static rtl::OUString NOTEQUALS( RTL_CONSTASCII_USTRINGPARAM("<>") );
const static rtl::OUString GREATERTHAN( RTL_CONSTASCII_USTRINGPARAM(">") );
const static rtl::OUString GREATERTHANEQUALS( RTL_CONSTASCII_USTRINGPARAM(">=") );
const static rtl::OUString LESSTHAN( RTL_CONSTASCII_USTRINGPARAM("<") );
const static rtl::OUString LESSTHANEQUALS( RTL_CONSTASCII_USTRINGPARAM("<=") );
const static rtl::OUString CONTS_HEADER( RTL_CONSTASCII_USTRINGPARAM("ContainsHeader" ));
const static rtl::OUString INSERTPAGEBREAKS( RTL_CONSTASCII_USTRINGPARAM("InsertPageBreaks" ));
const static rtl::OUString STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY( RTL_CONSTASCII_USTRINGPARAM("The command you chose cannot be performed with multiple selections.\nSelect a single range and click the command again") );
const static rtl::OUString STR_ERRORMESSAGE_NOCELLSWEREFOUND( RTL_CONSTASCII_USTRINGPARAM("No cells were found") );
const static rtl::OUString STR_ERRORMESSAGE_APPLIESTOROWCOLUMNSONLY( RTL_CONSTASCII_USTRINGPARAM("Property only applicable for Columns and Rows") );
const static rtl::OUString CELLSTYLE( RTL_CONSTASCII_USTRINGPARAM("CellStyle") );
class CellValueSetter : public ValueSetter
{
protected:
uno::Any maValue;
uno::TypeClass mTypeClass;
public:
CellValueSetter( const uno::Any& aValue );
virtual bool processValue( const uno::Any& aValue, const uno::Reference< table::XCell >& xCell );
virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell );
};
CellValueSetter::CellValueSetter( const uno::Any& aValue ): maValue( aValue ), mTypeClass( aValue.getValueTypeClass() ) {}
void
CellValueSetter::visitNode( sal_Int32 /*i*/, sal_Int32 /*j*/, const uno::Reference< table::XCell >& xCell )
{
processValue( maValue, xCell );
}
bool
CellValueSetter::processValue( const uno::Any& aValue, const uno::Reference< table::XCell >& xCell )
{
bool isExtracted = false;
switch ( aValue.getValueTypeClass() )
{
case uno::TypeClass_BOOLEAN:
{
sal_Bool bState = false;
if ( aValue >>= bState )
{
uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
if ( bState )
xCell->setValue( (double) 1 );
else
xCell->setValue( (double) 0 );
NumFormatHelper cellNumFormat( xRange );
cellNumFormat.setNumberFormat( util::NumberFormat::LOGICAL );
}
break;
}
case uno::TypeClass_STRING:
{
rtl::OUString aString;
if ( aValue >>= aString )
{
// The required behavior for a string value is:
// 1. If the first character is a single quote, use the rest as a string cell, regardless of the cell's number format.
// 2. Otherwise, if the cell's number format is "text", use the string value as a string cell.
// 3. Otherwise, parse the string value in English locale, and apply a corresponding number format with the cell's locale
// if the cell's number format was "General".
// Case 1 is handled here, the rest in ScCellObj::InputEnglishString
if ( aString.toChar() == '\'' ) // case 1 - handle with XTextRange
{
rtl::OUString aRemainder( aString.copy(1) ); // strip the quote
uno::Reference< text::XTextRange > xTextRange( xCell, uno::UNO_QUERY_THROW );
xTextRange->setString( aRemainder );
}
else
{
// call implementation method InputEnglishString
ScCellObj* pCellObj = dynamic_cast< ScCellObj* >( xCell.get() );
if ( pCellObj )
pCellObj->InputEnglishString( aString );
}
}
else
isExtracted = false;
break;
}
default:
{
double nDouble = 0.0;
if ( aValue >>= nDouble )
{
xCell->setValue( nDouble );
uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
NumFormatHelper cellNumFormat( xRange );
if ( cellNumFormat.isBooleanType() )
{
cellNumFormat.setNumberFormat( util::NumberFormat::NUMBER );
}
}
else
isExtracted = false;
break;
}
}
return isExtracted;
}
class CellValueGetter : public ValueGetter
{
protected:
uno::Any maValue;
uno::TypeClass mTypeClass;
public:
CellValueGetter() {}
virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell );
virtual void processValue( sal_Int32 x, sal_Int32 y, const uno::Any& aValue );
const uno::Any& getValue() const { return maValue; }
};
void
CellValueGetter::processValue( sal_Int32 /*x*/, sal_Int32 /*y*/, const uno::Any& aValue )
{
maValue = aValue;
}
void CellValueGetter::visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell )
{
uno::Any aValue;
table::CellContentType eType = xCell->getType();
if( eType == table::CellContentType_VALUE || eType == table::CellContentType_FORMULA )
{
if ( eType == table::CellContentType_FORMULA )
{
rtl::OUString sFormula = xCell->getFormula();
if ( sFormula.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("=TRUE()") ) ) )
aValue <<= sal_True;
else if ( sFormula.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("=FALSE()") ) ) )
aValue <<= false;
else
{
uno::Reference< beans::XPropertySet > xProp( xCell, uno::UNO_QUERY_THROW );
table::CellContentType eFormulaType = table::CellContentType_VALUE;
// some formulas give textual results
xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FormulaResultType" ) ) ) >>= eFormulaType;
if ( eFormulaType == table::CellContentType_TEXT )
{
uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW);
aValue <<= xTextRange->getString();
}
else
aValue <<= xCell->getValue();
}
}
else
{
uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
NumFormatHelper cellFormat( xRange );
if ( cellFormat.isBooleanType() )
aValue = uno::makeAny( ( xCell->getValue() != 0.0 ) );
else if ( cellFormat.isDateType() )
aValue = uno::makeAny( bridge::oleautomation::Date( xCell->getValue() ) );
else
aValue <<= xCell->getValue();
}
}
if( eType == table::CellContentType_TEXT )
{
uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW);
aValue <<= xTextRange->getString();
}
processValue( x,y,aValue );
}
class CellFormulaValueSetter : public CellValueSetter
{
private:
ScDocument* m_pDoc;
formula::FormulaGrammar::Grammar m_eGrammar;
public:
CellFormulaValueSetter( const uno::Any& aValue, ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ):CellValueSetter( aValue ), m_pDoc( pDoc ), m_eGrammar( eGram ){}
protected:
bool processValue( const uno::Any& aValue, const uno::Reference< table::XCell >& xCell )
{
rtl::OUString sFormula;
double aDblValue = 0.0;
if ( aValue >>= sFormula )
{
// convert to GRAM_PODF_A1 style grammar because XCell::setFormula
// always compile it in that grammar. Perhaps
// css.sheet.FormulaParser should be used in future to directly
// pass formula tokens when that API stabilizes.
if ( m_eGrammar != formula::FormulaGrammar::GRAM_PODF_A1 && ( sFormula.trim().indexOf('=') == 0 ) )
{
uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW );
ScCellRangesBase* pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() );
if ( pUnoRangesBase )
{
ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
ScCompiler aCompiler( m_pDoc, aCellRanges.front()->aStart );
aCompiler.SetGrammar(m_eGrammar);
// compile the string in the format passed in
aCompiler.CompileString( sFormula );
// set desired convention to that of the document
aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_PODF_A1 );
String sConverted;
aCompiler.CreateStringFromTokenArray(sConverted);
sFormula = EQUALS + sConverted;
}
}
xCell->setFormula( sFormula );
return true;
}
else if ( aValue >>= aDblValue )
{
xCell->setValue( aDblValue );
return true;
}
return false;
}
};
class CellFormulaValueGetter : public CellValueGetter
{
private:
ScDocument* m_pDoc;
formula::FormulaGrammar::Grammar m_eGrammar;
public:
CellFormulaValueGetter(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ) : CellValueGetter( ), m_pDoc( pDoc ), m_eGrammar( eGram ) {}
virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell )
{
uno::Any aValue;
aValue <<= xCell->getFormula();
rtl::OUString sVal;
aValue >>= sVal;
uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW );
ScCellRangesBase* pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() );
if ( ( xCell->getType() == table::CellContentType_FORMULA ) &&
pUnoRangesBase )
{
ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
ScCompiler aCompiler( m_pDoc, aCellRanges.front()->aStart );
aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_DEFAULT);
aCompiler.CompileString( sVal );
// set desired convention
aCompiler.SetGrammar( m_eGrammar );
String sConverted;
aCompiler.CreateStringFromTokenArray(sConverted);
sVal = EQUALS + sConverted;
aValue <<= sVal;
}
processValue( x,y,aValue );
}
};
class Dim2ArrayValueGetter : public ArrayVisitor
{
protected:
uno::Any maValue;
ValueGetter& mValueGetter;
virtual void processValue( sal_Int32 x, sal_Int32 y, const uno::Any& aValue )
{
uno::Sequence< uno::Sequence< uno::Any > >& aMatrix = *( uno::Sequence< uno::Sequence< uno::Any > >* )( maValue.getValue() );
aMatrix[x][y] = aValue;
}
public:
Dim2ArrayValueGetter(sal_Int32 nRowCount, sal_Int32 nColCount, ValueGetter& rValueGetter ): mValueGetter(rValueGetter)
{
uno::Sequence< uno::Sequence< uno::Any > > aMatrix;
aMatrix.realloc( nRowCount );
for ( sal_Int32 index = 0; index < nRowCount; ++index )
aMatrix[index].realloc( nColCount );
maValue <<= aMatrix;
}
void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell )
{
mValueGetter.visitNode( x, y, xCell );
processValue( x, y, mValueGetter.getValue() );
}
const uno::Any& getValue() const { return maValue; }
};
const static rtl::OUString sNA(RTL_CONSTASCII_USTRINGPARAM("#N/A"));
class Dim1ArrayValueSetter : public ArrayVisitor
{
uno::Sequence< uno::Any > aMatrix;
sal_Int32 nColCount;
ValueSetter& mCellValueSetter;
public:
Dim1ArrayValueSetter( const uno::Any& aValue, ValueSetter& rCellValueSetter ):mCellValueSetter( rCellValueSetter )
{
aValue >>= aMatrix;
nColCount = aMatrix.getLength();
}
virtual void visitNode( sal_Int32 /*x*/, sal_Int32 y, const uno::Reference< table::XCell >& xCell )
{
if ( y < nColCount )
mCellValueSetter.processValue( aMatrix[ y ], xCell );
else
mCellValueSetter.processValue( uno::makeAny( sNA ), xCell );
}
};
class Dim2ArrayValueSetter : public ArrayVisitor
{
uno::Sequence< uno::Sequence< uno::Any > > aMatrix;
ValueSetter& mCellValueSetter;
sal_Int32 nRowCount;
sal_Int32 nColCount;
public:
Dim2ArrayValueSetter( const uno::Any& aValue, ValueSetter& rCellValueSetter ) : mCellValueSetter( rCellValueSetter )
{
aValue >>= aMatrix;
nRowCount = aMatrix.getLength();
nColCount = aMatrix[0].getLength();
}
virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell )
{
if ( x < nRowCount && y < nColCount )
mCellValueSetter.processValue( aMatrix[ x ][ y ], xCell );
else
mCellValueSetter.processValue( uno::makeAny( sNA ), xCell );
}
};
class RangeProcessor
{
public:
virtual void process( const uno::Reference< excel::XRange >& xRange ) = 0;
};
class RangeValueProcessor : public RangeProcessor
{
const uno::Any& m_aVal;
public:
RangeValueProcessor( const uno::Any& rVal ):m_aVal( rVal ) {}
virtual void process( const uno::Reference< excel::XRange >& xRange )
{
xRange->setValue( m_aVal );
}
};
class RangeFormulaProcessor : public RangeProcessor
{
const uno::Any& m_aVal;
public:
RangeFormulaProcessor( const uno::Any& rVal ):m_aVal( rVal ) {}
virtual void process( const uno::Reference< excel::XRange >& xRange )
{
xRange->setFormula( m_aVal );
}
};
class RangeCountProcessor : public RangeProcessor
{
sal_Int32 nCount;
public:
RangeCountProcessor():nCount(0){}
virtual void process( const uno::Reference< excel::XRange >& xRange )
{
nCount = nCount + xRange->getCount();
}
sal_Int32 value() { return nCount; }
};
class AreasVisitor
{
private:
uno::Reference< XCollection > m_Areas;
public:
AreasVisitor( const uno::Reference< XCollection >& rAreas ):m_Areas( rAreas ){}
void visit( RangeProcessor& processor )
{
if ( m_Areas.is() )
{
sal_Int32 nItems = m_Areas->getCount();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
processor.process( xRange );
}
}
}
};
class RangeHelper
{
uno::Reference< table::XCellRange > m_xCellRange;
public:
RangeHelper( const uno::Reference< table::XCellRange >& xCellRange ) throw (uno::RuntimeException) : m_xCellRange( xCellRange )
{
if ( !m_xCellRange.is() )
throw uno::RuntimeException();
}
RangeHelper( const uno::Any aCellRange ) throw (uno::RuntimeException)
{
m_xCellRange.set( aCellRange, uno::UNO_QUERY_THROW );
}
uno::Reference< sheet::XSheetCellRange > getSheetCellRange() throw (uno::RuntimeException)
{
return uno::Reference< sheet::XSheetCellRange >(m_xCellRange, uno::UNO_QUERY_THROW);
}
uno::Reference< sheet::XSpreadsheet > getSpreadSheet() throw (uno::RuntimeException)
{
return getSheetCellRange()->getSpreadsheet();
}
uno::Reference< table::XCellRange > getCellRangeFromSheet() throw (uno::RuntimeException)
{
return uno::Reference< table::XCellRange >(getSpreadSheet(), uno::UNO_QUERY_THROW );
}
uno::Reference< sheet::XCellRangeAddressable > getCellRangeAddressable() throw (uno::RuntimeException)
{
return uno::Reference< sheet::XCellRangeAddressable >(m_xCellRange, ::uno::UNO_QUERY_THROW);
}
uno::Reference< sheet::XSheetCellCursor > getSheetCellCursor() throw ( uno::RuntimeException )
{
return uno::Reference< sheet::XSheetCellCursor >( getSpreadSheet()->createCursorByRange( getSheetCellRange() ), uno::UNO_QUERY_THROW );
}
static uno::Reference< excel::XRange > createRangeFromRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference<uno::XComponentContext >& xContext,
const uno::Reference< table::XCellRange >& xRange, const uno::Reference< sheet::XCellRangeAddressable >& xCellRangeAddressable,
sal_Int32 nStartColOffset = 0, sal_Int32 nStartRowOffset = 0, sal_Int32 nEndColOffset = 0, sal_Int32 nEndRowOffset = 0 )
{
return uno::Reference< excel::XRange >( new ScVbaRange( xParent, xContext,
xRange->getCellRangeByPosition(
xCellRangeAddressable->getRangeAddress().StartColumn + nStartColOffset,
xCellRangeAddressable->getRangeAddress().StartRow + nStartRowOffset,
xCellRangeAddressable->getRangeAddress().EndColumn + nEndColOffset,
xCellRangeAddressable->getRangeAddress().EndRow + nEndRowOffset ) ) );
}
};
bool
getCellRangesForAddress( sal_uInt16& rResFlags, const rtl::OUString& sAddress, ScDocShell* pDocSh, ScRangeList& rCellRanges, formula::FormulaGrammar::AddressConvention& eConv, char cDelimiter = 0 )
{
ScDocument* pDoc = NULL;
if ( pDocSh )
{
pDoc = pDocSh->GetDocument();
String aString(sAddress);
sal_uInt16 nMask = SCA_VALID;
rResFlags = rCellRanges.Parse( sAddress, pDoc, nMask, eConv, cDelimiter );
if ( rResFlags & SCA_VALID )
{
return true;
}
}
return false;
}
bool getScRangeListForAddress( const rtl::OUString& sName, ScDocShell* pDocSh, ScRange& refRange, ScRangeList& aCellRanges, formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( uno::RuntimeException )
{
// see if there is a match with a named range
uno::Reference< beans::XPropertySet > xProps( pDocSh->GetModel(), uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNameAccess( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW );
// Strangly enough you can have Range( "namedRange1, namedRange2, etc," )
// loop around each ',' seperated name
std::vector< rtl::OUString > vNames;
sal_Int32 nIndex = 0;
do
{
rtl::OUString aToken = sName.getToken( 0, ',', nIndex );
vNames.push_back( aToken );
} while ( nIndex >= 0 );
if ( vNames.empty() )
vNames.push_back( sName );
std::vector< rtl::OUString >::iterator it = vNames.begin();
std::vector< rtl::OUString >::iterator it_end = vNames.end();
for ( ; it != it_end; ++it )
{
formula::FormulaGrammar::AddressConvention eConv = aConv;
// spaces are illegal ( but the user of course can enter them )
rtl::OUString sAddress = (*it).trim();
// if a local name ( on the active sheet ) exists this will
// take precedence over a global with the same name
bool bLocalName = false;
if ( !xNameAccess->hasByName( sAddress ) && pDocSh )
{
// try a local name
ScDocument* pDoc = pDocSh->GetDocument();
if ( pDoc )
{
SCTAB nCurTab = pDocSh->GetCurTab();
ScRangeName* pRangeName = pDoc->GetRangeName(nCurTab);
if (pRangeName)
{
bLocalName = pRangeName->findByUpperName(ScGlobal::pCharClass->upper(sAddress)) != NULL;
// TODO: Handle local names correctly.
(void)bLocalName;
}
}
}
char aChar = 0;
if ( xNameAccess->hasByName( sAddress ) )
{
uno::Reference< sheet::XNamedRange > xNamed( xNameAccess->getByName( sAddress ), uno::UNO_QUERY_THROW );
sAddress = xNamed->getContent();
// As the address comes from OOO, the addressing
// style is may not be XL_A1
eConv = pDocSh->GetDocument()->GetAddressConvention();
aChar = ';';
}
sal_uInt16 nFlags = 0;
if ( !getCellRangesForAddress( nFlags, sAddress, pDocSh, aCellRanges, eConv, aChar ) )
return false;
bool bTabFromReferrer = !( nFlags & SCA_TAB_3D );
for ( size_t i = 0, nRanges = aCellRanges.size(); i < nRanges; ++i )
{
ScRange* pRange = aCellRanges[ i ];
pRange->aStart.SetCol( refRange.aStart.Col() + pRange->aStart.Col() );
pRange->aStart.SetRow( refRange.aStart.Row() + pRange->aStart.Row() );
pRange->aStart.SetTab( bTabFromReferrer ? refRange.aStart.Tab() : pRange->aStart.Tab() );
pRange->aEnd.SetCol( refRange.aStart.Col() + pRange->aEnd.Col() );
pRange->aEnd.SetRow( refRange.aStart.Row() + pRange->aEnd.Row() );
pRange->aEnd.SetTab( bTabFromReferrer ? refRange.aEnd.Tab() : pRange->aEnd.Tab() );
}
}
return true;
}
ScVbaRange*
getRangeForName( const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sName, ScDocShell* pDocSh, table::CellRangeAddress& pAddr, formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( uno::RuntimeException )
{
ScRangeList aCellRanges;
ScRange refRange;
ScUnoConversion::FillScRange( refRange, pAddr );
if ( !getScRangeListForAddress ( sName, pDocSh, refRange, aCellRanges, eConv ) )
throw uno::RuntimeException();
// Single range
if ( aCellRanges.size() == 1 )
{
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pDocSh, *aCellRanges.front() ) );
uno::Reference< XHelperInterface > xFixThisParent = excel::getUnoSheetModuleObj( xRange );
return new ScVbaRange( xFixThisParent, xContext, xRange );
}
uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDocSh, aCellRanges ) );
uno::Reference< XHelperInterface > xFixThisParent = excel::getUnoSheetModuleObj( xRanges );
return new ScVbaRange( xFixThisParent, xContext, xRanges );
}
// ----------------------------------------------------------------------------
namespace {
template< typename RangeType >
inline table::CellRangeAddress lclGetRangeAddress( const uno::Reference< RangeType >& rxCellRange ) throw (uno::RuntimeException)
{
return uno::Reference< sheet::XCellRangeAddressable >( rxCellRange, uno::UNO_QUERY_THROW )->getRangeAddress();
}
void lclClearRange( const uno::Reference< table::XCellRange >& rxCellRange ) throw (uno::RuntimeException)
{
using namespace ::com::sun::star::sheet::CellFlags;
sal_Int32 nFlags = VALUE | DATETIME | STRING | ANNOTATION | FORMULA | HARDATTR | STYLES | EDITATTR | FORMATTED;
uno::Reference< sheet::XSheetOperation > xSheetOperation( rxCellRange, uno::UNO_QUERY_THROW );
xSheetOperation->clearContents( nFlags );
}
uno::Reference< sheet::XSheetCellRange > lclExpandToMerged( const uno::Reference< table::XCellRange >& rxCellRange, bool bRecursive ) throw (uno::RuntimeException)
{
uno::Reference< sheet::XSheetCellRange > xNewCellRange( rxCellRange, uno::UNO_QUERY_THROW );
uno::Reference< sheet::XSpreadsheet > xSheet( xNewCellRange->getSpreadsheet(), uno::UNO_SET_THROW );
table::CellRangeAddress aNewAddress = lclGetRangeAddress( xNewCellRange );
table::CellRangeAddress aOldAddress;
// expand as long as there are new merged ranges included
do
{
aOldAddress = aNewAddress;
uno::Reference< sheet::XSheetCellCursor > xCursor( xSheet->createCursorByRange( xNewCellRange ), uno::UNO_SET_THROW );
xCursor->collapseToMergedArea();
xNewCellRange.set( xCursor, uno::UNO_QUERY_THROW );
aNewAddress = lclGetRangeAddress( xNewCellRange );
}
while( bRecursive && (aOldAddress != aNewAddress) );
return xNewCellRange;
}
uno::Reference< sheet::XSheetCellRangeContainer > lclExpandToMerged( const uno::Reference< sheet::XSheetCellRangeContainer >& rxCellRanges, bool bRecursive ) throw (uno::RuntimeException)
{
if( !rxCellRanges.is() )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Missing cell ranges object" ) ), uno::Reference< uno::XInterface >() );
sal_Int32 nCount = rxCellRanges->getCount();
if( nCount < 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Missing cell ranges object" ) ), uno::Reference< uno::XInterface >() );
ScRangeList aScRanges;
for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
{
uno::Reference< table::XCellRange > xRange( rxCellRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
table::CellRangeAddress aRangeAddr = lclGetRangeAddress( lclExpandToMerged( xRange, bRecursive ) );
ScRange aScRange;
ScUnoConversion::FillScRange( aScRange, aRangeAddr );
aScRanges.Append( aScRange );
}
return new ScCellRangesObj( excel::GetDocShellFromRanges( rxCellRanges ), aScRanges );
}
void lclExpandAndMerge( const uno::Reference< table::XCellRange >& rxCellRange, bool bMerge ) throw (uno::RuntimeException)
{
uno::Reference< util::XMergeable > xMerge( lclExpandToMerged( rxCellRange, true ), uno::UNO_QUERY_THROW );
// Calc cannot merge over merged ranges, always unmerge first
xMerge->merge( false );
if( bMerge )
{
// clear all contents of the covered cells (not the top-left cell)
table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange );
sal_Int32 nLastColIdx = aRangeAddr.EndColumn - aRangeAddr.StartColumn;
sal_Int32 nLastRowIdx = aRangeAddr.EndRow - aRangeAddr.StartRow;
// clear cells of top row, right of top-left cell
if( nLastColIdx > 0 )
lclClearRange( rxCellRange->getCellRangeByPosition( 1, 0, nLastColIdx, 0 ) );
// clear all rows below top row
if( nLastRowIdx > 0 )
lclClearRange( rxCellRange->getCellRangeByPosition( 0, 1, nLastColIdx, nLastRowIdx ) );
// merge the range
xMerge->merge( sal_True );
}
}
util::TriState lclGetMergedState( const uno::Reference< table::XCellRange >& rxCellRange ) throw (uno::RuntimeException)
{
/* 1) Check if range is completely inside one single merged range. To do
this, try to extend from top-left cell only (not from entire range).
This will exclude cases where this range consists of several merged
ranges (or parts of them). */
table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange );
uno::Reference< table::XCellRange > xTopLeft( rxCellRange->getCellRangeByPosition( 0, 0, 0, 0 ), uno::UNO_SET_THROW );
uno::Reference< sheet::XSheetCellRange > xExpanded( lclExpandToMerged( xTopLeft, false ), uno::UNO_SET_THROW );
table::CellRangeAddress aExpAddr = lclGetRangeAddress( xExpanded );
// check that expanded range has more than one cell (really merged)
if( ((aExpAddr.StartColumn < aExpAddr.EndColumn) || (aExpAddr.StartRow < aExpAddr.EndRow)) && ScUnoConversion::Contains( aExpAddr, aRangeAddr ) )
return util::TriState_YES;
/* 2) Check if this range contains any merged cells (completely or
partly). This seems to be hardly possible via API, as
XMergeable::getIsMerged() returns only true, if the top-left cell of a
merged range is part of this range, so cases where just the lower part
of a merged range is part of this range are not covered. */
ScRange aScRange;
ScUnoConversion::FillScRange( aScRange, aRangeAddr );
bool bHasMerged = excel::GetDocumentFromRange( rxCellRange )->HasAttrib( aScRange, HASATTR_MERGED | HASATTR_OVERLAPPED );
return bHasMerged ? util::TriState_INDETERMINATE : util::TriState_NO;
}
} // namespace
// ----------------------------------------------------------------------------
css::uno::Reference< excel::XRange >
ScVbaRange::getRangeObjectForName(
const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sRangeName,
ScDocShell* pDocSh, formula::FormulaGrammar::AddressConvention eConv ) throw ( uno::RuntimeException )
{
table::CellRangeAddress refAddr;
return getRangeForName( xContext, sRangeName, pDocSh, refAddr, eConv );
}
table::CellAddress ScVbaRange::getLeftUpperCellAddress()
{
table::CellAddress aCellAddress;
uno::Reference< table::XCellRange > xCellRange = mxRange;
if ( mxRanges.is() && m_Areas.is() && m_Areas->getCount() > 1 )
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY );
if ( xIndex.is() && xIndex->getCount() > 0 )
{
xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY );
}
}
if ( xCellRange.is() )
{
uno::Reference< sheet::XCellAddressable > xCellAddr( xCellRange->getCellByPosition( 0, 0 ), uno::UNO_QUERY );
if ( xCellAddr.is() )
{
aCellAddress = xCellAddr->getCellAddress();
}
}
return aCellAddress;
}
table::CellRangeAddress getCellRangeAddressForVBARange( const uno::Any& aParam, ScDocShell* pDocSh, formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1) throw ( uno::RuntimeException )
{
uno::Reference< table::XCellRange > xRangeParam;
switch ( aParam.getValueTypeClass() )
{
case uno::TypeClass_STRING:
{
rtl::OUString rString;
aParam >>= rString;
ScRangeList aCellRanges;
ScRange refRange;
if ( getScRangeListForAddress ( rString, pDocSh, refRange, aCellRanges, aConv ) )
{
if ( aCellRanges.size() == 1 )
{
table::CellRangeAddress aRangeAddress;
ScUnoConversion::FillApiRange( aRangeAddress, *aCellRanges.front() );
return aRangeAddress;
}
}
}
case uno::TypeClass_INTERFACE:
{
uno::Reference< excel::XRange > xRange;
aParam >>= xRange;
if ( xRange.is() )
{
ScVbaRange* pRange = dynamic_cast< ScVbaRange* >( xRange.get() );
if ( pRange && pDocSh && pRange->getScDocument() != pDocSh->GetDocument() )
{
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid range" ) ), uno::Reference< uno::XInterface >() );
}
xRange->getCellRange() >>= xRangeParam;
}
break;
}
default:
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't extact CellRangeAddress from type" ) ), uno::Reference< uno::XInterface >() );
}
return lclGetRangeAddress( xRangeParam );
}
uno::Reference< XCollection >
lcl_setupBorders( const uno::Reference< excel::XRange >& xParentRange, const uno::Reference<uno::XComponentContext>& xContext, const uno::Reference< table::XCellRange >& xRange ) throw( uno::RuntimeException )
{
uno::Reference< XHelperInterface > xParent( xParentRange, uno::UNO_QUERY_THROW );
ScDocument* pDoc = excel::GetDocumentFromRange(xRange);
if ( !pDoc )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() );
ScVbaPalette aPalette( pDoc->GetDocumentShell() );
uno::Reference< XCollection > borders( new ScVbaBorders( xParent, xContext, xRange, aPalette ) );
return borders;
}
void lcl_NotifyRangeChanges( const uno::Reference< frame::XModel >& xModel, ScCellRangesBase* pUnoRangesBase )
{
if ( xModel.is() && pUnoRangesBase )
{
ScModelObj* pModelObj = ScModelObj::getImplementation( xModel );
const ScRangeList& aCellRanges = pUnoRangesBase->GetRangeList();
if ( pModelObj && pModelObj->HasChangesListeners() )
{
pModelObj->NotifyChanges( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cell-change" ) ), aCellRanges );
}
}
}
ScVbaRange::ScVbaRange( uno::Sequence< uno::Any> const & args,
uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : ScVbaRange_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext, getXSomethingFromArgs< beans::XPropertySet >( args, 1, false ), excel::GetModelFromRange( getXSomethingFromArgs< uno::XInterface >( args, 1 ) ), true ), mbIsRows( false ), mbIsColumns( false )
{
mxRange.set( mxPropertySet, uno::UNO_QUERY );
mxRanges.set( mxPropertySet, uno::UNO_QUERY );
uno::Reference< container::XIndexAccess > xIndex;
if ( mxRange.is() )
{
xIndex = new SingleRangeIndexAccess( mxParent, mxContext, mxRange );
}
else if ( mxRanges.is() )
{
xIndex.set( mxRanges, uno::UNO_QUERY_THROW );
}
m_Areas = new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns );
}
ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange, sal_Bool bIsRows, sal_Bool bIsColumns ) throw( lang::IllegalArgumentException )
: ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRange, uno::UNO_QUERY_THROW ), excel::GetModelFromRange( xRange), true ), mxRange( xRange ),
mbIsRows( bIsRows ),
mbIsColumns( bIsColumns )
{
if ( !xContext.is() )
throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "context is not set " ) ), uno::Reference< uno::XInterface >() , 1 );
if ( !xRange.is() )
throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "range is not set " ) ), uno::Reference< uno::XInterface >() , 1 );
uno::Reference< container::XIndexAccess > xIndex( new SingleRangeIndexAccess( mxParent, mxContext, xRange ) );
m_Areas = new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns );
}
ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges, sal_Bool bIsRows, sal_Bool bIsColumns ) throw ( lang::IllegalArgumentException )
: ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRanges, uno::UNO_QUERY_THROW ), excel::GetModelFromRange( uno::Reference< uno::XInterface >( xRanges, uno::UNO_QUERY_THROW ) ), true ), mxRanges( xRanges ),mbIsRows( bIsRows ), mbIsColumns( bIsColumns )
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
m_Areas = new ScVbaRangeAreas( xParent, mxContext, xIndex, mbIsRows, mbIsColumns );
}
ScVbaRange::~ScVbaRange()
{
}
uno::Reference< XCollection >& ScVbaRange::getBorders()
{
if ( !m_Borders.is() )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
m_Borders = lcl_setupBorders( this, mxContext, uno::Reference< table::XCellRange >( xRange->getCellRange(), uno::UNO_QUERY_THROW ) );
}
return m_Borders;
}
void
ScVbaRange::visitArray( ArrayVisitor& visitor )
{
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount();
sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
for ( sal_Int32 i=0; i<nRowCount; ++i )
{
for ( sal_Int32 j=0; j<nColCount; ++j )
{
uno::Reference< table::XCell > xCell( mxRange->getCellByPosition( j, i ), uno::UNO_QUERY_THROW );
visitor.visitNode( i, j, xCell );
}
}
}
uno::Any SAL_CALL ScVbaRange::getName() throw (uno::RuntimeException)
{
uno::Reference< excel::XName > xName;
ScDocShell* pDocShell = getScDocShell();
uno::Reference< frame::XModel > xModel = pDocShell ? pDocShell->GetModel() : NULL;
if ( !xModel.is() )
{
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid document" )), uno::Reference< uno::XInterface >() );
}
uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW );
uno::Reference< sheet::XNamedRanges > xNamedRanges( xPropertySet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NamedRanges"))) , uno::UNO_QUERY_THROW );
uno::Reference< excel::XNames > xNames( new ScVbaNames( uno::Reference< XHelperInterface >(), mxContext , xNamedRanges , xModel ) );
sal_Int32 nCount = xNames->getCount();
ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
if ( pUnoRangesBase && nCount > 0 )
{
ScRangeList aRangeList = pUnoRangesBase->GetRangeList();
for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
{
uno::Reference< excel::XName > xTmpName( xNames->Item( uno::makeAny( nIndex + 1 ), uno::Any() ), uno::UNO_QUERY );
if ( xTmpName.is() )
{
try
{
uno::Reference< excel::XRange > xRange = xTmpName->getRefersToRange();
if ( xRange.is() )
{
ScVbaRange* pRange = dynamic_cast< ScVbaRange* >( xRange.get() );
ScCellRangesBase* pCurRangesBase = pRange ? pRange->getCellRangesBase() : NULL;
if ( pCurRangesBase && aRangeList == pCurRangesBase->GetRangeList() )
{
xName = xTmpName;
break;
}
}
}
catch (const uno::Exception&)
{
}
}
}
}
return uno::makeAny( xName );
}
void
ScVbaRange::setName( const uno::Any& aName ) throw (uno::RuntimeException)
{
uno::Reference< excel::XName > xName;
ScDocShell* pDocShell = getScDocShell();
uno::Reference< frame::XModel > xModel = pDocShell ? pDocShell->GetModel() : NULL;
if ( !xModel.is() )
{
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid document" )), uno::Reference< uno::XInterface >() );
}
uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW );
uno::Reference< sheet::XNamedRanges > xNamedRanges( xPropertySet->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NamedRanges"))) , uno::UNO_QUERY_THROW );
uno::Reference< excel::XNames > xNames( new ScVbaNames( uno::Reference< XHelperInterface >(), mxContext , xNamedRanges , xModel ) );
uno::Any aDummy;
//uno::Any aRefersTo;
// aRefersTo <<= uno::Reference< excel::XRange >(this, uno::UNO_QUERY);
xNames->Add(aName, getCellRange(), aDummy, aDummy, aDummy, aDummy,
aDummy, aDummy, aDummy, aDummy, aDummy);
}
uno::Any
ScVbaRange::getValue( ValueGetter& valueGetter) throw (uno::RuntimeException)
{
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
// single cell range
if ( isSingleCellRange() )
{
visitArray( valueGetter );
return valueGetter.getValue();
}
sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount();
sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
// multi cell range ( return array )
Dim2ArrayValueGetter arrayGetter( nRowCount, nColCount, valueGetter );
visitArray( arrayGetter );
return uno::makeAny( script::ArrayWrapper( false, arrayGetter.getValue() ) );
}
uno::Any SAL_CALL
ScVbaRange::getValue() throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->getValue();
}
CellValueGetter valueGetter;
return getValue( valueGetter );
}
void
ScVbaRange::setValue( const uno::Any& aValue, ValueSetter& valueSetter, bool bFireEvent ) throw (uno::RuntimeException)
{
uno::TypeClass aClass = aValue.getValueTypeClass();
if ( aClass == uno::TypeClass_SEQUENCE )
{
uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
uno::Any aConverted;
try
{
// test for single dimension, could do
// with a better test than this
if ( aValue.getValueTypeName().indexOf('[') == aValue.getValueTypeName().lastIndexOf('[') )
{
aConverted = xConverter->convertTo( aValue, getCppuType((uno::Sequence< uno::Any >*)0) );
Dim1ArrayValueSetter setter( aConverted, valueSetter );
visitArray( setter );
}
else
{
aConverted = xConverter->convertTo( aValue, getCppuType((uno::Sequence< uno::Sequence< uno::Any > >*)0) );
Dim2ArrayValueSetter setter( aConverted, valueSetter );
visitArray( setter );
}
}
catch ( const uno::Exception& e )
{
OSL_TRACE("Bahhh, caught exception %s",
rtl::OUStringToOString( e.Message,
RTL_TEXTENCODING_UTF8 ).getStr() );
}
}
else
{
visitArray( valueSetter );
}
if( bFireEvent ) fireChangeEvent();
}
void SAL_CALL
ScVbaRange::setValue( const uno::Any &aValue ) throw (uno::RuntimeException)
{
// If this is a multiple selection apply setValue over all areas
if ( m_Areas->getCount() > 1 )
{
AreasVisitor aVisitor( m_Areas );
RangeValueProcessor valueProcessor( aValue );
aVisitor.visit( valueProcessor );
return;
}
CellValueSetter valueSetter( aValue );
setValue( aValue, valueSetter, true );
#if 0 // TODO: Noel, do we still need this?
// Fires the range change event.
lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
#endif
}
void SAL_CALL
ScVbaRange::Clear() throw (uno::RuntimeException)
{
using namespace ::com::sun::star::sheet::CellFlags;
sal_Int32 nFlags = VALUE | DATETIME | STRING | FORMULA | HARDATTR | EDITATTR | FORMATTED;
ClearContents( nFlags, true );
#if 0 // TODO: do we still need this?
// Fires the range change event.
lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
#endif
}
//helper ClearContent
void
ScVbaRange::ClearContents( sal_Int32 nFlags, bool bFireEvent ) throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
ScVbaRange* pRange = getImplementation( xRange );
if ( pRange )
pRange->ClearContents( nFlags, false ); // do not fire for single ranges
}
// fire change event for the entire range list
if( bFireEvent ) fireChangeEvent();
return;
}
uno::Reference< sheet::XSheetOperation > xSheetOperation(mxRange, uno::UNO_QUERY_THROW);
xSheetOperation->clearContents( nFlags );
if( bFireEvent ) fireChangeEvent();
}
void SAL_CALL
ScVbaRange::ClearComments() throw (uno::RuntimeException)
{
ClearContents( sheet::CellFlags::ANNOTATION, false );
}
void SAL_CALL
ScVbaRange::ClearContents() throw (uno::RuntimeException)
{
sal_Int32 nClearFlags = ( sheet::CellFlags::VALUE |
sheet::CellFlags::STRING | sheet::CellFlags::DATETIME |
sheet::CellFlags::FORMULA );
ClearContents( nClearFlags, true );
#if 0 // TODO: do we still need this?
// Fires the range change event.
lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
#endif
}
void SAL_CALL
ScVbaRange::ClearFormats() throw (uno::RuntimeException)
{
//FIXME: need to check if we need to combine sheet::CellFlags::FORMATTED
sal_Int32 nClearFlags = sheet::CellFlags::HARDATTR | sheet::CellFlags::FORMATTED | sheet::CellFlags::EDITATTR;
ClearContents( nClearFlags, false );
#if 0 // TODO: do we still need this?
// Fires the range change event.
lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
#endif
}
void
ScVbaRange::setFormulaValue( const uno::Any& rFormula, formula::FormulaGrammar::Grammar eGram, bool bFireEvent ) throw (uno::RuntimeException)
{
// If this is a multiple selection apply setFormula over all areas
if ( m_Areas->getCount() > 1 )
{
AreasVisitor aVisitor( m_Areas );
RangeFormulaProcessor valueProcessor( rFormula );
aVisitor.visit( valueProcessor );
return;
}
CellFormulaValueSetter formulaValueSetter( rFormula, getScDocument(), eGram );
setValue( rFormula, formulaValueSetter, bFireEvent );
#if 0 // TODO: ditto
// Fires the range change event.
lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
#endif
}
uno::Any
ScVbaRange::getFormulaValue( formula::FormulaGrammar::Grammar eGram ) throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->getFormula();
}
CellFormulaValueGetter valueGetter( getScDocument(), eGram );
return getValue( valueGetter );
}
void
ScVbaRange::setFormula(const uno::Any &rFormula ) throw (uno::RuntimeException)
{
// #FIXME converting "=$a$1" e.g. CONV_XL_A1 -> CONV_OOO // results in "=$a$1:a1", temporalily disable conversion
setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
}
uno::Any
ScVbaRange::getFormulaR1C1() throw (::com::sun::star::uno::RuntimeException)
{
return getFormulaValue( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 );
}
void
ScVbaRange::setFormulaR1C1(const uno::Any& rFormula ) throw (uno::RuntimeException)
{
setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
}
uno::Any
ScVbaRange::getFormula() throw (::com::sun::star::uno::RuntimeException)
{
return getFormulaValue( formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
}
sal_Int32
ScVbaRange::getCount() throw (uno::RuntimeException)
{
// If this is a multiple selection apply setValue over all areas
if ( m_Areas->getCount() > 1 )
{
AreasVisitor aVisitor( m_Areas );
RangeCountProcessor valueProcessor;
aVisitor.visit( valueProcessor );
return valueProcessor.value();
}
sal_Int32 rowCount = 0;
sal_Int32 colCount = 0;
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
rowCount = xColumnRowRange->getRows()->getCount();
colCount = xColumnRowRange->getColumns()->getCount();
if( IsRows() )
return rowCount;
if( IsColumns() )
return colCount;
return rowCount * colCount;
}
sal_Int32
ScVbaRange::getRow() throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->getRow();
}
uno::Reference< sheet::XCellAddressable > xCellAddressable(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
return xCellAddressable->getCellAddress().Row + 1; // Zero value indexing
}
sal_Int32
ScVbaRange::getColumn() throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->getColumn();
}
uno::Reference< sheet::XCellAddressable > xCellAddressable(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
return xCellAddressable->getCellAddress().Column + 1; // Zero value indexing
}
uno::Any
ScVbaRange::HasFormula() throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
uno::Any aResult = aNULL();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
// if the HasFormula for any area is different to another
// return null
if ( index > 1 )
if ( aResult != xRange->HasFormula() )
return aNULL();
aResult = xRange->HasFormula();
if ( aNULL() == aResult )
return aNULL();
}
return aResult;
}
uno::Reference< uno::XInterface > xIf( mxRange, uno::UNO_QUERY_THROW );
ScCellRangesBase* pThisRanges = dynamic_cast< ScCellRangesBase * > ( xIf.get() );
if ( pThisRanges )
{
uno::Reference<uno::XInterface> xRanges( pThisRanges->queryFormulaCells( ( sheet::FormulaResult::ERROR | sheet::FormulaResult::VALUE | sheet::FormulaResult::STRING ) ), uno::UNO_QUERY_THROW );
ScCellRangesBase* pFormulaRanges = dynamic_cast< ScCellRangesBase * > ( xRanges.get() );
// check if there are no formula cell, return false
if ( pFormulaRanges->GetRangeList().empty() )
return uno::makeAny(sal_False);
// chech if there are holes (where some cells are not formulas)
// or returned range is not equal to this range
if ( ( pFormulaRanges->GetRangeList().size() > 1 )
|| ( pFormulaRanges->GetRangeList().front()->aStart != pThisRanges->GetRangeList().front()->aStart )
|| ( pFormulaRanges->GetRangeList().front()->aEnd != pThisRanges->GetRangeList().front()->aEnd )
)
return aNULL(); // should return aNULL;
}
return uno::makeAny( sal_True );
}
void
ScVbaRange::fillSeries( sheet::FillDirection nFillDirection, sheet::FillMode nFillMode, sheet::FillDateMode nFillDateMode, double fStep, double fEndValue ) throw( uno::RuntimeException )
{
if ( m_Areas->getCount() > 1 )
{
// Multi-Area Range
uno::Reference< XCollection > xCollection( m_Areas, uno::UNO_QUERY_THROW );
for ( sal_Int32 index = 1; index <= xCollection->getCount(); ++index )
{
uno::Reference< excel::XRange > xRange( xCollection->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
ScVbaRange* pThisRange = getImplementation( xRange );
pThisRange->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue );
}
return;
}
uno::Reference< sheet::XCellSeries > xCellSeries(mxRange, uno::UNO_QUERY_THROW );
xCellSeries->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue );
// Fires the range change event.
lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
}
void
ScVbaRange::FillLeft() throw (uno::RuntimeException)
{
fillSeries(sheet::FillDirection_TO_LEFT,
sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
}
void
ScVbaRange::FillRight() throw (uno::RuntimeException)
{
fillSeries(sheet::FillDirection_TO_RIGHT,
sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
}
void
ScVbaRange::FillUp() throw (uno::RuntimeException)
{
fillSeries(sheet::FillDirection_TO_TOP,
sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
}
void
ScVbaRange::FillDown() throw (uno::RuntimeException)
{
fillSeries(sheet::FillDirection_TO_BOTTOM,
sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
}
::rtl::OUString
ScVbaRange::getText() throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->getText();
}
uno::Reference< text::XTextRange > xTextRange(mxRange->getCellByPosition(0,0), uno::UNO_QUERY_THROW );
return xTextRange->getString();
}
uno::Reference< excel::XRange >
ScVbaRange::Offset( const ::uno::Any &nRowOff, const uno::Any &nColOff ) throw (uno::RuntimeException)
{
SCROW nRowOffset = 0;
SCCOL nColOffset = 0;
sal_Bool bIsRowOffset = ( nRowOff >>= nRowOffset );
sal_Bool bIsColumnOffset = ( nColOff >>= nColOffset );
ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
for ( size_t i = 0, nRanges = aCellRanges.size(); i < nRanges; ++i )
{
ScRange* pRange = aCellRanges[ i ];
if ( bIsColumnOffset )
{
pRange->aStart.SetCol( pRange->aStart.Col() + nColOffset );
pRange->aEnd.SetCol( pRange->aEnd.Col() + nColOffset );
}
if ( bIsRowOffset )
{
pRange->aStart.SetRow( pRange->aStart.Row() + nRowOffset );
pRange->aEnd.SetRow( pRange->aEnd.Row() + nRowOffset );
}
}
if ( aCellRanges.size() > 1 ) // Multi-Area
{
uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pUnoRangesBase->GetDocShell(), aCellRanges ) );
return new ScVbaRange( mxParent, mxContext, xRanges );
}
// normal range
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), *aCellRanges.front() ) );
return new ScVbaRange( mxParent, mxContext, xRange );
}
uno::Reference< excel::XRange >
ScVbaRange::CurrentRegion() throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->CurrentRegion();
}
RangeHelper helper( mxRange );
uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
helper.getSheetCellCursor();
xSheetCellCursor->collapseToCurrentRegion();
uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
return RangeHelper::createRangeFromRange( mxParent, mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
}
uno::Reference< excel::XRange >
ScVbaRange::CurrentArray() throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->CurrentArray();
}
RangeHelper helper( mxRange );
uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
helper.getSheetCellCursor();
xSheetCellCursor->collapseToCurrentArray();
uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
return RangeHelper::createRangeFromRange( mxParent, mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
}
uno::Any
ScVbaRange::getFormulaArray() throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->getFormulaArray();
}
uno::Reference< sheet::XCellRangeFormula> xCellRangeFormula( mxRange, uno::UNO_QUERY_THROW );
uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
uno::Any aMatrix;
uno::Sequence< uno::Sequence<rtl::OUString> > aFmArray = xCellRangeFormula->getFormulaArray();
if( aFmArray.getLength() )
{
if( aFmArray.getLength() == 1 && aFmArray[0].getLength() == 1 )
aMatrix <<= aFmArray[0][0];
else
aMatrix = xConverter->convertTo( uno::makeAny( xCellRangeFormula->getFormulaArray() ) , getCppuType((uno::Sequence< uno::Sequence< uno::Any > >*)0) ) ;
}
return aMatrix;
}
void
ScVbaRange::setFormulaArray(const uno::Any& rFormula) throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->setFormulaArray( rFormula );
}
// #TODO need to distinguish between getFormula and getFormulaArray e.g. (R1C1)
// but for the moment its just easier to treat them the same for setting
setFormula( rFormula );
}
::rtl::OUString
ScVbaRange::Characters(const uno::Any& Start, const uno::Any& Length) throw (uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->Characters( Start, Length );
}
long nIndex = 0, nCount = 0;
::rtl::OUString rString;
uno::Reference< text::XTextRange > xTextRange(mxRange, ::uno::UNO_QUERY_THROW );
rString = xTextRange->getString();
if( !( Start >>= nIndex ) && !( Length >>= nCount ) )
return rString;
if(!( Start >>= nIndex ) )
nIndex = 1;
if(!( Length >>= nCount ) )
nIndex = rString.getLength();
return rString.copy( --nIndex, nCount ); // Zero value indexing
}
::rtl::OUString
ScVbaRange::Address( const uno::Any& RowAbsolute, const uno::Any& ColumnAbsolute, const uno::Any& ReferenceStyle, const uno::Any& External, const uno::Any& RelativeTo ) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
// Multi-Area Range
rtl::OUString sAddress;
uno::Reference< XCollection > xCollection( m_Areas, uno::UNO_QUERY_THROW );
uno::Any aExternalCopy = External;
for ( sal_Int32 index = 1; index <= xCollection->getCount(); ++index )
{
uno::Reference< excel::XRange > xRange( xCollection->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
if ( index > 1 )
{
sAddress += rtl::OUString( ',' );
// force external to be false
// only first address should have the
// document and sheet specifications
aExternalCopy = uno::makeAny(sal_False);
}
sAddress += xRange->Address( RowAbsolute, ColumnAbsolute, ReferenceStyle, aExternalCopy, RelativeTo );
}
return sAddress;
}
ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
if ( ReferenceStyle.hasValue() )
{
sal_Int32 refStyle = excel::XlReferenceStyle::xlA1;
ReferenceStyle >>= refStyle;
if ( refStyle == excel::XlReferenceStyle::xlR1C1 )
dDetails = ScAddress::Details( formula::FormulaGrammar::CONV_XL_R1C1, 0, 0 );
}
sal_uInt16 nFlags = SCA_VALID;
ScDocShell* pDocShell = getScDocShell();
ScDocument* pDoc = pDocShell->GetDocument();
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
ScRange aRange( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCROW >( thisAddress.StartRow ), static_cast< SCTAB >( thisAddress.Sheet ), static_cast< SCCOL >( thisAddress.EndColumn ), static_cast< SCROW >( thisAddress.EndRow ), static_cast< SCTAB >( thisAddress.Sheet ) );
String sRange;
sal_uInt16 ROW_ABSOLUTE = ( SCA_ROW_ABSOLUTE | SCA_ROW2_ABSOLUTE );
sal_uInt16 COL_ABSOLUTE = ( SCA_COL_ABSOLUTE | SCA_COL2_ABSOLUTE );
// default
nFlags |= ( SCA_TAB_ABSOLUTE | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB2_ABSOLUTE | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE );
if ( RowAbsolute.hasValue() )
{
sal_Bool bVal = sal_True;
RowAbsolute >>= bVal;
if ( !bVal )
nFlags &= ~ROW_ABSOLUTE;
}
if ( ColumnAbsolute.hasValue() )
{
sal_Bool bVal = sal_True;
ColumnAbsolute >>= bVal;
if ( !bVal )
nFlags &= ~COL_ABSOLUTE;
}
sal_Bool bLocal = false;
if ( External.hasValue() )
{
External >>= bLocal;
if ( bLocal )
nFlags |= SCA_TAB_3D | SCA_FORCE_DOC;
}
if ( RelativeTo.hasValue() )
{
// #TODO should I throw an error if R1C1 is not set?
table::CellRangeAddress refAddress = getCellRangeAddressForVBARange( RelativeTo, pDocShell );
dDetails = ScAddress::Details( formula::FormulaGrammar::CONV_XL_R1C1, static_cast< SCROW >( refAddress.StartRow ), static_cast< SCCOL >( refAddress.StartColumn ) );
}
aRange.Format( sRange, nFlags, pDoc, dDetails );
return sRange;
}
uno::Reference < excel::XFont >
ScVbaRange::Font() throw ( script::BasicErrorException, uno::RuntimeException)
{
uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY );
ScDocument* pDoc = getScDocument();
if ( mxRange.is() )
xProps.set(mxRange, ::uno::UNO_QUERY );
else if ( mxRanges.is() )
xProps.set(mxRanges, ::uno::UNO_QUERY );
if ( !pDoc )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() );
ScVbaPalette aPalette( pDoc->GetDocumentShell() );
ScCellRangeObj* pRangeObj = NULL;
try
{
pRangeObj = getCellRangeObj();
}
catch( uno::Exception& )
{
}
return new ScVbaFont( this, mxContext, aPalette, xProps, pRangeObj );
}
uno::Reference< excel::XRange >
ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) throw(uno::RuntimeException)
{
// #TODO code within the test below "if ( m_Areas.... " can be removed
// Test is performed only because m_xRange is NOT set to be
// the first range in m_Areas ( to force failure while
// the implementations for each method are being updated )
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->Cells( nRowIndex, nColumnIndex );
}
// Performance: Use a common helper method for ScVbaRange::Cells and ScVbaWorksheet::Cells,
// instead of creating a new ScVbaRange object in often-called ScVbaWorksheet::Cells
return CellsHelper( mxParent, mxContext, mxRange, nRowIndex, nColumnIndex );
}
// static
uno::Reference< excel::XRange >
ScVbaRange::CellsHelper( const uno::Reference< ov::XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< css::table::XCellRange >& xRange,
const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) throw(uno::RuntimeException)
{
sal_Int32 nRow = 0, nColumn = 0;
sal_Bool bIsIndex = nRowIndex.hasValue();
sal_Bool bIsColumnIndex = nColumnIndex.hasValue();
// Sometimes we might get a float or a double or whatever
// set in the Any, we should convert as appropriate
// #FIXME - perhaps worth turning this into some sort of
// convertion routine e.g. bSuccess = getValueFromAny( nRow, nRowIndex, getCppuType((sal_Int32*)0) )
uno::Any aRowIndexAny = nRowIndex;
if ( aRowIndexAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
{
try
{
aRowIndexAny = getDefaultPropByIntrospection( aRowIndexAny );
}
catch( uno::Exception& ) {}
}
else if ( aRowIndexAny.hasValue() && !( aRowIndexAny >>= nRow ) )
{
uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( xContext );
uno::Any aConverted;
try
{
aConverted = xConverter->convertTo( aRowIndexAny, getCppuType((sal_Int32*)0) );
bIsIndex = ( aConverted >>= nRow );
}
catch( uno::Exception& ) {} // silence any errors
}
uno::Any aColumnAny = nColumnIndex;
if ( bIsColumnIndex )
{
// Column index can be a col address e.g Cells( 1, "B" ) etc.
rtl::OUString sCol;
if ( nColumnIndex >>= sCol )
{
ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
ScRange tmpRange;
sal_uInt16 flags = tmpRange.ParseCols( sCol, excel::GetDocumentFromRange( xRange ), dDetails );
if ( ( flags & 0x200 ) != 0x200 )
throw uno::RuntimeException();
nColumn = tmpRange.aStart.Col() + 1;
}
else
{
if ( aColumnAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
{
try
{
aColumnAny = getDefaultPropByIntrospection( aColumnAny );
}
catch( uno::Exception& ) {}
}
if ( !( aColumnAny >>= nColumn ) )
{
uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( xContext );
uno::Any aConverted;
try
{
aConverted = xConverter->convertTo( aColumnAny, getCppuType((sal_Int32*)0) );
bIsColumnIndex = ( aConverted >>= nColumn );
}
catch( uno::Exception& ) {} // silence any errors
}
}
}
RangeHelper thisRange( xRange );
table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
uno::Reference< table::XCellRange > xSheetRange = thisRange.getCellRangeFromSheet();
if( !bIsIndex && !bIsColumnIndex ) // .Cells
// #FIXE needs proper parent ( Worksheet )
return uno::Reference< excel::XRange >( new ScVbaRange( xParent, xContext, xRange ) );
sal_Int32 nIndex = --nRow;
if( bIsIndex && !bIsColumnIndex ) // .Cells(n)
{
uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, ::uno::UNO_QUERY_THROW);
sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
if ( !nIndex || nIndex < 0 )
nRow = 0;
else
nRow = nIndex / nColCount;
nColumn = nIndex % nColCount;
}
else
--nColumn;
nRow = nRow + thisRangeAddress.StartRow;
nColumn = nColumn + thisRangeAddress.StartColumn;
return new ScVbaRange( xParent, xContext, xSheetRange->getCellRangeByPosition( nColumn, nRow, nColumn, nRow ) );
}
void
ScVbaRange::Select() throw (uno::RuntimeException)
{
ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
if ( !pUnoRangesBase )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access underlying uno range object" ) ), uno::Reference< uno::XInterface >() );
ScDocShell* pShell = pUnoRangesBase->GetDocShell();
if ( pShell )
{
uno::Reference< frame::XModel > xModel( pShell->GetModel(), uno::UNO_QUERY_THROW );
uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
if ( mxRanges.is() )
xSelection->select( uno::Any( lclExpandToMerged( mxRanges, true ) ) );
else
xSelection->select( uno::Any( lclExpandToMerged( mxRange, true ) ) );
// set focus on document e.g.
// ThisComponent.CurrentController.Frame.getContainerWindow.SetFocus
try
{
uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_QUERY_THROW );
uno::Reference< awt::XWindow > xWin( xFrame->getContainerWindow(), uno::UNO_QUERY_THROW );
xWin->setFocus();
}
catch( uno::Exception& )
{
}
}
}
bool cellInRange( const table::CellRangeAddress& rAddr, const sal_Int32& nCol, const sal_Int32& nRow )
{
if ( nCol >= rAddr.StartColumn && nCol <= rAddr.EndColumn &&
nRow >= rAddr.StartRow && nRow <= rAddr.EndRow )
return true;
return false;
}
void setCursor( const SCCOL& nCol, const SCROW& nRow, const uno::Reference< frame::XModel >& xModel, bool bInSel = true )
{
ScTabViewShell* pShell = excel::getBestViewShell( xModel );
if ( pShell )
{
if ( bInSel )
pShell->SetCursor( nCol, nRow );
else
pShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_NONE, false, false, sal_True, false );
}
}
void
ScVbaRange::Activate() throw (uno::RuntimeException)
{
// get first cell of current range
uno::Reference< table::XCellRange > xCellRange;
if ( mxRanges.is() )
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
}
else
xCellRange.set( mxRange, uno::UNO_QUERY_THROW );
RangeHelper thisRange( xCellRange );
uno::Reference< sheet::XCellRangeAddressable > xThisRangeAddress = thisRange.getCellRangeAddressable();
table::CellRangeAddress thisRangeAddress = xThisRangeAddress->getRangeAddress();
uno::Reference< frame::XModel > xModel;
ScDocShell* pShell = getScDocShell();
if ( pShell )
xModel = pShell->GetModel();
if ( !xModel.is() )
throw uno::RuntimeException();
// get current selection
uno::Reference< sheet::XCellRangeAddressable > xRange( xModel->getCurrentSelection(), ::uno::UNO_QUERY);
uno::Reference< sheet::XSheetCellRanges > xRanges( xModel->getCurrentSelection(), ::uno::UNO_QUERY);
if ( xRanges.is() )
{
uno::Sequence< table::CellRangeAddress > nAddrs = xRanges->getRangeAddresses();
for ( sal_Int32 index = 0; index < nAddrs.getLength(); ++index )
{
if ( cellInRange( nAddrs[index], thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
{
setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
return;
}
}
}
if ( xRange.is() && cellInRange( xRange->getRangeAddress(), thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
else
{
// if this range is multi cell select the range other
// wise just position the cell at this single range position
if ( isSingleCellRange() )
// This top-leftmost cell of this Range is not in the current
// selection so just select this range
setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel, false );
else
Select();
}
}
uno::Reference< excel::XRange >
ScVbaRange::Rows(const uno::Any& aIndex ) throw (uno::RuntimeException)
{
rtl::OUString sAddress;
if ( aIndex.hasValue() )
{
sal_Int32 nValue = 0;
ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
ScRange aRange = *aCellRanges.front();
if( aIndex >>= nValue )
{
aRange.aStart.SetRow( aRange.aStart.Row() + --nValue );
aRange.aEnd.SetRow( aRange.aStart.Row() );
}
else if ( aIndex >>= sAddress )
{
ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
ScRange tmpRange;
tmpRange.ParseRows( sAddress, excel::GetDocumentFromRange( mxRange ), dDetails );
SCROW nStartRow = tmpRange.aStart.Row();
SCROW nEndRow = tmpRange.aEnd.Row();
aRange.aStart.SetRow( aRange.aStart.Row() + nStartRow );
aRange.aEnd.SetRow( aRange.aStart.Row() + ( nEndRow - nStartRow ));
}
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Illegal param" ) ), uno::Reference< uno::XInterface >() );
if ( aRange.aStart.Row() < 0 || aRange.aEnd.Row() < 0 )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Internal failure, illegal param")), uno::Reference< uno::XInterface >() );
// return a normal range ( even for multi-selection
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), aRange ) );
return new ScVbaRange( mxParent, mxContext, xRange, true );
}
// Rows() - no params
if ( m_Areas->getCount() > 1 )
return new ScVbaRange( mxParent, mxContext, mxRanges, true );
return new ScVbaRange( mxParent, mxContext, mxRange, true );
}
uno::Reference< excel::XRange >
ScVbaRange::Columns(const uno::Any& aIndex ) throw (uno::RuntimeException)
{
rtl::OUString sAddress;
ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
ScRange aRange = *aCellRanges.front();
if ( aIndex.hasValue() )
{
sal_Int32 nValue = 0;
if ( aIndex >>= nValue )
{
aRange.aStart.SetCol( aRange.aStart.Col() + static_cast< SCCOL > ( --nValue ) );
aRange.aEnd.SetCol( aRange.aStart.Col() );
}
else if ( aIndex >>= sAddress )
{
ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
ScRange tmpRange;
tmpRange.ParseCols( sAddress, excel::GetDocumentFromRange( mxRange ), dDetails );
SCCOL nStartCol = tmpRange.aStart.Col();
SCCOL nEndCol = tmpRange.aEnd.Col();
aRange.aStart.SetCol( aRange.aStart.Col() + nStartCol );
aRange.aEnd.SetCol( aRange.aStart.Col() + ( nEndCol - nStartCol ));
}
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Illegal param" ) ), uno::Reference< uno::XInterface >() );
if ( aRange.aStart.Col() < 0 || aRange.aEnd.Col() < 0 )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Internal failure, illegal param")), uno::Reference< uno::XInterface >() );
}
// Columns() - no params
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), aRange ) );
return new ScVbaRange( mxParent, mxContext, xRange, false, true );
}
void
ScVbaRange::setMergeCells( const uno::Any& aIsMerged ) throw (script::BasicErrorException, uno::RuntimeException)
{
bool bMerge = extractBoolFromAny( aIsMerged );
if( mxRanges.is() )
{
sal_Int32 nCount = mxRanges->getCount();
// VBA does nothing (no error) if the own ranges overlap somehow
::std::vector< table::CellRangeAddress > aList;
for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
{
uno::Reference< sheet::XCellRangeAddressable > xRangeAddr( mxRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
table::CellRangeAddress aAddress = xRangeAddr->getRangeAddress();
for( ::std::vector< table::CellRangeAddress >::const_iterator aIt = aList.begin(), aEnd = aList.end(); aIt != aEnd; ++aIt )
if( ScUnoConversion::Intersects( *aIt, aAddress ) )
return;
aList.push_back( aAddress );
}
// (un)merge every range after it has been extended to intersecting merged ranges from sheet
for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
{
uno::Reference< table::XCellRange > xRange( mxRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
lclExpandAndMerge( xRange, bMerge );
}
return;
}
// otherwise, merge single range
lclExpandAndMerge( mxRange, bMerge );
}
uno::Any
ScVbaRange::getMergeCells() throw (script::BasicErrorException, uno::RuntimeException)
{
if( mxRanges.is() )
{
sal_Int32 nCount = mxRanges->getCount();
for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
{
uno::Reference< table::XCellRange > xRange( mxRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
util::TriState eMerged = lclGetMergedState( xRange );
/* Excel always returns NULL, if one range of the range list is
partly or completely merged. Even if all ranges are completely
merged, the return value is still NULL. */
if( eMerged != util::TriState_NO )
return aNULL();
}
// no range is merged anyhow, return false
return uno::Any( false );
}
// otherwise, check single range
switch( lclGetMergedState( mxRange ) )
{
case util::TriState_YES: return uno::Any( true );
case util::TriState_NO: return uno::Any( false );
default: return aNULL();
}
}
void
ScVbaRange::Copy(const ::uno::Any& Destination) throw (uno::RuntimeException)
{
if ( Destination.hasValue() )
{
// #TODO support ( if necessary ) multi-area range in this scenario
if ( m_Areas->getCount() > 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("!!! That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() );
uno::Reference< excel::XRange > xRange( Destination, uno::UNO_QUERY_THROW );
uno::Any aRange = xRange->getCellRange();
uno::Reference< table::XCellRange > xCellRange;
aRange >>= xCellRange;
uno::Reference< sheet::XSheetCellRange > xSheetCellRange(xCellRange, ::uno::UNO_QUERY_THROW);
uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet();
uno::Reference< table::XCellRange > xDest( xSheet, uno::UNO_QUERY_THROW );
uno::Reference< sheet::XCellRangeMovement > xMover( xSheet, uno::UNO_QUERY_THROW);
uno::Reference< sheet::XCellAddressable > xDestination( xDest->getCellByPosition(
xRange->getColumn()-1,xRange->getRow()-1), uno::UNO_QUERY_THROW );
uno::Reference< sheet::XCellRangeAddressable > xSource( mxRange, uno::UNO_QUERY);
xMover->copyRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
}
else
{
if ( m_Areas->getCount() > 1 )
{
uno::Reference< frame::XModel > xModel = excel::GetModelFromRange( mxRanges );
ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
ScRangeList aList = pUnoRangesBase->GetRangeList();
if ( !excel::implnCopyRanges( xModel, aList ) )
{
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() );
}
}
else
{
ScRange aRange;
RangeHelper thisRange( mxRange );
uno::Reference< frame::XModel > xModel = excel::GetModelFromRange( mxRange );
ScUnoConversion::FillScRange( aRange, thisRange.getCellRangeAddressable()->getRangeAddress() );
excel::implnCopyRange( xModel, aRange );
}
}
}
void
ScVbaRange::Cut(const ::uno::Any& Destination) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() );
if (Destination.hasValue())
{
uno::Reference< excel::XRange > xRange( Destination, uno::UNO_QUERY_THROW );
uno::Reference< table::XCellRange > xCellRange( xRange->getCellRange(), uno::UNO_QUERY_THROW );
uno::Reference< sheet::XSheetCellRange > xSheetCellRange(xCellRange, ::uno::UNO_QUERY_THROW );
uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet();
uno::Reference< table::XCellRange > xDest( xSheet, uno::UNO_QUERY_THROW );
uno::Reference< sheet::XCellRangeMovement > xMover( xSheet, uno::UNO_QUERY_THROW);
uno::Reference< sheet::XCellAddressable > xDestination( xDest->getCellByPosition(
xRange->getColumn()-1,xRange->getRow()-1), uno::UNO_QUERY);
uno::Reference< sheet::XCellRangeAddressable > xSource( mxRange, uno::UNO_QUERY);
xMover->moveRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
}
else {
uno::Reference< frame::XModel > xModel = excel::GetModelFromRange( mxRange );
Select();
excel::implnCut( xModel );
}
}
void
ScVbaRange::setNumberFormat( const uno::Any& aFormat ) throw ( script::BasicErrorException, uno::RuntimeException)
{
rtl::OUString sFormat;
aFormat >>= sFormat;
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->setNumberFormat( aFormat );
}
return;
}
NumFormatHelper numFormat( mxRange );
numFormat.setNumberFormat( sFormat );
}
uno::Any
ScVbaRange::getNumberFormat() throw ( script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
uno::Any aResult = aNULL();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
// if the numberformat of one area is different to another
// return null
if ( index > 1 )
if ( aResult != xRange->getNumberFormat() )
return aNULL();
aResult = xRange->getNumberFormat();
if ( aNULL() == aResult )
return aNULL();
}
return aResult;
}
NumFormatHelper numFormat( mxRange );
rtl::OUString sFormat = numFormat.getNumberFormatString();
if ( sFormat.getLength() > 0 )
return uno::makeAny( sFormat );
return aNULL();
}
uno::Reference< excel::XRange >
ScVbaRange::Resize( const uno::Any &RowSize, const uno::Any &ColumnSize ) throw (uno::RuntimeException)
{
long nRowSize = 0, nColumnSize = 0;
sal_Bool bIsRowChanged = ( RowSize >>= nRowSize ), bIsColumnChanged = ( ColumnSize >>= nColumnSize );
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, ::uno::UNO_QUERY_THROW);
uno::Reference< sheet::XSheetCellRange > xSheetRange(mxRange, ::uno::UNO_QUERY_THROW);
uno::Reference< sheet::XSheetCellCursor > xCursor( xSheetRange->getSpreadsheet()->createCursorByRange(xSheetRange), ::uno::UNO_QUERY_THROW );
if( !bIsRowChanged )
nRowSize = xColumnRowRange->getRows()->getCount();
if( !bIsColumnChanged )
nColumnSize = xColumnRowRange->getColumns()->getCount();
xCursor->collapseToSize( nColumnSize, nRowSize );
uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xCursor, ::uno::UNO_QUERY_THROW );
uno::Reference< table::XCellRange > xRange( xSheetRange->getSpreadsheet(), ::uno::UNO_QUERY_THROW );
return new ScVbaRange( mxParent, mxContext,xRange->getCellRangeByPosition(
xCellRangeAddressable->getRangeAddress().StartColumn,
xCellRangeAddressable->getRangeAddress().StartRow,
xCellRangeAddressable->getRangeAddress().EndColumn,
xCellRangeAddressable->getRangeAddress().EndRow ) );
}
void
ScVbaRange::setWrapText( const uno::Any& aIsWrapped ) throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
uno::Any aResult;
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->setWrapText( aIsWrapped );
}
return;
}
uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY_THROW );
bool bIsWrapped = extractBoolFromAny( aIsWrapped );
xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTextWrapped" ) ), uno::Any( bIsWrapped ) );
}
uno::Any
ScVbaRange::getWrapText() throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
uno::Any aResult;
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
if ( index > 1 )
if ( aResult != xRange->getWrapText() )
return aNULL();
aResult = xRange->getWrapText();
}
return aResult;
}
SfxItemSet* pDataSet = getCurrentDataSet();
SfxItemState eState = pDataSet->GetItemState( ATTR_LINEBREAK, true, NULL);
if ( eState == SFX_ITEM_DONTCARE )
return aNULL();
uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY_THROW );
uno::Any aValue = xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTextWrapped" ) ) );
return aValue;
}
uno::Reference< excel::XInterior > ScVbaRange::Interior( ) throw ( script::BasicErrorException, uno::RuntimeException)
{
uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW );
return new ScVbaInterior ( this, mxContext, xProps, getScDocument() );
}
uno::Reference< excel::XRange >
ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2 ) throw (uno::RuntimeException)
{
return Range( Cell1, Cell2, false );
}
uno::Reference< excel::XRange >
ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2, bool bForceUseInpuRangeTab ) throw (uno::RuntimeException)
{
uno::Reference< table::XCellRange > xCellRange = mxRange;
if ( m_Areas->getCount() > 1 )
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
}
else
xCellRange.set( mxRange );
RangeHelper thisRange( xCellRange );
uno::Reference< table::XCellRange > xRanges = thisRange.getCellRangeFromSheet();
uno::Reference< sheet::XCellRangeAddressable > xAddressable( xRanges, uno::UNO_QUERY_THROW );
uno::Reference< table::XCellRange > xReferrer =
xRanges->getCellRangeByPosition( getColumn()-1, getRow()-1,
xAddressable->getRangeAddress().EndColumn,
xAddressable->getRangeAddress().EndRow );
// xAddressable now for this range
xAddressable.set( xReferrer, uno::UNO_QUERY_THROW );
if( !Cell1.hasValue() )
throw uno::RuntimeException(
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " Invalid Argument " ) ),
uno::Reference< XInterface >() );
table::CellRangeAddress resultAddress;
table::CellRangeAddress parentRangeAddress = xAddressable->getRangeAddress();
ScRange aRange;
// Cell1 defined only
if ( !Cell2.hasValue() )
{
rtl::OUString sName;
Cell1 >>= sName;
RangeHelper referRange( xReferrer );
table::CellRangeAddress referAddress = referRange.getCellRangeAddressable()->getRangeAddress();
return getRangeForName( mxContext, sName, getScDocShell(), referAddress );
}
else
{
table::CellRangeAddress cell1, cell2;
cell1 = getCellRangeAddressForVBARange( Cell1, getScDocShell() );
// Cell1 & Cell2 defined
// Excel seems to combine the range as the range defined by
// the combination of Cell1 & Cell2
cell2 = getCellRangeAddressForVBARange( Cell2, getScDocShell() );
resultAddress.StartColumn = ( cell1.StartColumn < cell2.StartColumn ) ? cell1.StartColumn : cell2.StartColumn;
resultAddress.StartRow = ( cell1.StartRow < cell2.StartRow ) ? cell1.StartRow : cell2.StartRow;
resultAddress.EndColumn = ( cell1.EndColumn > cell2.EndColumn ) ? cell1.EndColumn : cell2.EndColumn;
resultAddress.EndRow = ( cell1.EndRow > cell2.EndRow ) ? cell1.EndRow : cell2.EndRow;
if ( bForceUseInpuRangeTab )
{
// this is a call from Application.Range( x,y )
// its possiblefor x or y to specify a different sheet from
// the current or active on ( but they must be the same )
if ( cell1.Sheet != cell2.Sheet )
throw uno::RuntimeException();
parentRangeAddress.Sheet = cell1.Sheet;
}
else
{
// this is not a call from Application.Range( x,y )
// if a different sheet from this range is specified it's
// an error
if ( parentRangeAddress.Sheet != cell1.Sheet
|| parentRangeAddress.Sheet != cell2.Sheet
)
throw uno::RuntimeException();
}
ScUnoConversion::FillScRange( aRange, resultAddress );
}
ScRange parentAddress;
ScUnoConversion::FillScRange( parentAddress, parentRangeAddress);
if ( aRange.aStart.Col() >= 0 && aRange.aStart.Row() >= 0 && aRange.aEnd.Col() >= 0 && aRange.aEnd.Row() >= 0 )
{
sal_Int32 nStartX = parentAddress.aStart.Col() + aRange.aStart.Col();
sal_Int32 nStartY = parentAddress.aStart.Row() + aRange.aStart.Row();
sal_Int32 nEndX = parentAddress.aStart.Col() + aRange.aEnd.Col();
sal_Int32 nEndY = parentAddress.aStart.Row() + aRange.aEnd.Row();
if ( nStartX <= nEndX && nEndX <= parentAddress.aEnd.Col() &&
nStartY <= nEndY && nEndY <= parentAddress.aEnd.Row() )
{
ScRange aNew( (SCCOL)nStartX, (SCROW)nStartY, parentAddress.aStart.Tab(),
(SCCOL)nEndX, (SCROW)nEndY, parentAddress.aEnd.Tab() );
xCellRange = new ScCellRangeObj( getScDocShell(), aNew );
}
}
return new ScVbaRange( mxParent, mxContext, xCellRange );
}
// Allow access to underlying openoffice uno api ( useful for debugging
// with openoffice basic )
uno::Any SAL_CALL ScVbaRange::getCellRange( ) throw (uno::RuntimeException)
{
uno::Any aAny;
if ( mxRanges.is() )
aAny <<= mxRanges;
else if ( mxRange.is() )
aAny <<= mxRange;
return aAny;
}
uno::Any ScVbaRange::getCellRange( const uno::Reference< excel::XRange >& rxRange ) throw (uno::RuntimeException)
{
if( ScVbaRange* pVbaRange = getImplementation( rxRange ) )
return pVbaRange->getCellRange();
throw uno::RuntimeException();
}
static sal_uInt16
getPasteFlags (sal_Int32 Paste)
{
sal_uInt16 nFlags = IDF_NONE;
switch (Paste) {
case excel::XlPasteType::xlPasteComments:
nFlags = IDF_NOTE;break;
case excel::XlPasteType::xlPasteFormats:
nFlags = IDF_ATTRIB;break;
case excel::XlPasteType::xlPasteFormulas:
nFlags = IDF_FORMULA;break;
case excel::XlPasteType::xlPasteFormulasAndNumberFormats :
case excel::XlPasteType::xlPasteValues:
#ifdef VBA_OOBUILD_HACK
nFlags = ( IDF_VALUE | IDF_DATETIME | IDF_STRING | IDF_SPECIAL_BOOLEAN ); break;
#else
nFlags = ( IDF_VALUE | IDF_DATETIME | IDF_STRING ); break;
#endif
case excel::XlPasteType::xlPasteValuesAndNumberFormats:
nFlags = IDF_VALUE | IDF_ATTRIB; break;
case excel::XlPasteType::xlPasteColumnWidths:
case excel::XlPasteType::xlPasteValidation:
nFlags = IDF_NONE;break;
case excel::XlPasteType::xlPasteAll:
case excel::XlPasteType::xlPasteAllExceptBorders:
default:
nFlags = IDF_ALL;break;
};
return nFlags;
}
static sal_uInt16
getPasteFormulaBits( sal_Int32 Operation)
{
sal_uInt16 nFormulaBits = PASTE_NOFUNC ;
switch (Operation)
{
case excel::XlPasteSpecialOperation::xlPasteSpecialOperationAdd:
nFormulaBits = PASTE_ADD;break;
case excel::XlPasteSpecialOperation::xlPasteSpecialOperationSubtract:
nFormulaBits = PASTE_SUB;break;
case excel::XlPasteSpecialOperation::xlPasteSpecialOperationMultiply:
nFormulaBits = PASTE_MUL;break;
case excel::XlPasteSpecialOperation::xlPasteSpecialOperationDivide:
nFormulaBits = PASTE_DIV;break;
case excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone:
default:
nFormulaBits = PASTE_NOFUNC; break;
};
return nFormulaBits;
}
void SAL_CALL
ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, const uno::Any& SkipBlanks, const uno::Any& Transpose ) throw (::com::sun::star::uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() );
ScDocShell* pShell = getScDocShell();
uno::Reference< frame::XModel > xModel( ( pShell ? pShell->GetModel() : NULL ), uno::UNO_QUERY_THROW );
uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
// select this range
xSelection->select( uno::makeAny( mxRange ) );
// set up defaults
sal_Int32 nPaste = excel::XlPasteType::xlPasteAll;
sal_Int32 nOperation = excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone;
sal_Bool bTranspose = false;
sal_Bool bSkipBlanks = false;
if ( Paste.hasValue() )
Paste >>= nPaste;
if ( Operation.hasValue() )
Operation >>= nOperation;
if ( SkipBlanks.hasValue() )
SkipBlanks >>= bSkipBlanks;
if ( Transpose.hasValue() )
Transpose >>= bTranspose;
sal_uInt16 nFlags = getPasteFlags(nPaste);
sal_uInt16 nFormulaBits = getPasteFormulaBits(nOperation);
excel::implnPasteSpecial(pShell->GetModel(), nFlags,nFormulaBits,bSkipBlanks,bTranspose);
}
uno::Reference< excel::XRange >
ScVbaRange::getEntireColumnOrRow( bool bColumn ) throw (uno::RuntimeException)
{
ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
// copy the range list
ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
for ( size_t i = 0, nRanges = aCellRanges.size(); i < nRanges; ++i )
{
ScRange* pRange = aCellRanges[ i ];
if ( bColumn )
{
pRange->aStart.SetRow( 0 );
pRange->aEnd.SetRow( MAXROW );
}
else
{
pRange->aStart.SetCol( 0 );
pRange->aEnd.SetCol( MAXCOL );
}
}
if ( aCellRanges.size() > 1 ) // Multi-Area
{
uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pUnoRangesBase->GetDocShell(), aCellRanges ) );
return new ScVbaRange( mxParent, mxContext, xRanges, !bColumn, bColumn );
}
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), *aCellRanges.front() ) );
return new ScVbaRange( mxParent, mxContext, xRange, !bColumn, bColumn );
}
uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::getEntireRow() throw (uno::RuntimeException)
{
return getEntireColumnOrRow(false);
}
uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::getEntireColumn() throw (uno::RuntimeException)
{
return getEntireColumnOrRow();
}
uno::Reference< excel::XComment > SAL_CALL
ScVbaRange::AddComment( const uno::Any& Text ) throw (uno::RuntimeException)
{
// if there is already a comment in the top-left cell then throw
if( getComment().is() )
throw uno::RuntimeException();
// workaround: Excel allows to create empty comment, Calc does not
::rtl::OUString aNoteText;
if( Text.hasValue() && !(Text >>= aNoteText) )
throw uno::RuntimeException();
if( aNoteText.getLength() == 0 )
aNoteText = ::rtl::OUString( sal_Unicode( ' ' ) );
// try to create a new annotation
table::CellRangeAddress aRangePos = lclGetRangeAddress( mxRange );
table::CellAddress aNotePos( aRangePos.Sheet, aRangePos.StartColumn, aRangePos.StartRow );
uno::Reference< sheet::XSheetCellRange > xCellRange( mxRange, uno::UNO_QUERY_THROW );
uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xCellRange->getSpreadsheet(), uno::UNO_QUERY_THROW );
uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_SET_THROW );
xAnnos->insertNew( aNotePos, aNoteText );
return new ScVbaComment( this, mxContext, getUnoModel(), mxRange );
}
uno::Reference< excel::XComment > SAL_CALL
ScVbaRange::getComment() throw (uno::RuntimeException)
{
// intentional behavior to return a null object if no
// comment defined
uno::Reference< excel::XComment > xComment( new ScVbaComment( this, mxContext, getUnoModel(), mxRange ) );
if ( !xComment->Text( uno::Any(), uno::Any(), uno::Any() ).getLength() )
return NULL;
return xComment;
}
uno::Reference< beans::XPropertySet >
getRowOrColumnProps( const uno::Reference< table::XCellRange >& xCellRange, bool bRows ) throw ( uno::RuntimeException )
{
uno::Reference< table::XColumnRowRange > xColRow( xCellRange, uno::UNO_QUERY_THROW );
uno::Reference< beans::XPropertySet > xProps;
if ( bRows )
xProps.set( xColRow->getRows(), uno::UNO_QUERY_THROW );
else
xProps.set( xColRow->getColumns(), uno::UNO_QUERY_THROW );
return xProps;
}
uno::Any SAL_CALL
ScVbaRange::getHidden() throw (uno::RuntimeException)
{
// if multi-area result is the result of the
// first area
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(sal_Int32(1)), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->getHidden();
}
bool bIsVisible = false;
try
{
uno::Reference< beans::XPropertySet > xProps = getRowOrColumnProps( mxRange, mbIsRows );
if ( !( xProps->getPropertyValue( ISVISIBLE ) >>= bIsVisible ) )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to get IsVisible property")), uno::Reference< uno::XInterface >() );
}
catch( const uno::Exception& e )
{
throw uno::RuntimeException( e.Message, uno::Reference< uno::XInterface >() );
}
return uno::makeAny( !bIsVisible );
}
void SAL_CALL
ScVbaRange::setHidden( const uno::Any& _hidden ) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->setHidden( _hidden );
}
return;
}
bool bHidden = extractBoolFromAny( _hidden );
try
{
uno::Reference< beans::XPropertySet > xProps = getRowOrColumnProps( mxRange, mbIsRows );
xProps->setPropertyValue( ISVISIBLE, uno::Any( !bHidden ) );
}
catch( const uno::Exception& e )
{
throw uno::RuntimeException( e.Message, uno::Reference< uno::XInterface >() );
}
}
::sal_Bool SAL_CALL
ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replacement, const uno::Any& LookAt, const uno::Any& SearchOrder, const uno::Any& MatchCase, const uno::Any& MatchByte, const uno::Any& SearchFormat, const uno::Any& ReplaceFormat ) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
for ( sal_Int32 index = 1; index <= m_Areas->getCount(); ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->Replace( What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat );
}
return sal_True; // seems to return true always ( or at least I haven't found the trick of
}
// sanity check required params
if ( !What.getLength() )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, missing params" )) , uno::Reference< uno::XInterface >() );
rtl::OUString sWhat = VBAToRegexp( What);
// #TODO #FIXME SearchFormat & ReplacesFormat are not processed
// What do we do about MatchByte.. we don't seem to support that
const SvxSearchItem& globalSearchOptions = ScGlobal::GetSearchItem();
SvxSearchItem newOptions( globalSearchOptions );
sal_Int16 nLook = globalSearchOptions.GetWordOnly() ? excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole;
sal_Int16 nSearchOrder = globalSearchOptions.GetRowDirection() ? excel::XlSearchOrder::xlByRows : excel::XlSearchOrder::xlByColumns;
sal_Bool bMatchCase = false;
uno::Reference< util::XReplaceable > xReplace( mxRange, uno::UNO_QUERY );
if ( xReplace.is() )
{
uno::Reference< util::XReplaceDescriptor > xDescriptor =
xReplace->createReplaceDescriptor();
xDescriptor->setSearchString( sWhat);
xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHREGEXP ) ), uno::makeAny( sal_True ) );
xDescriptor->setReplaceString( Replacement);
if ( LookAt.hasValue() )
{
// sets SearchWords ( true is Cell match )
nLook = ::comphelper::getINT16( LookAt );
sal_Bool bSearchWords = false;
if ( nLook == excel::XlLookAt::xlPart )
bSearchWords = false;
else if ( nLook == excel::XlLookAt::xlWhole )
bSearchWords = sal_True;
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for LookAt" )) , uno::Reference< uno::XInterface >() );
// set global search props ( affects the find dialog
// and of course the defaults for this method
newOptions.SetWordOnly( bSearchWords );
xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHWORDS ) ), uno::makeAny( bSearchWords ) );
}
// sets SearchByRow ( true for Rows )
if ( SearchOrder.hasValue() )
{
nSearchOrder = ::comphelper::getINT16( SearchOrder );
sal_Bool bSearchByRow = false;
if ( nSearchOrder == excel::XlSearchOrder::xlByColumns )
bSearchByRow = false;
else if ( nSearchOrder == excel::XlSearchOrder::xlByRows )
bSearchByRow = sal_True;
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for SearchOrder" )) , uno::Reference< uno::XInterface >() );
newOptions.SetRowDirection( bSearchByRow );
xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHBYROW ) ), uno::makeAny( bSearchByRow ) );
}
if ( MatchCase.hasValue() )
{
// SearchCaseSensitive
MatchCase >>= bMatchCase;
xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHCASE ) ), uno::makeAny( bMatchCase ) );
}
ScGlobal::SetSearchItem( newOptions );
// ignore MatchByte for the moment, its not supported in
// OOo.org afaik
uno::Reference< util::XSearchDescriptor > xSearch( xDescriptor, uno::UNO_QUERY );
// Find all cells that being replaced, used to fire the range changed event.
uno::Reference< container::XIndexAccess > xIndexAccess = xReplace->findAll( xSearch );
xReplace->replaceAll( xSearch );
if ( xIndexAccess.is() && xIndexAccess->getCount() > 0 )
{
// Fires the range change event.
ScCellRangesBase* pScCellRangesBase = ScCellRangesBase::getImplementation( xIndexAccess );
lcl_NotifyRangeChanges( getScDocShell()->GetModel(), pScCellRangesBase ); // the original convert method will fail in SUSE
}
}
return sal_True; // always
}
uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& LookIn, const uno::Any& LookAt, const uno::Any& SearchOrder, const uno::Any& SearchDirection, const uno::Any& MatchCase, const uno::Any& /*MatchByte*/, const uno::Any& /*SearchFormat*/ ) throw (uno::RuntimeException)
{
// return a Range object that represents the first cell where that information is found.
rtl::OUString sWhat;
sal_Int32 nWhat = 0;
double fWhat = 0.0;
// string.
if( What >>= sWhat )
{
if( !sWhat.getLength() )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Find, missing params" )) , uno::Reference< uno::XInterface >() );
}
else if( What >>= nWhat )
{
sWhat = rtl::OUString::valueOf( nWhat );
}
else if( What >>= fWhat )
{
sWhat = rtl::OUString::valueOf( fWhat );
}
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Find, missing params" )) , uno::Reference< uno::XInterface >() );
rtl::OUString sSearch = VBAToRegexp( sWhat );
const SvxSearchItem& globalSearchOptions = ScGlobal::GetSearchItem();
SvxSearchItem newOptions( globalSearchOptions );
sal_Int16 nLookAt = globalSearchOptions.GetWordOnly() ? excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole;
sal_Int16 nSearchOrder = globalSearchOptions.GetRowDirection() ? excel::XlSearchOrder::xlByRows : excel::XlSearchOrder::xlByColumns;
uno::Reference< util::XSearchable > xSearch( mxRange, uno::UNO_QUERY );
if( xSearch.is() )
{
uno::Reference< util::XSearchDescriptor > xDescriptor = xSearch->createSearchDescriptor();
xDescriptor->setSearchString( sSearch );
xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHREGEXP ) ), uno::Any( true ) );
uno::Reference< excel::XRange > xAfterRange;
uno::Reference< table::XCellRange > xStartCell;
if( After >>= xAfterRange )
{
// After must be a single cell in the range
if( xAfterRange->getCount() > 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("After must be a single cell." )) , uno::Reference< uno::XInterface >() );
uno::Reference< excel::XRange > xCell( Cells( uno::makeAny( xAfterRange->getRow() ), uno::makeAny( xAfterRange->getColumn() ) ), uno::UNO_QUERY );
if( !xCell.is() )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("After must be in range." )) , uno::Reference< uno::XInterface >() );
xStartCell.set( xAfterRange->getCellRange(), uno::UNO_QUERY_THROW );
}
// LookIn
if( LookIn.hasValue() )
{
sal_Int32 nLookIn = 0;
if( LookIn >>= nLookIn )
{
sal_Int16 nSearchType = 0;
switch( nLookIn )
{
case excel::XlFindLookIn::xlComments :
nSearchType = SVX_SEARCHIN_NOTE; // Notes
break;
case excel::XlFindLookIn::xlFormulas :
nSearchType = SVX_SEARCHIN_FORMULA;
break;
case excel::XlFindLookIn::xlValues :
nSearchType = SVX_SEARCHIN_VALUE;
break;
default:
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for LookIn." )) , uno::Reference< uno::XInterface >() );
}
newOptions.SetCellType( nSearchType );
xDescriptor->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "SearchType" )), uno::makeAny( nSearchType ) );
}
}
// LookAt
if ( LookAt.hasValue() )
{
nLookAt = ::comphelper::getINT16( LookAt );
sal_Bool bSearchWords = false;
if ( nLookAt == excel::XlLookAt::xlPart )
bSearchWords = false;
else if ( nLookAt == excel::XlLookAt::xlWhole )
bSearchWords = sal_True;
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for LookAt" )) , uno::Reference< uno::XInterface >() );
newOptions.SetWordOnly( bSearchWords );
xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHWORDS ) ), uno::makeAny( bSearchWords ) );
}
// SearchOrder
if ( SearchOrder.hasValue() )
{
nSearchOrder = ::comphelper::getINT16( SearchOrder );
sal_Bool bSearchByRow = false;
if ( nSearchOrder == excel::XlSearchOrder::xlByColumns )
bSearchByRow = false;
else if ( nSearchOrder == excel::XlSearchOrder::xlByRows )
bSearchByRow = sal_True;
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for SearchOrder" )) , uno::Reference< uno::XInterface >() );
newOptions.SetRowDirection( bSearchByRow );
xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHBYROW ) ), uno::makeAny( bSearchByRow ) );
}
// SearchDirection
if ( SearchDirection.hasValue() )
{
sal_Int32 nSearchDirection = 0;
if( SearchDirection >>= nSearchDirection )
{
sal_Bool bSearchBackwards = false;
if ( nSearchDirection == excel::XlSearchDirection::xlNext )
bSearchBackwards = false;
else if( nSearchDirection == excel::XlSearchDirection::xlPrevious )
bSearchBackwards = sal_True;
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for SearchDirection" )) , uno::Reference< uno::XInterface >() );
newOptions.SetBackward( bSearchBackwards );
xDescriptor->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "SearchBackwards" )), uno::makeAny( bSearchBackwards ) );
}
}
// MatchCase
sal_Bool bMatchCase = false;
if ( MatchCase.hasValue() )
{
// SearchCaseSensitive
if( !( MatchCase >>= bMatchCase ) )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for MatchCase" )) , uno::Reference< uno::XInterface >() );
}
xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHCASE ) ), uno::makeAny( bMatchCase ) );
// MatchByte
// SearchFormat
// ignore
ScGlobal::SetSearchItem( newOptions );
uno::Reference< uno::XInterface > xInterface = xStartCell.is() ? xSearch->findNext( xStartCell, xDescriptor) : xSearch->findFirst( xDescriptor );
uno::Reference< table::XCellRange > xCellRange( xInterface, uno::UNO_QUERY );
// if we are searching from a starting cell and failed to find a match
// then try from the begining
if ( !xCellRange.is() && xStartCell.is() )
{
xInterface = xSearch->findFirst( xDescriptor );
xCellRange.set( xInterface, uno::UNO_QUERY );
}
if ( xCellRange.is() )
{
uno::Reference< excel::XRange > xResultRange = new ScVbaRange( mxParent, mxContext, xCellRange );
if( xResultRange.is() )
{
xResultRange->Select();
return xResultRange;
}
}
}
return uno::Reference< excel::XRange >();
}
uno::Reference< table::XCellRange > processKey( const uno::Any& Key, uno::Reference< uno::XComponentContext >& xContext, ScDocShell* pDocSh )
{
uno::Reference< excel::XRange > xKeyRange;
if ( Key.getValueType() == excel::XRange::static_type() )
{
xKeyRange.set( Key, uno::UNO_QUERY_THROW );
}
else if ( Key.getValueType() == ::getCppuType( static_cast< const rtl::OUString* >(0) ) )
{
rtl::OUString sRangeName = ::comphelper::getString( Key );
table::CellRangeAddress aRefAddr;
if ( !pDocSh )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort no docshell to calculate key param")), uno::Reference< uno::XInterface >() );
xKeyRange = getRangeForName( xContext, sRangeName, pDocSh, aRefAddr );
}
else
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort illegal type value for key param")), uno::Reference< uno::XInterface >() );
uno::Reference< table::XCellRange > xKey;
xKey.set( xKeyRange->getCellRange(), uno::UNO_QUERY_THROW );
return xKey;
}
// helper method for Sort
sal_Int32 findSortPropertyIndex( const uno::Sequence< beans::PropertyValue >& props,
const rtl::OUString& sPropName ) throw( uno::RuntimeException )
{
const beans::PropertyValue* pProp = props.getConstArray();
sal_Int32 nItems = props.getLength();
sal_Int32 count=0;
for ( ; count < nItems; ++count, ++pProp )
if ( pProp->Name.equals( sPropName ) )
return count;
if ( count == nItems )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort unknown sort property")), uno::Reference< uno::XInterface >() );
return -1; //should never reach here ( satisfy compiler )
}
// helper method for Sort
void updateTableSortField( const uno::Reference< table::XCellRange >& xParentRange,
const uno::Reference< table::XCellRange >& xColRowKey, sal_Int16 nOrder,
table::TableSortField& aTableField, sal_Bool bIsSortColumn, sal_Bool bMatchCase ) throw ( uno::RuntimeException )
{
RangeHelper parentRange( xParentRange );
RangeHelper colRowRange( xColRowKey );
table::CellRangeAddress parentRangeAddress = parentRange.getCellRangeAddressable()->getRangeAddress();
table::CellRangeAddress colRowKeyAddress = colRowRange.getCellRangeAddressable()->getRangeAddress();
// make sure that upper left poing of key range is within the
// parent range
if ( ( !bIsSortColumn && colRowKeyAddress.StartColumn >= parentRangeAddress.StartColumn &&
colRowKeyAddress.StartColumn <= parentRangeAddress.EndColumn ) || ( bIsSortColumn &&
colRowKeyAddress.StartRow >= parentRangeAddress.StartRow &&
colRowKeyAddress.StartRow <= parentRangeAddress.EndRow ) )
{
//determine col/row index
if ( bIsSortColumn )
aTableField.Field = colRowKeyAddress.StartRow - parentRangeAddress.StartRow;
else
aTableField.Field = colRowKeyAddress.StartColumn - parentRangeAddress.StartColumn;
aTableField.IsCaseSensitive = bMatchCase;
if ( nOrder == excel::XlSortOrder::xlAscending )
aTableField.IsAscending = sal_True;
else
aTableField.IsAscending = false;
}
else
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal Key param" ) ), uno::Reference< uno::XInterface >() );
}
void SAL_CALL
ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any& Key2, const uno::Any& /*Type*/, const uno::Any& Order2, const uno::Any& Key3, const uno::Any& Order3, const uno::Any& Header, const uno::Any& OrderCustom, const uno::Any& MatchCase, const uno::Any& Orientation, const uno::Any& SortMethod, const uno::Any& DataOption1, const uno::Any& DataOption2, const uno::Any& DataOption3 ) throw (uno::RuntimeException)
{
// #TODO# #FIXME# can we do something with Type
if ( m_Areas->getCount() > 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() );
sal_Int16 nDataOption1 = excel::XlSortDataOption::xlSortNormal;
sal_Int16 nDataOption2 = excel::XlSortDataOption::xlSortNormal;
sal_Int16 nDataOption3 = excel::XlSortDataOption::xlSortNormal;
ScDocument* pDoc = getScDocument();
if ( !pDoc )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() );
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
ScSortParam aSortParam;
SCTAB nTab = thisRangeAddress.Sheet;
pDoc->GetSortParam( aSortParam, nTab );
if ( DataOption1.hasValue() )
DataOption1 >>= nDataOption1;
if ( DataOption2.hasValue() )
DataOption2 >>= nDataOption2;
if ( DataOption3.hasValue() )
DataOption3 >>= nDataOption3;
// 1) #TODO #FIXME need to process DataOption[1..3] not used currently
// 2) #TODO #FIXME need to refactor this ( below ) into a IsSingleCell() method
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
// set up defaults
sal_Int16 nOrder1 = aSortParam.bAscending[0] ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
sal_Int16 nOrder2 = aSortParam.bAscending[1] ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
sal_Int16 nOrder3 = aSortParam.bAscending[2] ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
sal_Int16 nCustom = aSortParam.nUserIndex;
sal_Int16 nSortMethod = excel::XlSortMethod::xlPinYin;
sal_Bool bMatchCase = aSortParam.bCaseSens;
// seems to work opposite to expected, see below
sal_Int16 nOrientation = aSortParam.bByRow ? excel::XlSortOrientation::xlSortColumns : excel::XlSortOrientation::xlSortRows;
if ( Orientation.hasValue() )
{
// Documentation says xlSortRows is default but that doesn't appear to be
// the case. Also it appears that xlSortColumns is the default which
// strangely enought sorts by Row
nOrientation = ::comphelper::getINT16( Orientation );
// persist new option to be next calls default
if ( nOrientation == excel::XlSortOrientation::xlSortRows )
aSortParam.bByRow = false;
else
aSortParam.bByRow = sal_True;
}
sal_Bool bIsSortColumns=false; // sort by row
if ( nOrientation == excel::XlSortOrientation::xlSortRows )
bIsSortColumns = sal_True;
sal_Int16 nHeader = 0;
#ifdef VBA_OOBUILD_HACK
nHeader = aSortParam.nCompatHeader;
#endif
sal_Bool bContainsHeader = false;
if ( Header.hasValue() )
{
nHeader = ::comphelper::getINT16( Header );
#ifdef VBA_OOBUILD_HACK
aSortParam.nCompatHeader = nHeader;
#endif
}
if ( nHeader == excel::XlYesNoGuess::xlGuess )
{
bool bHasColHeader = pDoc->HasColHeader( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), static_cast< SCCOL >( thisRangeAddress.EndColumn ), static_cast< SCROW >( thisRangeAddress.EndRow ), static_cast< SCTAB >( thisRangeAddress.Sheet ));
bool bHasRowHeader = pDoc->HasRowHeader( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), static_cast< SCCOL >( thisRangeAddress.EndColumn ), static_cast< SCROW >( thisRangeAddress.EndRow ), static_cast< SCTAB >( thisRangeAddress.Sheet ) );
if ( bHasColHeader || bHasRowHeader )
nHeader = excel::XlYesNoGuess::xlYes;
else
nHeader = excel::XlYesNoGuess::xlNo;
#ifdef VBA_OOBUILD_HACK
aSortParam.nCompatHeader = nHeader;
#endif
}
if ( nHeader == excel::XlYesNoGuess::xlYes )
bContainsHeader = sal_True;
if ( SortMethod.hasValue() )
{
nSortMethod = ::comphelper::getINT16( SortMethod );
}
if ( OrderCustom.hasValue() )
{
OrderCustom >>= nCustom;
--nCustom; // 0-based in OOo
aSortParam.nUserIndex = nCustom;
}
if ( MatchCase.hasValue() )
{
MatchCase >>= bMatchCase;
aSortParam.bCaseSens = bMatchCase;
}
if ( Order1.hasValue() )
{
nOrder1 = ::comphelper::getINT16(Order1);
if ( nOrder1 == excel::XlSortOrder::xlAscending )
aSortParam.bAscending[0] = true;
else
aSortParam.bAscending[0] = false;
}
if ( Order2.hasValue() )
{
nOrder2 = ::comphelper::getINT16(Order2);
if ( nOrder2 == excel::XlSortOrder::xlAscending )
aSortParam.bAscending[1] = true;
else
aSortParam.bAscending[1] = false;
}
if ( Order3.hasValue() )
{
nOrder3 = ::comphelper::getINT16(Order3);
if ( nOrder3 == excel::XlSortOrder::xlAscending )
aSortParam.bAscending[2] = true;
else
aSortParam.bAscending[2] = false;
}
uno::Reference< table::XCellRange > xKey1;
uno::Reference< table::XCellRange > xKey2;
uno::Reference< table::XCellRange > xKey3;
ScDocShell* pDocShell = getScDocShell();
xKey1 = processKey( Key1, mxContext, pDocShell );
if ( !xKey1.is() )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort needs a key1 param")), uno::Reference< uno::XInterface >() );
if ( Key2.hasValue() )
xKey2 = processKey( Key2, mxContext, pDocShell );
if ( Key3.hasValue() )
xKey3 = processKey( Key3, mxContext, pDocShell );
uno::Reference< util::XSortable > xSort( mxRange, uno::UNO_QUERY_THROW );
uno::Sequence< beans::PropertyValue > sortDescriptor = xSort->createSortDescriptor();
sal_Int32 nTableSortFieldIndex = findSortPropertyIndex( sortDescriptor, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SortFields") ) );
uno::Sequence< table::TableSortField > sTableFields(1);
sal_Int32 nTableIndex = 0;
updateTableSortField( mxRange, xKey1, nOrder1, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase );
if ( xKey2.is() )
{
sTableFields.realloc( sTableFields.getLength() + 1 );
updateTableSortField( mxRange, xKey2, nOrder2, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase );
}
if ( xKey3.is() )
{
sTableFields.realloc( sTableFields.getLength() + 1 );
updateTableSortField( mxRange, xKey3, nOrder3, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase );
}
sortDescriptor[ nTableSortFieldIndex ].Value <<= sTableFields;
sal_Int32 nIndex = findSortPropertyIndex( sortDescriptor, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsSortColumns")) );
sortDescriptor[ nIndex ].Value <<= bIsSortColumns;
nIndex = findSortPropertyIndex( sortDescriptor, CONTS_HEADER );
sortDescriptor[ nIndex ].Value <<= bContainsHeader;
pDoc->SetSortParam( aSortParam, nTab );
xSort->sort( sortDescriptor );
// #FIXME #TODO
// The SortMethod param is not processed ( not sure what its all about, need to
(void)nSortMethod;
}
uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::End( ::sal_Int32 Direction ) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
return xRange->End( Direction );
}
table::CellAddress aAddress = getLeftUpperCellAddress();
SCTAB nTab = aAddress.Sheet;
SCCOL nCurX = aAddress.Column;
SCROW nCurY = aAddress.Row;
SCCOL nNewX = nCurX;
SCROW nNewY = nCurY;
ScDocShell* pDocShell = getScDocShell();
ScDocument* pDoc = pDocShell->GetDocument();
SCsCOL nMoveX = 0;
SCsROW nMoveY = 0;
switch ( Direction )
{
case excel::XlDirection::xlDown:
nMoveY = 1;
break;
case excel::XlDirection::xlUp:
nMoveY = -1;
break;
case excel::XlDirection::xlToLeft:
nMoveX = -1;
break;
case excel::XlDirection::xlToRight:
nMoveX = 1;
break;
default:
throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid Direction" ) ), uno::Reference< uno::XInterface >() );
}
if ( pDoc )
{
pDoc->FindAreaPos( nNewX, nNewY, nTab, nMoveX, nMoveY );
}
ScRange aNewRange( (SCCOL)nNewX, (SCROW)nNewY, nTab, (SCCOL)nNewX, (SCROW)nNewY, nTab );
uno::Reference< table::XCellRange > xCellRange( new ScCellRangeObj( getScDocShell(), aNewRange ) );
uno::Reference< excel::XRange > xResultRange = new ScVbaRange( mxParent, mxContext, xCellRange );
return xResultRange;
}
bool
ScVbaRange::isSingleCellRange()
{
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY);
if ( xColumnRowRange.is() && xColumnRowRange->getRows()->getCount() == 1 && xColumnRowRange->getColumns()->getCount() == 1 )
return true;
return false;
}
uno::Reference< excel::XCharacters > SAL_CALL
ScVbaRange::characters( const uno::Any& Start, const uno::Any& Length ) throw (uno::RuntimeException)
{
if ( !isSingleCellRange() )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't create Characters property for multicell range ") ), uno::Reference< uno::XInterface >() );
uno::Reference< text::XSimpleText > xSimple(mxRange->getCellByPosition(0,0) , uno::UNO_QUERY_THROW );
ScDocument* pDoc = excel::GetDocumentFromRange(mxRange);
if ( !pDoc )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() );
ScVbaPalette aPalette( pDoc->GetDocumentShell() );
return new ScVbaCharacters( this, mxContext, aPalette, xSimple, Start, Length );
}
void SAL_CALL
ScVbaRange::Delete( const uno::Any& Shift ) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->Delete( Shift );
}
return;
}
sheet::CellDeleteMode mode = sheet::CellDeleteMode_NONE ;
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
if ( Shift.hasValue() )
{
sal_Int32 nShift = 0;
Shift >>= nShift;
switch ( nShift )
{
case excel::XlDeleteShiftDirection::xlShiftUp:
mode = sheet::CellDeleteMode_UP;
break;
case excel::XlDeleteShiftDirection::xlShiftToLeft:
mode = sheet::CellDeleteMode_LEFT;
break;
default:
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ("Illegal paramater ") ), uno::Reference< uno::XInterface >() );
}
}
else
{
bool bFullRow = ( thisAddress.StartColumn == 0 && thisAddress.EndColumn == MAXCOL );
sal_Int32 nCols = thisAddress.EndColumn - thisAddress.StartColumn;
sal_Int32 nRows = thisAddress.EndRow - thisAddress.StartRow;
if ( mbIsRows || bFullRow || ( nCols >= nRows ) )
mode = sheet::CellDeleteMode_UP;
else
mode = sheet::CellDeleteMode_LEFT;
}
uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
xCellRangeMove->removeRange( thisAddress, mode );
}
//XElementAccess
sal_Bool SAL_CALL
ScVbaRange::hasElements() throw (uno::RuntimeException)
{
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY );
if ( xColumnRowRange.is() )
if ( xColumnRowRange->getRows()->getCount() ||
xColumnRowRange->getColumns()->getCount() )
return sal_True;
return false;
}
// XEnumerationAccess
uno::Reference< container::XEnumeration > SAL_CALL
ScVbaRange::createEnumeration() throw (uno::RuntimeException)
{
if ( mbIsColumns || mbIsRows )
{
uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY );
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
sal_Int32 nElems = 0;
if ( mbIsColumns )
nElems = xColumnRowRange->getColumns()->getCount();
else
nElems = xColumnRowRange->getRows()->getCount();
return new ColumnsRowEnumeration( mxContext, xRange, nElems );
}
return new CellsEnumeration( mxParent, mxContext, m_Areas );
}
::rtl::OUString SAL_CALL
ScVbaRange::getDefaultMethodName( ) throw (uno::RuntimeException)
{
const static rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM("Item") );
return sName;
}
uno::Reference< awt::XDevice >
getDeviceFromDoc( const uno::Reference< frame::XModel >& xModel ) throw( uno::RuntimeException )
{
uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
uno::Reference< frame::XFrame> xFrame( xController->getFrame(), uno::UNO_QUERY_THROW );
uno::Reference< awt::XDevice > xDevice( xFrame->getComponentWindow(), uno::UNO_QUERY_THROW );
return xDevice;
}
// returns calc internal col. width ( in points )
double
ScVbaRange::getCalcColWidth( const table::CellRangeAddress& rAddress) throw (uno::RuntimeException)
{
ScDocument* pDoc = getScDocument();
sal_uInt16 nWidth = pDoc->GetOriginalWidth( static_cast< SCCOL >( rAddress.StartColumn ), static_cast< SCTAB >( rAddress.Sheet ) );
double nPoints = lcl_TwipsToPoints( nWidth );
nPoints = lcl_Round2DecPlaces( nPoints );
return nPoints;
}
double
ScVbaRange::getCalcRowHeight( const table::CellRangeAddress& rAddress ) throw (uno::RuntimeException)
{
ScDocument* pDoc = excel::GetDocumentFromRange( mxRange );
sal_uInt16 nWidth = pDoc->GetOriginalHeight( rAddress.StartRow, rAddress.Sheet );
double nPoints = lcl_TwipsToPoints( nWidth );
nPoints = lcl_Round2DecPlaces( nPoints );
return nPoints;
}
// return Char Width in points
double getDefaultCharWidth( const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException )
{
const static rtl::OUString sDflt( RTL_CONSTASCII_USTRINGPARAM("Default"));
const static rtl::OUString sCharFontName( RTL_CONSTASCII_USTRINGPARAM("CharFontName"));
const static rtl::OUString sPageStyles( RTL_CONSTASCII_USTRINGPARAM("PageStyles"));
// get the font from the default style
uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNameAccess( xStyleSupplier->getStyleFamilies(), uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNameAccess2( xNameAccess->getByName( sPageStyles ), uno::UNO_QUERY_THROW );
uno::Reference< beans::XPropertySet > xProps( xNameAccess2->getByName( sDflt ), uno::UNO_QUERY_THROW );
rtl::OUString sFontName;
xProps->getPropertyValue( sCharFontName ) >>= sFontName;
uno::Reference< awt::XDevice > xDevice = getDeviceFromDoc( xModel );
awt::FontDescriptor aDesc;
aDesc.Name = sFontName;
uno::Reference< awt::XFont > xFont( xDevice->getFont( aDesc ), uno::UNO_QUERY_THROW );
double nCharPixelWidth = xFont->getCharWidth( (sal_Int8)'0' );
double nPixelsPerMeter = xDevice->getInfo().PixelPerMeterX;
double nCharWidth = nCharPixelWidth / nPixelsPerMeter;
nCharWidth = nCharWidth * (double)56700;// in twips
return lcl_TwipsToPoints( (sal_uInt16)nCharWidth );
}
double getDefaultCharWidth( ScDocShell* pDocShell )
{
ScDocument* pDoc = pDocShell->GetDocument();
OutputDevice* pRefDevice = pDoc->GetRefDevice();
ScPatternAttr* pAttr = pDoc->GetDefPattern();
::Font aDefFont;
pAttr->GetFont( aDefFont, SC_AUTOCOL_BLACK, pRefDevice );
pRefDevice->SetFont( aDefFont );
long nCharWidth = pRefDevice->GetTextWidth( String( '0' ) ); // 1/100th mm
return lcl_hmmToPoints( nCharWidth );
}
uno::Any SAL_CALL
ScVbaRange::getColumnWidth() throw (uno::RuntimeException)
{
sal_Int32 nLen = m_Areas->getCount();
if ( nLen > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->getColumnWidth();
}
double nColWidth = 0;
ScDocShell* pShell = getScDocShell();
if ( pShell )
{
uno::Reference< frame::XModel > xModel = pShell->GetModel();
double defaultCharWidth = getDefaultCharWidth( xModel );
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
sal_Int32 nStartCol = thisAddress.StartColumn;
sal_Int32 nEndCol = thisAddress.EndColumn;
sal_uInt16 nColTwips = 0;
for( sal_Int32 nCol = nStartCol ; nCol <= nEndCol; ++nCol )
{
thisAddress.StartColumn = nCol;
sal_uInt16 nCurTwips = pShell->GetDocument()->GetOriginalWidth( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCTAB >( thisAddress.Sheet ) );
if ( nCol == nStartCol )
nColTwips = nCurTwips;
if ( nColTwips != nCurTwips )
return aNULL();
}
nColWidth = lcl_TwipsToPoints( nColTwips );
if ( nColWidth != 0.0 )
nColWidth = ( nColWidth / defaultCharWidth ) - fExtraWidth;
}
nColWidth = lcl_Round2DecPlaces( nColWidth );
return uno::makeAny( nColWidth );
}
void SAL_CALL
ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) throw (uno::RuntimeException)
{
sal_Int32 nLen = m_Areas->getCount();
if ( nLen > 1 )
{
for ( sal_Int32 index = 1; index != nLen; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(index) ), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->setColumnWidth( _columnwidth );
}
return;
}
double nColWidth = 0;
_columnwidth >>= nColWidth;
nColWidth = lcl_Round2DecPlaces( nColWidth );
ScDocShell* pDocShell = getScDocShell();
if ( pDocShell )
{
if ( nColWidth != 0.0 )
nColWidth = ( nColWidth + fExtraWidth ) * getDefaultCharWidth( pDocShell );
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
sal_uInt16 nTwips = lcl_pointsToTwips( nColWidth );
ScDocFunc aFunc(*pDocShell);
SCCOLROW nColArr[2];
nColArr[0] = thisAddress.StartColumn;
nColArr[1] = thisAddress.EndColumn;
// #163561# use mode SC_SIZE_DIRECT: hide for width 0, show for other values
aFunc.SetWidthOrHeight( true, 1, nColArr, thisAddress.Sheet,
SC_SIZE_DIRECT, nTwips, true, true );
}
}
uno::Any SAL_CALL
ScVbaRange::getWidth() throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->getWidth();
}
uno::Reference< table::XColumnRowRange > xColRowRange( mxRange, uno::UNO_QUERY_THROW );
uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getColumns(), uno::UNO_QUERY_THROW );
sal_Int32 nElems = xIndexAccess->getCount();
double nWidth = 0;
for ( sal_Int32 index=0; index<nElems; ++index )
{
uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
double nTmpWidth = getCalcColWidth( xAddressable->getRangeAddress() );
nWidth += nTmpWidth;
}
return uno::makeAny( nWidth );
}
uno::Any SAL_CALL
ScVbaRange::Areas( const uno::Any& item) throw (uno::RuntimeException)
{
if ( !item.hasValue() )
return uno::makeAny( m_Areas );
return m_Areas->Item( item, uno::Any() );
}
uno::Reference< excel::XRange >
ScVbaRange::getArea( sal_Int32 nIndex ) throw( css::uno::RuntimeException )
{
if ( !m_Areas.is() )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No areas available")), uno::Reference< uno::XInterface >() );
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( ++nIndex ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange;
}
uno::Any
ScVbaRange::Borders( const uno::Any& item ) throw( script::BasicErrorException, uno::RuntimeException )
{
if ( !item.hasValue() )
return uno::makeAny( getBorders() );
return getBorders()->Item( item, uno::Any() );
}
uno::Any SAL_CALL
ScVbaRange::BorderAround( const css::uno::Any& LineStyle, const css::uno::Any& Weight,
const css::uno::Any& ColorIndex, const css::uno::Any& Color ) throw (css::uno::RuntimeException)
{
sal_Int32 nCount = getBorders()->getCount();
for( sal_Int32 i = 0; i < nCount; i++ )
{
const sal_Int32 nLineType = supportedIndexTable[i];
switch( nLineType )
{
case excel::XlBordersIndex::xlEdgeLeft:
case excel::XlBordersIndex::xlEdgeTop:
case excel::XlBordersIndex::xlEdgeBottom:
case excel::XlBordersIndex::xlEdgeRight:
{
uno::Reference< excel::XBorder > xBorder( m_Borders->Item( uno::makeAny( nLineType ), uno::Any() ), uno::UNO_QUERY_THROW );
if( LineStyle.hasValue() )
{
xBorder->setLineStyle( LineStyle );
}
if( Weight.hasValue() )
{
xBorder->setWeight( Weight );
}
if( ColorIndex.hasValue() )
{
xBorder->setColorIndex( ColorIndex );
}
if( Color.hasValue() )
{
xBorder->setColor( Color );
}
break;
}
case excel::XlBordersIndex::xlInsideVertical:
case excel::XlBordersIndex::xlInsideHorizontal:
case excel::XlBordersIndex::xlDiagonalDown:
case excel::XlBordersIndex::xlDiagonalUp:
break;
default:
return uno::makeAny( false );
}
}
return uno::makeAny( sal_True );
}
uno::Any SAL_CALL
ScVbaRange::getRowHeight() throw (uno::RuntimeException)
{
sal_Int32 nLen = m_Areas->getCount();
if ( nLen > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->getRowHeight();
}
// if any row's RowHeight in the
// range is different from any other then return NULL
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
sal_Int32 nStartRow = thisAddress.StartRow;
sal_Int32 nEndRow = thisAddress.EndRow;
sal_uInt16 nRowTwips = 0;
// #TODO probably possible to use the SfxItemSet ( and see if
// SFX_ITEM_DONTCARE is set ) to improve performance
// #CHECKME looks like this is general behaviour not just row Range specific
// if ( mbIsRows )
ScDocShell* pShell = getScDocShell();
if ( pShell )
{
for ( sal_Int32 nRow = nStartRow ; nRow <= nEndRow; ++nRow )
{
thisAddress.StartRow = nRow;
sal_uInt16 nCurTwips = pShell->GetDocument()->GetOriginalHeight( thisAddress.StartRow, thisAddress.Sheet );
if ( nRow == nStartRow )
nRowTwips = nCurTwips;
if ( nRowTwips != nCurTwips )
return aNULL();
}
}
double nHeight = lcl_Round2DecPlaces( lcl_TwipsToPoints( nRowTwips ) );
return uno::makeAny( nHeight );
}
void SAL_CALL
ScVbaRange::setRowHeight( const uno::Any& _rowheight) throw (uno::RuntimeException)
{
sal_Int32 nLen = m_Areas->getCount();
if ( nLen > 1 )
{
for ( sal_Int32 index = 1; index != nLen; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(index) ), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->setRowHeight( _rowheight );
}
return;
}
double nHeight = 0; // Incomming height is in points
_rowheight >>= nHeight;
nHeight = lcl_Round2DecPlaces( nHeight );
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
sal_uInt16 nTwips = lcl_pointsToTwips( nHeight );
ScDocShell* pDocShell = excel::GetDocShellFromRange( mxRange );
ScDocFunc aFunc(*pDocShell);
SCCOLROW nRowArr[2];
nRowArr[0] = thisAddress.StartRow;
nRowArr[1] = thisAddress.EndRow;
aFunc.SetWidthOrHeight( false, 1, nRowArr, thisAddress.Sheet, SC_SIZE_ORIGINAL,
nTwips, true, true );
}
uno::Any SAL_CALL
ScVbaRange::getPageBreak() throw (uno::RuntimeException)
{
sal_Int32 nPageBreak = excel::XlPageBreak::xlPageBreakNone;
ScDocShell* pShell = excel::GetDocShellFromRange( mxRange );
if ( pShell )
{
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
sal_Bool bColumn = false;
if (thisAddress.StartRow==0)
bColumn = true;
uno::Reference< frame::XModel > xModel = pShell->GetModel();
if ( xModel.is() )
{
ScDocument* pDoc = excel::GetDocumentFromRange( mxRange );
ScBreakType nBreak = BREAK_NONE;
if ( !bColumn )
nBreak = pDoc->HasRowBreak(thisAddress.StartRow, thisAddress.Sheet);
else
nBreak = pDoc->HasColBreak(thisAddress.StartColumn, thisAddress.Sheet);
if (nBreak & BREAK_PAGE)
nPageBreak = excel::XlPageBreak::xlPageBreakAutomatic;
if (nBreak & BREAK_MANUAL)
nPageBreak = excel::XlPageBreak::xlPageBreakManual;
}
}
return uno::makeAny( nPageBreak );
}
void SAL_CALL
ScVbaRange::setPageBreak( const uno::Any& _pagebreak) throw (uno::RuntimeException)
{
sal_Int32 nPageBreak = 0;
_pagebreak >>= nPageBreak;
ScDocShell* pShell = excel::GetDocShellFromRange( mxRange );
if ( pShell )
{
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
if ((thisAddress.StartColumn==0) && (thisAddress.StartRow==0))
return;
sal_Bool bColumn = false;
if (thisAddress.StartRow==0)
bColumn = true;
ScAddress aAddr( static_cast<SCCOL>(thisAddress.StartColumn), thisAddress.StartRow, thisAddress.Sheet );
uno::Reference< frame::XModel > xModel = pShell->GetModel();
if ( xModel.is() )
{
ScTabViewShell* pViewShell = excel::getBestViewShell( xModel );
if ( nPageBreak == excel::XlPageBreak::xlPageBreakManual )
pViewShell->InsertPageBreak( bColumn, sal_True, &aAddr);
else if ( nPageBreak == excel::XlPageBreak::xlPageBreakNone )
pViewShell->DeletePageBreak( bColumn, sal_True, &aAddr);
}
}
}
uno::Any SAL_CALL
ScVbaRange::getHeight() throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->getHeight();
}
uno::Reference< table::XColumnRowRange > xColRowRange( mxRange, uno::UNO_QUERY_THROW );
uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getRows(), uno::UNO_QUERY_THROW );
sal_Int32 nElems = xIndexAccess->getCount();
double nHeight = 0;
for ( sal_Int32 index=0; index<nElems; ++index )
{
uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
nHeight += getCalcRowHeight(xAddressable->getRangeAddress() );
}
return uno::makeAny( nHeight );
}
awt::Point
ScVbaRange::getPosition() throw ( uno::RuntimeException )
{
awt::Point aPoint;
uno::Reference< beans::XPropertySet > xProps;
if ( mxRange.is() )
xProps.set( mxRange, uno::UNO_QUERY_THROW );
else
xProps.set( mxRanges, uno::UNO_QUERY_THROW );
xProps->getPropertyValue(POSITION) >>= aPoint;
return aPoint;
}
uno::Any SAL_CALL
ScVbaRange::getLeft() throw (uno::RuntimeException)
{
// helperapi returns the first ranges left ( and top below )
if ( m_Areas->getCount() > 1 )
return getArea( 0 )->getLeft();
awt::Point aPoint = getPosition();
return uno::makeAny( lcl_hmmToPoints( aPoint.X ) );
}
uno::Any SAL_CALL
ScVbaRange::getTop() throw (uno::RuntimeException)
{
// helperapi returns the first ranges top
if ( m_Areas->getCount() > 1 )
return getArea( 0 )->getTop();
awt::Point aPoint= getPosition();
return uno::makeAny( lcl_hmmToPoints( aPoint.Y ) );
}
uno::Reference< excel::XWorksheet >
ScVbaRange::getWorksheet() throw (uno::RuntimeException)
{
// #TODO #FIXME parent should always be set up ( currently thats not
// the case )
uno::Reference< excel::XWorksheet > xSheet( getParent(), uno::UNO_QUERY );
if ( !xSheet.is() )
{
uno::Reference< table::XCellRange > xRange = mxRange;
if ( mxRanges.is() ) // assign xRange to first range
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
xRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
}
ScDocShell* pDocShell = excel::GetDocShellFromRange(xRange);
RangeHelper rHelper(xRange);
// parent should be Thisworkbook
xSheet.set( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), mxContext,rHelper.getSpreadSheet(),pDocShell->GetModel()) );
}
return xSheet;
}
// #TODO remove this ugly application processing
// Process an application Range request e.g. 'Range("a1,b2,a4:b6")
uno::Reference< excel::XRange >
ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xContext, const css::uno::Any &Cell1, const css::uno::Any &Cell2 ) throw (css::uno::RuntimeException)
{
// Althought the documentation seems clear that Range without a
// qualifier then its a shortcut for ActiveSheet.Range
// however, similarly Application.Range is apparently also a
// shortcut for ActiveSheet.Range
// The is however a subtle behavioural difference I've come across
// wrt to named ranges.
// If a named range "test" exists { Sheet1!$A1 } and the active sheet
// is Sheet2 then the following will fail
// msgbox ActiveSheet.Range("test").Address ' failes
// msgbox WorkSheets("Sheet2").Range("test").Address
// but !!!
// msgbox Range("test").Address ' works
// msgbox Application.Range("test").Address ' works
// Single param Range
rtl::OUString sRangeName;
Cell1 >>= sRangeName;
if ( Cell1.hasValue() && !Cell2.hasValue() && sRangeName.getLength() )
{
const static rtl::OUString sNamedRanges( RTL_CONSTASCII_USTRINGPARAM("NamedRanges"));
uno::Reference< beans::XPropertySet > xPropSet( getCurrentExcelDoc(xContext), uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue( sNamedRanges ), uno::UNO_QUERY_THROW );
uno::Reference< sheet::XCellRangeReferrer > xReferrer;
try
{
xReferrer.set ( xNamed->getByName( sRangeName ), uno::UNO_QUERY );
}
catch( uno::Exception& /*e*/ )
{
// do nothing
}
if ( xReferrer.is() )
{
uno::Reference< table::XCellRange > xRange = xReferrer->getReferredCells();
if ( xRange.is() )
{
uno::Reference< excel::XRange > xVbRange = new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), xContext, xRange );
return xVbRange;
}
}
}
// Add these codes for supporting shortcut: Application.Range(Range1, Range2), Range1 or Range2 is not the range of current active sheet.
// If Range1 and Range2 are not in current active sheet, we should not use the active sheet, but use the sheet of Range1 and Range2.
// If Range1 and Range2 are not in the same sheet, we throw an exception.
uno::Reference< sheet::XSpreadsheet > xSpreadsheet;
uno::Reference< excel::XRange > xRange1( Cell1, uno::UNO_QUERY ), xRange2( Cell2, uno::UNO_QUERY );
if ( xRange1.is() )
{
RangeHelper thisRange( xRange1->getCellRange() );
xSpreadsheet = thisRange.getSpreadSheet();
}
else if ( xRange2.is() )
{
RangeHelper thisRange( xRange2->getCellRange() );
xSpreadsheet = thisRange.getSpreadSheet();
}
if ( !xSpreadsheet.is() )
{
uno::Reference< frame::XModel > xModel = getCurrentExcelDoc( xContext );
if ( xModel.is() )
{
uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
xSpreadsheet = xView->getActiveSheet();
}
}
uno::Reference< table::XCellRange > xSheetRange( xSpreadsheet, uno::UNO_QUERY_THROW );
ScVbaRange* pRange = new ScVbaRange( excel::getUnoSheetModuleObj( xSheetRange ), xContext, xSheetRange );
uno::Reference< excel::XRange > xVbSheetRange( pRange );
return pRange->Range( Cell1, Cell2, true );
}
// Helper functions for AutoFilter
ScDBData* lcl_GetDBData_Impl( ScDocShell* pDocShell, sal_Int16 nSheet )
{
ScDBData* pRet = NULL;
if (pDocShell)
{
pRet = pDocShell->GetDocument()->GetAnonymousDBData(nSheet);
}
return pRet;
}
void lcl_SelectAll( ScDocShell* pDocShell, ScQueryParam& aParam )
{
if ( pDocShell )
{
ScViewData* pViewData = pDocShell->GetViewData();
if ( pViewData )
{
OSL_TRACE("Pushing out SelectAll query");
pViewData->GetView()->Query( aParam, NULL, sal_True );
}
}
}
ScQueryParam lcl_GetQueryParam( ScDocShell* pDocShell, sal_Int16 nSheet )
{
ScDBData* pDBData = lcl_GetDBData_Impl( pDocShell, nSheet );
ScQueryParam aParam;
if (pDBData)
{
pDBData->GetQueryParam( aParam );
}
return aParam;
}
void lcl_SetAllQueryForField( ScDocShell* pDocShell, SCCOLROW nField, sal_Int16 nSheet )
{
ScQueryParam aParam = lcl_GetQueryParam( pDocShell, nSheet );
aParam.RemoveEntryByField(nField);
lcl_SelectAll( pDocShell, aParam );
}
// Modifies sCriteria, and nOp depending on the value of sCriteria
void lcl_setTableFieldsFromCriteria( rtl::OUString& sCriteria1, uno::Reference< beans::XPropertySet >& xDescProps, sheet::TableFilterField2& rFilterField )
{
// #TODO make this more efficient and cycle through
// sCriteria1 character by character to pick up <,<>,=, * etc.
// right now I am more concerned with just getting it to work right
sCriteria1 = sCriteria1.trim();
// table of translation of criteria text to FilterOperators
// <>searchtext - NOT_EQUAL
// =searchtext - EQUAL
// *searchtext - startwith
// <>*searchtext - doesn't startwith
// *searchtext* - contains
// <>*searchtext* - doesn't contain
// [>|>=|<=|...]searchtext for GREATER_value, GREATER_EQUAL_value etc.
sal_Int32 nPos = 0;
bool bIsNumeric = false;
if ( ( nPos = sCriteria1.indexOf( EQUALS ) ) == 0 )
{
if ( sCriteria1.getLength() == EQUALS.getLength() )
rFilterField.Operator = sheet::FilterOperator2::EMPTY;
else
{
rFilterField.Operator = sheet::FilterOperator2::EQUAL;
sCriteria1 = sCriteria1.copy( EQUALS.getLength() );
sCriteria1 = VBAToRegexp( sCriteria1 );
// UseRegularExpressions
if ( xDescProps.is() )
xDescProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseRegularExpressions" ) ), uno::Any( sal_True ) );
}
}
else if ( ( nPos = sCriteria1.indexOf( NOTEQUALS ) ) == 0 )
{
if ( sCriteria1.getLength() == NOTEQUALS.getLength() )
rFilterField.Operator = sheet::FilterOperator2::NOT_EMPTY;
else
{
rFilterField.Operator = sheet::FilterOperator2::NOT_EQUAL;
sCriteria1 = sCriteria1.copy( NOTEQUALS.getLength() );
sCriteria1 = VBAToRegexp( sCriteria1 );
// UseRegularExpressions
if ( xDescProps.is() )
xDescProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseRegularExpressions" ) ), uno::Any( sal_True ) );
}
}
else if ( ( nPos = sCriteria1.indexOf( GREATERTHAN ) ) == 0 )
{
bIsNumeric = true;
if ( ( nPos = sCriteria1.indexOf( GREATERTHANEQUALS ) ) == 0 )
{
sCriteria1 = sCriteria1.copy( GREATERTHANEQUALS.getLength() );
rFilterField.Operator = sheet::FilterOperator2::GREATER_EQUAL;
}
else
{
sCriteria1 = sCriteria1.copy( GREATERTHAN.getLength() );
rFilterField.Operator = sheet::FilterOperator2::GREATER;
}
}
else if ( ( nPos = sCriteria1.indexOf( LESSTHAN ) ) == 0 )
{
bIsNumeric = true;
if ( ( nPos = sCriteria1.indexOf( LESSTHANEQUALS ) ) == 0 )
{
sCriteria1 = sCriteria1.copy( LESSTHANEQUALS.getLength() );
rFilterField.Operator = sheet::FilterOperator2::LESS_EQUAL;
}
else
{
sCriteria1 = sCriteria1.copy( LESSTHAN.getLength() );
rFilterField.Operator = sheet::FilterOperator2::LESS;
}
}
else
rFilterField.Operator = sheet::FilterOperator2::EQUAL;
if ( bIsNumeric )
{
rFilterField.IsNumeric= sal_True;
rFilterField.NumericValue = sCriteria1.toDouble();
}
rFilterField.StringValue = sCriteria1;
}
void SAL_CALL
ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const uno::Any& Operator, const uno::Any& Criteria2, const uno::Any& VisibleDropDown ) throw (uno::RuntimeException)
{
// Is there an existing autofilter
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
sal_Int16 nSheet = thisAddress.Sheet;
ScDocShell* pShell = getScDocShell();
sal_Bool bHasAuto = false;
uno::Reference< sheet::XDatabaseRange > xDataBaseRange = excel::GetAutoFiltRange( pShell, nSheet );
if ( xDataBaseRange.is() )
bHasAuto = true;
uno::Reference< table::XCellRange > xFilterRange;
if ( !bHasAuto )
{
if ( m_Areas->getCount() > 1 )
throw uno::RuntimeException( STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY, uno::Reference< uno::XInterface >() );
table::CellRangeAddress autoFiltAddress;
//CurrentRegion()
if ( isSingleCellRange() )
{
uno::Reference< excel::XRange > xCurrent( CurrentRegion() );
if ( xCurrent.is() )
{
ScVbaRange* pRange = getImplementation( xCurrent );
if ( pRange->isSingleCellRange() )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't create AutoFilter") ), uno::Reference< uno::XInterface >() );
if ( pRange )
{
RangeHelper currentRegion( pRange->mxRange );
autoFiltAddress = currentRegion.getCellRangeAddressable()->getRangeAddress();
}
}
}
else // multi-cell range
{
RangeHelper multiCellRange( mxRange );
autoFiltAddress = multiCellRange.getCellRangeAddressable()->getRangeAddress();
// #163530# Filter box shows only entry of first row
ScDocument* pDocument = ( pShell ? pShell->GetDocument() : NULL );
if ( pDocument )
{
SCCOL nStartCol = autoFiltAddress.StartColumn;
SCROW nStartRow = autoFiltAddress.StartRow;
SCCOL nEndCol = autoFiltAddress.EndColumn;
SCROW nEndRow = autoFiltAddress.EndRow;
pDocument->GetDataArea( autoFiltAddress.Sheet, nStartCol, nStartRow, nEndCol, nEndRow, sal_True, true );
autoFiltAddress.StartColumn = nStartCol;
autoFiltAddress.StartRow = nStartRow;
autoFiltAddress.EndColumn = nEndCol;
autoFiltAddress.EndRow = nEndRow;
}
}
uno::Reference< sheet::XUnnamedDatabaseRanges > xDBRanges = excel::GetUnnamedDataBaseRanges( pShell );
if ( xDBRanges.is() )
{
OSL_TRACE("Going to add new autofilter range.. sheet %i", nSheet );
if ( !xDBRanges->hasByTable( nSheet ) )
xDBRanges->setByTable( autoFiltAddress );
xDataBaseRange.set( xDBRanges->getByTable(nSheet ), uno::UNO_QUERY_THROW );
}
if ( !xDataBaseRange.is() )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Failed to find the autofilter placeholder range" ) ), uno::Reference< uno::XInterface >() );
uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW );
// set autofilt
xDBRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ), uno::Any(sal_True) );
// set header
uno::Reference< beans::XPropertySet > xFiltProps( xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY_THROW );
sal_Bool bHasColHeader = false;
ScDocument* pDoc = pShell ? pShell->GetDocument() : NULL;
bHasColHeader = pDoc->HasColHeader( static_cast< SCCOL >( autoFiltAddress.StartColumn ), static_cast< SCROW >( autoFiltAddress.StartRow ), static_cast< SCCOL >( autoFiltAddress.EndColumn ), static_cast< SCROW >( autoFiltAddress.EndRow ), static_cast< SCTAB >( autoFiltAddress.Sheet ) ) ? sal_True : false;
xFiltProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ContainsHeader") ), uno::Any( bHasColHeader ) );
}
sal_Int32 nField = 0; // *IS* 1 based
rtl::OUString sCriteria1;
sal_Int32 nOperator = excel::XlAutoFilterOperator::xlAnd;
sal_Bool bVisible = sal_True;
VisibleDropDown >>= bVisible;
if ( bVisible == bHasAuto ) // dropdown is displayed/notdisplayed as required
bVisible = false;
sheet::FilterConnection nConn = sheet::FilterConnection_AND;
double nCriteria1 = 0;
bool bHasCritValue = Criteria1.hasValue();
bool bCritHasNumericValue = false; // not sure if a numeric criteria is possible
if ( bHasCritValue )
bCritHasNumericValue = ( Criteria1 >>= nCriteria1 );
if ( !Field.hasValue() && ( Criteria1.hasValue() || Operator.hasValue() || Criteria2.hasValue() ) )
throw uno::RuntimeException();
// Use the normal uno api, sometimes e.g. when you want to use ALL as the filter
// we can't use refresh as the uno interface doesn't have a concept of ALL
// in this case we just call the core calc functionality -
bool bAll = false;
uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
bool bIsValidFieldValue = ( Field >>= nField );
if ( !bIsValidFieldValue && xConverter.is() )
{
try
{
uno::Any aConverted = xConverter->convertTo( Field, getCppuType( (sal_Int32*)0 ) );
bIsValidFieldValue = ( aConverted >>= nField );
}
catch( const uno::Exception& )
{
}
}
if ( bIsValidFieldValue )
{
uno::Reference< sheet::XSheetFilterDescriptor2 > xDesc(
xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY );
if ( xDesc.is() )
{
uno::Sequence< sheet::TableFilterField2 > sTabFilts;
uno::Reference< beans::XPropertySet > xDescProps( xDesc, uno::UNO_QUERY_THROW );
if ( Criteria1.hasValue() )
{
sTabFilts.realloc( 1 );
sTabFilts[0].Operator = sheet::FilterOperator2::EQUAL;// sensible default
if ( !bCritHasNumericValue )
{
Criteria1 >>= sCriteria1;
sTabFilts[0].IsNumeric = bCritHasNumericValue;
if ( bHasCritValue && sCriteria1.getLength() )
lcl_setTableFieldsFromCriteria( sCriteria1, xDescProps, sTabFilts[0] );
else
bAll = true;
}
else // numeric
{
sTabFilts[0].IsNumeric = sal_True;
sTabFilts[0].NumericValue = nCriteria1;
}
}
else // no value specified
bAll = true;
// not sure what the relationship between Criteria1 and Operator is,
// e.g. can you have a Operator without a Criteria ? in openoffice it
bool bIsValidOpValue = ( Operator.hasValue() && ( Operator >>= nOperator ) );
if ( Operator.hasValue() && !bIsValidOpValue && xConverter.is() )
{
try
{
uno::Any aConverted = xConverter->convertTo( Operator, getCppuType( (sal_Int32*)0 ) );
bIsValidOpValue = ( aConverted >>= nOperator );
}
catch( const uno::Exception& )
{
}
}
if ( bIsValidOpValue )
{
// if its a bottom/top Ten(Percent/Value) and there
// is no value specified for critera1 set it to 10
if ( !bCritHasNumericValue && !sCriteria1.getLength() && ( nOperator != excel::XlAutoFilterOperator::xlOr ) && ( nOperator != excel::XlAutoFilterOperator::xlAnd ) )
{
sTabFilts[0].IsNumeric = sal_True;
sTabFilts[0].NumericValue = 10;
bAll = false;
}
switch ( nOperator )
{
case excel::XlAutoFilterOperator::xlBottom10Items:
sTabFilts[0].Operator = sheet::FilterOperator2::BOTTOM_VALUES;
break;
case excel::XlAutoFilterOperator::xlBottom10Percent:
sTabFilts[0].Operator = sheet::FilterOperator2::BOTTOM_PERCENT;
break;
case excel::XlAutoFilterOperator::xlTop10Items:
sTabFilts[0].Operator = sheet::FilterOperator2::TOP_VALUES;
break;
case excel::XlAutoFilterOperator::xlTop10Percent:
sTabFilts[0].Operator = sheet::FilterOperator2::TOP_PERCENT;
break;
case excel::XlAutoFilterOperator::xlOr:
nConn = sheet::FilterConnection_OR;
break;
case excel::XlAutoFilterOperator::xlAnd:
nConn = sheet::FilterConnection_AND;
break;
default:
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UnknownOption") ), uno::Reference< uno::XInterface >() );
}
}
if ( !bAll )
{
sTabFilts[0].Connection = sheet::FilterConnection_AND;
sTabFilts[0].Field = (nField - 1);
rtl::OUString sCriteria2;
if ( Criteria2.hasValue() ) // there is a Criteria2
{
sTabFilts.realloc(2);
sTabFilts[1].Field = sTabFilts[0].Field;
sTabFilts[1].Connection = nConn;
if ( Criteria2 >>= sCriteria2 )
{
if ( sCriteria2.getLength() > 0 )
{
uno::Reference< beans::XPropertySet > xProps;
lcl_setTableFieldsFromCriteria( sCriteria2, xProps, sTabFilts[1] );
sTabFilts[1].IsNumeric = false;
}
}
else // numeric
{
Criteria2 >>= sTabFilts[1].NumericValue;
sTabFilts[1].IsNumeric = sal_True;
sTabFilts[1].Operator = sheet::FilterOperator2::EQUAL;
}
}
}
xDesc->setFilterFields2( sTabFilts );
if ( !bAll )
{
xDataBaseRange->refresh();
}
else
// was 0 based now seems to be 1
lcl_SetAllQueryForField( pShell, nField, nSheet );
}
}
else
{
// this is just to toggle autofilter on and off ( not to be confused with
// a VisibleDropDown option combined with a field, in that case just the
// button should be disabled ) - currently we don't support that
uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW );
if ( bHasAuto )
{
// find the any field with the query and select all
ScQueryParam aParam = lcl_GetQueryParam( pShell, nSheet );
for (SCSIZE i = 0; i< aParam.GetEntryCount(); ++i)
{
ScQueryEntry& rEntry = aParam.GetEntry(i);
if ( rEntry.bDoQuery )
lcl_SetAllQueryForField( pShell, rEntry.nField, nSheet );
}
// remove exising filters
uno::Reference< sheet::XSheetFilterDescriptor2 > xSheetFilterDescriptor(
xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY );
if( xSheetFilterDescriptor.is() )
xSheetFilterDescriptor->setFilterFields2( uno::Sequence< sheet::TableFilterField2 >() );
}
xDBRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ), uno::Any(!bHasAuto) );
}
}
void SAL_CALL
ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& /*CopyOrigin*/ ) throw (uno::RuntimeException)
{
// It appears ( from the web ) that the undocumented CopyOrigin
// param should contain member of enum XlInsertFormatOrigin
// which can have values xlFormatFromLeftOrAbove or xlFormatFromRightOrBelow
// #TODO investigate resultant behaviour using these constants
// currently just processing Shift
sheet::CellInsertMode mode = sheet::CellInsertMode_NONE;
if ( Shift.hasValue() )
{
sal_Int32 nShift = 0;
Shift >>= nShift;
switch ( nShift )
{
case excel::XlInsertShiftDirection::xlShiftToRight:
mode = sheet::CellInsertMode_RIGHT;
break;
case excel::XlInsertShiftDirection::xlShiftDown:
mode = sheet::CellInsertMode_DOWN;
break;
default:
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ("Illegal paramater ") ), uno::Reference< uno::XInterface >() );
}
}
else
{
if ( getRow() >= getColumn() )
mode = sheet::CellInsertMode_DOWN;
else
mode = sheet::CellInsertMode_RIGHT;
}
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
xCellRangeMove->insertCells( thisAddress, mode );
// Paste from clipboard only if the clipboard content was copied via VBA, and not already pasted via VBA again.
// "Insert" behavior should not depend on random clipboard content previously copied by the user.
ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard( NULL );
if ( pClipObj && pClipObj->GetUseInApi() )
{
// After the insert ( this range ) actually has moved
ScRange aRange( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCROW >( thisAddress.StartRow ), static_cast< SCTAB >( thisAddress.Sheet ), static_cast< SCCOL >( thisAddress.EndColumn ), static_cast< SCROW >( thisAddress.EndRow ), static_cast< SCTAB >( thisAddress.Sheet ) );
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( excel::GetDocShellFromRange( mxRange ) , aRange ) );
uno::Reference< excel::XRange > xVbaRange( new ScVbaRange( mxParent, mxContext, xRange, mbIsRows, mbIsColumns ) );
xVbaRange->PasteSpecial( uno::Any(), uno::Any(), uno::Any(), uno::Any() );
}
}
void SAL_CALL
ScVbaRange::Autofit() throw (uno::RuntimeException)
{
sal_Int32 nLen = m_Areas->getCount();
if ( nLen > 1 )
{
for ( sal_Int32 index = 1; index != nLen; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(index) ), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->Autofit();
}
return;
}
// if the range is a not a row or column range autofit will
// throw an error
if ( !( mbIsColumns || mbIsRows ) )
DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
ScDocShell* pDocShell = excel::GetDocShellFromRange( mxRange );
if ( pDocShell )
{
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
ScDocFunc aFunc(*pDocShell);
SCCOLROW nColArr[2];
nColArr[0] = thisAddress.StartColumn;
nColArr[1] = thisAddress.EndColumn;
sal_Bool bDirection = sal_True;
if ( mbIsRows )
{
bDirection = false;
nColArr[0] = thisAddress.StartRow;
nColArr[1] = thisAddress.EndRow;
}
aFunc.SetWidthOrHeight( bDirection, 1, nColArr, thisAddress.Sheet, SC_SIZE_OPTIMAL,
0, true, true );
}
}
/***************************************************************************************
* interface for text:
* com.sun.star.text.XText, com.sun.star.table.XCell, com.sun.star.container.XEnumerationAccess
* com.sun.star.text.XTextRange,
* the main problem is to recognize the numeric and date, which assosiate with DecimalSeparator, ThousandsSeparator,
* TrailingMinusNumbers and FieldInfo.
***************************************************************************************/
void SAL_CALL
ScVbaRange::TextToColumns( const css::uno::Any& Destination, const css::uno::Any& DataType, const css::uno::Any& TextQualifier,
const css::uno::Any& ConsecutiveDelimiter, const css::uno::Any& Tab, const css::uno::Any& Semicolon, const css::uno::Any& Comma,
const css::uno::Any& Space, const css::uno::Any& Other, const css::uno::Any& OtherChar, const css::uno::Any& FieldInfo,
const css::uno::Any& DecimalSeparator, const css::uno::Any& ThousandsSeparator, const css::uno::Any& /*TrailingMinusNumbers*/ ) throw (css::uno::RuntimeException)
{
uno::Reference< excel::XRange > xRange;
if( Destination.hasValue() )
{
if( !( Destination >>= xRange ) )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Destination parameter should be a range" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set range");
}
else
{
//set as current
xRange = this;
OSL_TRACE("set range as himself");
}
sal_Int16 xlTextParsingType = excel::XlTextParsingType::xlDelimited;
if ( DataType.hasValue() )
{
if( !( DataType >>= xlTextParsingType ) )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "DataType parameter should be a short" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set Datatype" );
}
sal_Bool bDilimited = ( xlTextParsingType == excel::XlTextParsingType::xlDelimited );
sal_Int16 xlTextQualifier = excel::XlTextQualifier::xlTextQualifierDoubleQuote;
if( TextQualifier.hasValue() )
{
if( !( TextQualifier >>= xlTextQualifier ))
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "TextQualifier parameter should be a short" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set TextQualifier");
}
sal_Bool bConsecutiveDelimiter = false;
if( ConsecutiveDelimiter.hasValue() )
{
if( !( ConsecutiveDelimiter >>= bConsecutiveDelimiter ) )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ConsecutiveDelimiter parameter should be a boolean" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set ConsecutiveDelimiter");
}
sal_Bool bTab = false;
if( Tab.hasValue() && bDilimited )
{
if( !( Tab >>= bTab ) )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Tab parameter should be a boolean" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set Tab");
}
sal_Bool bSemicolon = false;
if( Semicolon.hasValue() && bDilimited )
{
if( !( Semicolon >>= bSemicolon ) )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Semicolon parameter should be a boolean" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set Semicolon");
}
sal_Bool bComma = false;
if( Comma.hasValue() && bDilimited )
{
if( !( Comma >>= bComma ) )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Comma parameter should be a boolean" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set Comma");
}
sal_Bool bSpace = false;
if( Space.hasValue() && bDilimited )
{
if( !( Space >>= bSpace ) )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Space parameter should be a boolean" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set Space");
}
sal_Bool bOther = false;
rtl::OUString sOtherChar;
if( Other.hasValue() && bDilimited )
{
if( Other >>= bOther )
{
if( OtherChar.hasValue() )
if( !( OtherChar >>= sOtherChar ) )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "OtherChar parameter should be a String" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set OtherChar" );
}
else if( bOther )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Other parameter should be a True" )),
uno::Reference< uno::XInterface >() );
}
// FieldInfo, Optional Variant. An array containing parse information for the individual columns of data.
// The interpretation depends on the value of DataType. When the data is delimited, this argument is an array
// of two-element arrays, with each two-element array specifying the conversion options for a particular column.
// The first element is the column number (1-based), and the second element is one of the xlColumnDataType
// constants specifying how the column is parsed.
uno::Sequence< uno::Sequence< uno::Any > > sFieldInfo;
FieldInfo >>= sFieldInfo;
rtl::OUString sDecimalSeparator;
if( DecimalSeparator.hasValue() )
{
if( !( DecimalSeparator >>= sDecimalSeparator ) )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "DecimalSeparator parameter should be a String" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set DecimalSeparator" );
}
rtl::OUString sThousandsSeparator;
if( ThousandsSeparator.hasValue() )
{
if( !( ThousandsSeparator >>= sThousandsSeparator ) )
throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ThousandsSeparator parameter should be a String" )),
uno::Reference< uno::XInterface >() );
OSL_TRACE("set ThousandsSpeparator" );
}
//TODO* TrailingMinusNumbers Optional Variant. Numbers that begin with a minus character.
// Get the destination range's left-upper cell address.
ScVbaRange* pDestVbaRange = dynamic_cast< ScVbaRange* >( xRange.get() );
ScAddress aScDestAddress;
if ( pDestVbaRange )
{
ScUnoConversion::FillScAddress( aScDestAddress, pDestVbaRange->getLeftUpperCellAddress() );
}
// Parse the value of parameter FieldInfo.
sal_uInt16 nRealCount = 0;
xub_StrLen* pColumns = NULL;
sal_uInt8* pFormats = NULL;
if ( sFieldInfo.getLength() > 0 )
{
sal_uInt16 nCount = sFieldInfo.getLength();
pColumns = new xub_StrLen[nCount];
pFormats = new sal_uInt8[nCount];
sal_uInt16 nFormat = 1;
uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
{
if ( sFieldInfo[nIndex].getLength() >= 2 )
{
nFormat = 1;
try
{
uno::Any aConverted = xConverter->convertTo( sFieldInfo[nIndex][0], getCppuType((xub_StrLen*)0) );
aConverted >>= pColumns[nRealCount];
aConverted = xConverter->convertTo( sFieldInfo[nIndex][1], getCppuType((sal_uInt16*)0) );
aConverted >>= nFormat;
}
catch( const uno::Exception& )
{
}
pFormats[nRealCount++] = nFormat;
}
}
}
sal_Unicode cTextQualifier = '"';
cTextQualifier = xlTextQualifier == excel::XlTextQualifier::xlTextQualifierNone ? '\0' : cTextQualifier;
cTextQualifier = xlTextQualifier == excel::XlTextQualifier::xlTextQualifierSingleQuote ? '\'' : cTextQualifier;
// Get field delimiters.
String rFieldDelimiters;
if ( bTab ) rFieldDelimiters += '\t';
if ( bSemicolon ) rFieldDelimiters += ';';
if ( bComma ) rFieldDelimiters += ',';
if ( bSpace ) rFieldDelimiters += ' ';
if ( bOther ) rFieldDelimiters += *sOtherChar.getStr();
// Get the text in current range to SvMemoryStream.
ScRange aSrcScRange;
ScCellRangesBase* pSrcCellRangesBase = getCellRangesBase();
if ( pSrcCellRangesBase )
{
ScRangeList aRangeList = pSrcCellRangesBase->GetRangeList();
if ( !aRangeList.empty() )
{
aSrcScRange = *aRangeList.front();
}
}
ScImportExport aExport( getScDocument(), aSrcScRange );
aExport.SetDelimiter( static_cast< sal_Unicode >( 0 ) );
SvMemoryStream aStream;
aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
ScImportExport::SetNoEndianSwap( aStream );
aExport.ExportStream( aStream, String(), FORMAT_STRING );
aStream.Seek( 0 );
// Set ScAsciiOptions according to the input parameters.
ScAsciiOptions aOptions;
aOptions.SetFixedLen( !bDilimited );
aOptions.SetStartRow( 0 );
aOptions.SetColInfo( nRealCount, pColumns, pFormats );
if ( bDilimited )
{
aOptions.SetFieldSeps( rFieldDelimiters );
aOptions.SetMergeSeps( bConsecutiveDelimiter );
aOptions.SetTextSep( cTextQualifier );
}
// Split the String in to columns.
if ( pDestVbaRange && pDestVbaRange->getScDocument() )
{
ScImportExport aImport( pDestVbaRange->getScDocument(), aScDestAddress );
aImport.SetExtOptions( aOptions );
aImport.SetApi( false );
aImport.ImportStream( aStream, String(), FORMAT_STRING );
}
if ( pColumns )
{
DELETEZ( pColumns );
}
if ( pFormats )
{
DELETEZ( pFormats );
}
}
uno::Any SAL_CALL
ScVbaRange::Hyperlinks( const uno::Any& aIndex ) throw (uno::RuntimeException)
{
/* The range object always returns a new Hyperlinks object containing a
fixed list of existing hyperlinks in the range.
See vbahyperlinks.hxx for more details. */
// get the global hyperlink object of the sheet (sheet should always be the parent of a Range object)
uno::Reference< excel::XWorksheet > xWorksheet( getParent(), uno::UNO_QUERY_THROW );
uno::Reference< excel::XHyperlinks > xSheetHlinks( xWorksheet->Hyperlinks( uno::Any() ), uno::UNO_QUERY_THROW );
ScVbaHyperlinksRef xScSheetHlinks( dynamic_cast< ScVbaHyperlinks* >( xSheetHlinks.get() ) );
if( !xScSheetHlinks.is() )
throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain hyperlinks implementation object" ) ), uno::Reference< uno::XInterface >() );
// create a new local hyperlinks object based on the sheet hyperlinks
ScVbaHyperlinksRef xHlinks( new ScVbaHyperlinks( getParent(), mxContext, xScSheetHlinks, getScRangeList() ) );
if( aIndex.hasValue() )
return xHlinks->Item( aIndex, uno::Any() );
return uno::Any( uno::Reference< excel::XHyperlinks >( xHlinks.get() ) );
}
css::uno::Reference< excel::XValidation > SAL_CALL
ScVbaRange::getValidation() throw (css::uno::RuntimeException)
{
if ( !m_xValidation.is() )
m_xValidation = new ScVbaValidation( this, mxContext, mxRange );
return m_xValidation;
}
namespace {
sal_Unicode lclGetPrefixChar( const uno::Reference< table::XCell >& rxCell ) throw (uno::RuntimeException)
{
/* TODO/FIXME: We need an apostroph-prefix property at the cell to
implement this correctly. For now, return an apostroph for every text
cell.
TODO/FIXME: When Application.TransitionNavigKeys is supported and true,
this function needs to inspect the cell formatting and return different
prefixes according to the horizontal cell alignment.
*/
return (rxCell->getType() == table::CellContentType_TEXT) ? '\'' : 0;
}
sal_Unicode lclGetPrefixChar( const uno::Reference< table::XCellRange >& rxRange ) throw (uno::RuntimeException)
{
/* This implementation is able to handle different prefixes (needed if
Application.TransitionNavigKeys is true). The function lclGetPrefixChar
for single cells called from here may return any prefix. If that
function returns an empty prefix (NUL character) or different non-empty
prefixes for two cells, this function returns 0.
*/
sal_Unicode cCurrPrefix = 0;
table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxRange );
sal_Int32 nEndCol = aRangeAddr.EndColumn - aRangeAddr.StartColumn;
sal_Int32 nEndRow = aRangeAddr.EndRow - aRangeAddr.StartRow;
for( sal_Int32 nRow = 0; nRow <= nEndRow; ++nRow )
{
for( sal_Int32 nCol = 0; nCol <= nEndCol; ++nCol )
{
uno::Reference< table::XCell > xCell( rxRange->getCellByPosition( nCol, nRow ), uno::UNO_SET_THROW );
sal_Unicode cNewPrefix = lclGetPrefixChar( xCell );
if( (cNewPrefix == 0) || ((cCurrPrefix != 0) && (cNewPrefix != cCurrPrefix)) )
return 0;
cCurrPrefix = cNewPrefix;
}
}
// all cells contain the same prefix - return it
return cCurrPrefix;
}
sal_Unicode lclGetPrefixChar( const uno::Reference< sheet::XSheetCellRangeContainer >& rxRanges ) throw (uno::RuntimeException)
{
sal_Unicode cCurrPrefix = 0;
uno::Reference< container::XEnumerationAccess > xRangesEA( rxRanges, uno::UNO_QUERY_THROW );
uno::Reference< container::XEnumeration > xRangesEnum( xRangesEA->createEnumeration(), uno::UNO_SET_THROW );
while( xRangesEnum->hasMoreElements() )
{
uno::Reference< table::XCellRange > xRange( xRangesEnum->nextElement(), uno::UNO_QUERY_THROW );
sal_Unicode cNewPrefix = lclGetPrefixChar( xRange );
if( (cNewPrefix == 0) || ((cCurrPrefix != 0) && (cNewPrefix != cCurrPrefix)) )
return 0;
cCurrPrefix = cNewPrefix;
}
// all ranges contain the same prefix - return it
return cCurrPrefix;
}
inline uno::Any lclGetPrefixVariant( sal_Unicode cPrefixChar )
{
return uno::Any( (cPrefixChar == 0) ? ::rtl::OUString() : ::rtl::OUString( cPrefixChar ) );
}
} // namespace
uno::Any SAL_CALL ScVbaRange::getPrefixCharacter() throw (uno::RuntimeException)
{
/* (1) If Application.TransitionNavigKeys is false, this function returns
an apostroph character if the text cell begins with an apostroph
character (formula return values are not taken into account); otherwise
an empty string.
(2) If Application.TransitionNavigKeys is true, this function returns
an apostroph character, if the cell is left-aligned; a double-quote
character, if the cell is right-aligned; a circumflex character, if the
cell is centered; a backslash character, if the cell is set to filled;
or an empty string, if nothing of the above.
If a range or a list of ranges contains texts with leading apostroph
character as well as other cells, this function returns an empty
string.
*/
if( mxRange.is() )
return lclGetPrefixVariant( lclGetPrefixChar( mxRange ) );
if( mxRanges.is() )
return lclGetPrefixVariant( lclGetPrefixChar( mxRanges ) );
throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected empty Range object" ) ), uno::Reference< uno::XInterface >() );
}
uno::Any ScVbaRange::getShowDetail() throw ( css::uno::RuntimeException)
{
// #FIXME, If the specified range is in a PivotTable report
// In MSO VBA, the specified range must be a single summary column or row in an outline. otherwise throw exception
if( m_Areas->getCount() > 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can not get Range.ShowDetail attribute ")), uno::Reference< uno::XInterface >() );
sal_Bool bShowDetail = false;
RangeHelper helper( mxRange );
uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor();
xSheetCellCursor->collapseToCurrentRegion();
uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
table::CellRangeAddress aOutlineAddress = xCellRangeAddressable->getRangeAddress();
// check if the specified range is a single summary column or row.
table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress();
if( (thisAddress.StartRow == thisAddress.EndRow && thisAddress.EndRow == aOutlineAddress.EndRow ) ||
(thisAddress.StartColumn == thisAddress.EndColumn && thisAddress.EndColumn == aOutlineAddress.EndColumn ))
{
sal_Bool bColumn =thisAddress.StartRow == thisAddress.EndRow ? false:sal_True;
ScDocument* pDoc = excel::GetDocumentFromRange( mxRange );
ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(static_cast<SCTAB>(thisAddress.Sheet), sal_True);
const ScOutlineArray* pOutlineArray = bColumn ? pOutlineTable->GetColArray(): pOutlineTable->GetRowArray();
if( pOutlineArray )
{
SCCOLROW nPos = bColumn ? (SCCOLROW)(thisAddress.EndColumn-1):(SCCOLROW)(thisAddress.EndRow-1);
ScOutlineEntry* pEntry = pOutlineArray->GetEntryByPos( 0, nPos );
if( pEntry )
{
bShowDetail = !pEntry->IsHidden();
return uno::makeAny( bShowDetail );
}
}
}
else
{
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can not set Range.ShowDetail attribute ")), uno::Reference< uno::XInterface >() );
}
return aNULL();
}
void ScVbaRange::setShowDetail(const uno::Any& aShowDetail) throw ( css::uno::RuntimeException)
{
// #FIXME, If the specified range is in a PivotTable report
// In MSO VBA, the specified range must be a single summary column or row in an outline. otherwise throw exception
if( m_Areas->getCount() > 1 )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can not set Range.ShowDetail attribute ")), uno::Reference< uno::XInterface >() );
bool bShowDetail = extractBoolFromAny( aShowDetail );
RangeHelper helper( mxRange );
uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor();
xSheetCellCursor->collapseToCurrentRegion();
uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
table::CellRangeAddress aOutlineAddress = xCellRangeAddressable->getRangeAddress();
// check if the specified range is a single summary column or row.
table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress();
if( (thisAddress.StartRow == thisAddress.EndRow && thisAddress.EndRow == aOutlineAddress.EndRow ) ||
(thisAddress.StartColumn == thisAddress.EndColumn && thisAddress.EndColumn == aOutlineAddress.EndColumn ))
{
// #FIXME, seems there is a different behavior between MSO and OOo.
// In OOo, the showDetail will show all the level entrys, while only show the first level entry in MSO
uno::Reference< sheet::XSheetOutline > xSheetOutline( helper.getSpreadSheet(), uno::UNO_QUERY_THROW );
if( bShowDetail )
xSheetOutline->showDetail( aOutlineAddress );
else
xSheetOutline->hideDetail( aOutlineAddress );
}
else
{
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can not set Range.ShowDetail attribute ")), uno::Reference< uno::XInterface >() );
}
}
::com::sun::star::uno::Reference< ::ooo::vba::excel::XQueryTable > SAL_CALL
ScVbaRange::getQueryTable() throw (::com::sun::star::uno::RuntimeException)
{
if (!m_xQueryTable.is())
{
m_xQueryTable = new ScVbaQueryTable(mxParent ,mxContext, getScDocument(), this);
}
return m_xQueryTable;
}
uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::MergeArea() throw (script::BasicErrorException, uno::RuntimeException)
{
uno::Reference< sheet::XSheetCellRange > xMergeShellCellRange(mxRange->getCellRangeByPosition(0,0,0,0), uno::UNO_QUERY_THROW);
uno::Reference< sheet::XSheetCellCursor > xMergeSheetCursor(xMergeShellCellRange->getSpreadsheet()->createCursorByRange( xMergeShellCellRange ), uno::UNO_QUERY_THROW);
if( xMergeSheetCursor.is() )
{
xMergeSheetCursor->collapseToMergedArea();
uno::Reference<sheet::XCellRangeAddressable> xMergeCellAddress(xMergeSheetCursor, uno::UNO_QUERY_THROW);
if( xMergeCellAddress.is() )
{
table::CellRangeAddress aCellAddress = xMergeCellAddress->getRangeAddress();
if( aCellAddress.StartColumn ==0 && aCellAddress.EndColumn==0 &&
aCellAddress.StartRow==0 && aCellAddress.EndRow==0)
{
return new ScVbaRange( mxParent,mxContext,mxRange );
}
else
{
ScRange refRange( static_cast< SCCOL >( aCellAddress.StartColumn ), static_cast< SCROW >( aCellAddress.StartRow ), static_cast< SCTAB >( aCellAddress.Sheet ),
static_cast< SCCOL >( aCellAddress.EndColumn ), static_cast< SCROW >( aCellAddress.EndRow ), static_cast< SCTAB >( aCellAddress.Sheet ) );
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell() , refRange ) );
return new ScVbaRange( mxParent, mxContext,xRange );
}
}
}
return new ScVbaRange( mxParent, mxContext, mxRange );
}
//The recordset's member: Recordset.Fields.Item will get a Field obj.
//Field.value is the column value.
::sal_Int32 SAL_CALL
ScVbaRange::CopyFromRecordset( const ::com::sun::star::uno::Any& Data, const ::com::sun::star::uno::Any& MaxRows, const ::com::sun::star::uno::Any& MaxColumns )
throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException)
{
uno::Sequence< uno::Any > aParams;
uno::Sequence< uno::Any > aFieldsParams(1);
uno::Sequence< sal_Int16 > aOutParamIndex;
uno::Sequence< uno::Any > aOutParam;
uno::Reference< uno::XInterface > xIntRes;
uno::Reference< uno::XInterface > xIntFields;
uno::Reference< uno::XInterface > xIntFld;
uno::Any aRet;
uno::Any aPar;
uno::Any aCrrCol;
uno::Any aCrrRow;
sal_Int16 nCrrCol = 0;
sal_Int32 nCrrRow = 0;
sal_Int32 nCol;
sal_Int32 nMaxRows = 0;
sal_Int32 nMaxColumns = 0;
sal_Bool bEof = false;
long lColCnt = 0;
if (MaxColumns.hasValue())
{
MaxColumns >>= nMaxColumns;
}
long lMaxCol = nMaxColumns;
if (MaxRows.hasValue())
{
MaxRows >>= nMaxRows;
}
Data >>= xIntRes;
uno::Reference< script::XInvocation > xInvRes(xIntRes, uno::UNO_QUERY_THROW);
rtl::OUString oMoveNext(RTL_CONSTASCII_USTRINGPARAM("MoveNext")) ;
rtl::OUString oEof(RTL_CONSTASCII_USTRINGPARAM("EOF")) ;
rtl::OUString oFields(RTL_CONSTASCII_USTRINGPARAM("Fields")) ;
if( !xInvRes->hasMethod(oMoveNext))
{
return -1;
}
//Get columns count
aRet = xInvRes->getValue(oFields);
aRet >>= xIntFields;
uno::Reference< script::XInvocation > xInvFields(xIntFields, uno::UNO_QUERY_THROW);
aRet = xInvFields->getValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Count"))) ;
aRet >>= lColCnt;
//Set the assign column number
if (lMaxCol != 0)
{
if (lColCnt > lMaxCol)
{
lColCnt = lMaxCol;
}
}
aCrrRow <<= nCrrRow;
aCrrCol <<= nCrrCol;
//Get start position
uno::Reference< excel::XRange > xRngStartRow = Rows(uno::Any(sal_Int32(1)) );
uno::Reference< excel::XRange > xRngPos = xRngStartRow->Columns( uno::Any(sal_Int32(1)) );
while(1)
{//travel recordset
//get every column
for (long l = 0; l < lColCnt ; l++)
{
nCol = l;
aPar <<= nCol;
//get every field
aRet = xInvFields->invoke( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Item")), uno::Sequence< uno::Any >(&aPar,1) , aOutParamIndex,aOutParam);
aRet >>= xIntFld;
uno::Reference< script::XInvocation > xInvFld(xIntFld, uno::UNO_QUERY_THROW); //Get the Field obj
//set the field value
aRet = xInvFld->getValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Value")) );
uno::Reference< excel::XRange > xRngToFill = xRngPos->Offset(aCrrRow,aCrrCol );
xRngToFill->setValue(aRet);
nCrrCol++;
aCrrCol <<= nCrrCol;
}
aRet = xInvRes->invoke(oMoveNext, aParams,aOutParamIndex,aOutParam );
aRet = xInvRes->getValue(oEof);
aRet >>= bEof;
if (bEof || ( nCrrRow >= nMaxRows && nMaxRows != 0) )
{//Arrive the end of recordset
break;
}
nCrrRow++;
aCrrRow <<= nCrrRow;
nCrrCol = 0;
aCrrCol <<= nCrrCol;
}
return 0;
}
void SAL_CALL
ScVbaRange::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName ) throw (uno::RuntimeException)
{
ScDocShell* pShell = NULL;
sal_Int32 nItems = m_Areas->getCount();
uno::Sequence< table::CellRangeAddress > printAreas( nItems );
uno::Reference< sheet::XPrintAreas > xPrintAreas;
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
RangeHelper thisRange( xRange->getCellRange() );
table::CellRangeAddress rangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
if ( index == 1 )
{
ScVbaRange* pRange = getImplementation( xRange );
// initialise the doc shell and the printareas
pShell = excel::GetDocShellFromRange( pRange->mxRange );
xPrintAreas.set( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
}
printAreas[ index - 1 ] = rangeAddress;
}
if ( pShell )
{
if ( xPrintAreas.is() )
{
xPrintAreas->setPrintAreas( printAreas );
uno::Reference< frame::XModel > xModel = pShell->GetModel();
PrintOutHelper( excel::getBestViewShell( xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, sal_True );
}
}
}
void SAL_CALL
ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const uno::Any& Type ) throw (uno::RuntimeException)
{
uno::Reference< excel::XRange > xDest( Destination, uno::UNO_QUERY_THROW );
ScVbaRange* pRange = getImplementation( xDest );
RangeHelper destRangeHelper( pRange->mxRange );
table::CellRangeAddress destAddress = destRangeHelper.getCellRangeAddressable()->getRangeAddress();
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
ScRange sourceRange;
ScRange destRange;
ScUnoConversion::FillScRange( destRange, destAddress );
ScUnoConversion::FillScRange( sourceRange, thisAddress );
FillDir eDir = FILL_TO_BOTTOM;
double fStep = 1.0;
ScRange aRange( destRange );
ScRange aSourceRange( destRange );
// default to include the number of Rows in the source range;
SCCOLROW nSourceCount = ( sourceRange.aEnd.Row() - sourceRange.aStart.Row() ) + 1;
SCCOLROW nCount = 0;
if ( sourceRange != destRange )
{
// Find direction of fill, vertical or horizontal
if ( sourceRange.aStart == destRange.aStart )
{
if ( sourceRange.aEnd.Row() == destRange.aEnd.Row() )
{
nSourceCount = ( sourceRange.aEnd.Col() - sourceRange.aStart.Col() + 1 );
aSourceRange.aEnd.SetCol( static_cast<SCCOL>( aSourceRange.aStart.Col() + nSourceCount - 1 ) );
eDir = FILL_TO_RIGHT;
nCount = aRange.aEnd.Col() - aSourceRange.aEnd.Col();
}
else if ( sourceRange.aEnd.Col() == destRange.aEnd.Col() )
{
aSourceRange.aEnd.SetRow( static_cast<SCROW>( aSourceRange.aStart.Row() + nSourceCount ) - 1 );
nCount = aRange.aEnd.Row() - aSourceRange.aEnd.Row();
eDir = FILL_TO_BOTTOM;
}
}
else if ( aSourceRange.aEnd == destRange.aEnd )
{
if ( sourceRange.aStart.Col() == destRange.aStart.Col() )
{
aSourceRange.aStart.SetRow( static_cast<SCROW>( aSourceRange.aEnd.Row() - nSourceCount + 1 ) );
nCount = aSourceRange.aStart.Row() - aRange.aStart.Row();
eDir = FILL_TO_TOP;
fStep = -fStep;
}
else if ( sourceRange.aStart.Row() == destRange.aStart.Row() )
{
nSourceCount = ( sourceRange.aEnd.Col() - sourceRange.aStart.Col() ) + 1;
aSourceRange.aStart.SetCol( static_cast<SCCOL>( aSourceRange.aEnd.Col() - nSourceCount + 1 ) );
nCount = aSourceRange.aStart.Col() - aRange.aStart.Col();
eDir = FILL_TO_LEFT;
fStep = -fStep;
}
}
}
ScDocShell* pDocSh= excel::GetDocShellFromRange( mxRange );
FillCmd eCmd = FILL_AUTO;
FillDateCmd eDateCmd = FILL_DAY;
#ifdef VBA_OOBUILD_HACK
double fEndValue = MAXDOUBLE;
#endif
if ( Type.hasValue() )
{
sal_Int16 nFillType = excel::XlAutoFillType::xlFillDefault;
Type >>= nFillType;
switch ( nFillType )
{
case excel::XlAutoFillType::xlFillCopy:
eCmd = FILL_SIMPLE;
fStep = 0.0;
break;
case excel::XlAutoFillType::xlFillDays:
eCmd = FILL_DATE;
break;
case excel::XlAutoFillType::xlFillMonths:
eCmd = FILL_DATE;
eDateCmd = FILL_MONTH;
break;
case excel::XlAutoFillType::xlFillWeekdays:
eCmd = FILL_DATE;
eDateCmd = FILL_WEEKDAY;
break;
case excel::XlAutoFillType::xlFillYears:
eCmd = FILL_DATE;
eDateCmd = FILL_YEAR;
break;
case excel::XlAutoFillType::xlGrowthTrend:
eCmd = FILL_GROWTH;
break;
case excel::XlAutoFillType::xlFillFormats:
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "xlFillFormat not supported for AutoFill" ) ), uno::Reference< uno::XInterface >() );
case excel::XlAutoFillType::xlFillValues:
case excel::XlAutoFillType::xlFillSeries:
case excel::XlAutoFillType::xlLinearTrend:
eCmd = FILL_LINEAR;
break;
case excel::XlAutoFillType::xlFillDefault:
default:
eCmd = FILL_AUTO;
break;
}
}
ScDocFunc aFunc(*pDocSh);
#ifdef VBA_OOBUILD_HACK
aFunc.FillAuto( aSourceRange, NULL, eDir, eCmd, eDateCmd, nCount, fStep, fEndValue, sal_True, sal_True );
#endif
}
sal_Bool SAL_CALL
ScVbaRange::GoalSeek( const uno::Any& Goal, const uno::Reference< excel::XRange >& ChangingCell ) throw (uno::RuntimeException)
{
ScDocShell* pDocShell = getScDocShell();
sal_Bool bRes = sal_True;
ScVbaRange* pRange = static_cast< ScVbaRange* >( ChangingCell.get() );
if ( pDocShell && pRange )
{
uno::Reference< sheet::XGoalSeek > xGoalSeek( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
RangeHelper changingCellRange( pRange->mxRange );
table::CellRangeAddress changingCellAddr = changingCellRange.getCellRangeAddressable()->getRangeAddress();
rtl::OUString sGoal = getAnyAsString( Goal );
table::CellAddress thisCell( thisAddress.Sheet, thisAddress.StartColumn, thisAddress.StartRow );
table::CellAddress changingCell( changingCellAddr.Sheet, changingCellAddr.StartColumn, changingCellAddr.StartRow );
sheet::GoalResult res = xGoalSeek->seekGoal( thisCell, changingCell, sGoal );
ChangingCell->setValue( uno::makeAny( res.Result ) );
// openoffice behaves differently, result is 0 if the divergence is too great
// but... if it detects 0 is the value it requires then it will use that
// e.g. divergence & result both = 0.0 does NOT mean there is an error
if ( ( res.Divergence != 0.0 ) && ( res.Result == 0.0 ) )
bRes = false;
}
else
bRes = false;
return bRes;
}
void
ScVbaRange::Calculate( ) throw (script::BasicErrorException, uno::RuntimeException)
{
getWorksheet()->Calculate();
}
uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::Item( const uno::Any& row, const uno::Any& column ) throw (script::BasicErrorException, uno::RuntimeException)
{
if ( mbIsRows || mbIsColumns )
{
if ( column.hasValue() )
DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
uno::Reference< excel::XRange > xRange;
if ( mbIsColumns )
xRange = Columns( row );
else
xRange = Rows( row );
return xRange;
}
return Cells( row, column );
}
void
ScVbaRange::AutoOutline( ) throw (script::BasicErrorException, uno::RuntimeException)
{
// #TODO #FIXME needs to check for summary row/col ( whatever they are )
// not valid for multi Area Addresses
if ( m_Areas->getCount() > 1 )
DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY);
// So needs to either span an entire Row or a just be a single cell
// ( that contains a summary RowColumn )
// also the Single cell cause doesn't seem to be handled specially in
// this code ( ported from the helperapi RangeImpl.java,
// RangeRowsImpl.java, RangesImpl.java, RangeSingleCellImpl.java
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
xSheetOutline->autoOutline( thisAddress );
}
void SAL_CALL
ScVbaRange:: ClearOutline( ) throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->ClearOutline();
}
return;
}
RangeHelper thisRange( mxRange );
uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
xSheetOutline->clearOutline();
}
void
ScVbaRange::groupUnGroup( bool bUnGroup ) throw ( script::BasicErrorException, uno::RuntimeException )
{
if ( m_Areas->getCount() > 1 )
DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY);
table::TableOrientation nOrient = table::TableOrientation_COLUMNS;
if ( mbIsRows )
nOrient = table::TableOrientation_ROWS;
RangeHelper thisRange( mxRange );
table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
if ( bUnGroup )
xSheetOutline->ungroup( thisAddress, nOrient );
else
xSheetOutline->group( thisAddress, nOrient );
}
void SAL_CALL
ScVbaRange::Group( ) throw (script::BasicErrorException, uno::RuntimeException)
{
groupUnGroup();
}
void SAL_CALL
ScVbaRange::Ungroup( ) throw (script::BasicErrorException, uno::RuntimeException)
{
groupUnGroup(true);
}
void lcl_mergeCellsOfRange( const uno::Reference< table::XCellRange >& xCellRange, sal_Bool _bMerge = sal_True ) throw ( uno::RuntimeException )
{
uno::Reference< util::XMergeable > xMergeable( xCellRange, uno::UNO_QUERY_THROW );
xMergeable->merge(_bMerge);
}
void SAL_CALL
ScVbaRange::Merge( const uno::Any& Across ) throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->Merge(Across);
}
return;
}
uno::Reference< table::XCellRange > oCellRange;
sal_Bool bAcross = false;
Across >>= bAcross;
if ( !bAcross )
lcl_mergeCellsOfRange( mxRange );
else
{
uno::Reference< excel::XRange > oRangeRowsImpl = Rows( uno::Any() );
// #TODO #FIXME this seems incredibly lame, this can't be right
for (sal_Int32 i=1; i <= oRangeRowsImpl->getCount();i++)
{
oRangeRowsImpl->Cells( uno::makeAny( i ), uno::Any() )->Merge( uno::makeAny( false ) );
}
}
}
void SAL_CALL
ScVbaRange::UnMerge( ) throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
sal_Int32 nItems = m_Areas->getCount();
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->UnMerge();
}
return;
}
lcl_mergeCellsOfRange( mxRange, false);
}
uno::Any SAL_CALL
ScVbaRange::getStyle() throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->getStyle();
}
uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW );
rtl::OUString sStyleName;
xProps->getPropertyValue(CELLSTYLE) >>= sStyleName;
ScDocShell* pShell = getScDocShell();
uno::Reference< frame::XModel > xModel( pShell->GetModel() );
uno::Reference< excel::XStyle > xStyle = new ScVbaStyle( this, mxContext, sStyleName, xModel );
return uno::makeAny( xStyle );
}
void SAL_CALL
ScVbaRange::setStyle( const uno::Any& _style ) throw (uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ), uno::UNO_QUERY_THROW );
xRange->setStyle( _style );
return;
}
uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW );
uno::Reference< excel::XStyle > xStyle;
_style >>= xStyle;
xProps->setPropertyValue(CELLSTYLE, uno::makeAny(xStyle->getName()));
}
uno::Reference< excel::XRange >
ScVbaRange::PreviousNext( bool bIsPrevious )
{
ScMarkData markedRange;
ScRange refRange;
RangeHelper thisRange( mxRange );
ScUnoConversion::FillScRange( refRange, thisRange.getCellRangeAddressable()->getRangeAddress());
markedRange. SetMarkArea( refRange );
short nMove = bIsPrevious ? -1 : 1;
SCCOL nNewX = refRange.aStart.Col();
SCROW nNewY = refRange.aStart.Row();
SCTAB nTab = refRange.aStart.Tab();
ScDocument* pDoc = getScDocument();
pDoc->GetNextPos( nNewX,nNewY, nTab, nMove,0, true,true, markedRange );
refRange.aStart.SetCol( nNewX );
refRange.aStart.SetRow( nNewY );
refRange.aStart.SetTab( nTab );
refRange.aEnd.SetCol( nNewX );
refRange.aEnd.SetRow( nNewY );
refRange.aEnd.SetTab( nTab );
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell() , refRange ) );
return new ScVbaRange( mxParent, mxContext, xRange );
}
uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::Next() throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ) , uno::UNO_QUERY_THROW );
return xRange->Next();
}
return PreviousNext( false );
}
uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::Previous() throw (script::BasicErrorException, uno::RuntimeException)
{
if ( m_Areas->getCount() > 1 )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ), uno::UNO_QUERY_THROW );
return xRange->Previous();
}
return PreviousNext( true );
}
uno::Reference< excel::XRange > SAL_CALL
ScVbaRange::SpecialCells( const uno::Any& _oType, const uno::Any& _oValue) throw ( script::BasicErrorException )
{
bool bIsSingleCell = isSingleCellRange();
bool bIsMultiArea = ( m_Areas->getCount() > 1 );
ScVbaRange* pRangeToUse = this;
uno::Reference< excel::XRange > xUsedRange( getWorksheet()->getUsedRange() );
sal_Int32 nType = 0;
if ( !( _oType >>= nType ) )
DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
switch(nType)
{
case excel::XlCellType::xlCellTypeSameFormatConditions:
case excel::XlCellType::xlCellTypeAllValidation:
case excel::XlCellType::xlCellTypeSameValidation:
DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
break;
case excel::XlCellType::xlCellTypeBlanks:
case excel::XlCellType::xlCellTypeComments:
case excel::XlCellType::xlCellTypeConstants:
case excel::XlCellType::xlCellTypeFormulas:
case excel::XlCellType::xlCellTypeVisible:
case excel::XlCellType::xlCellTypeLastCell:
{
if ( bIsMultiArea )
{
// need to process each area, gather the results and
// create a new range from those
std::vector< table::CellRangeAddress > rangeResults;
sal_Int32 nItems = ( m_Areas->getCount() + 1 );
for ( sal_Int32 index=1; index <= nItems; ++index )
{
uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
xRange = xRange->SpecialCells( _oType, _oValue);
ScVbaRange* pRange = getImplementation( xRange );
if ( xRange.is() && pRange )
{
sal_Int32 nElems = ( pRange->m_Areas->getCount() + 1 );
for ( sal_Int32 nArea = 1; nArea < nElems; ++nArea )
{
uno::Reference< excel::XRange > xTmpRange( m_Areas->Item( uno::makeAny( nArea ), uno::Any() ), uno::UNO_QUERY_THROW );
RangeHelper rHelper( xTmpRange->getCellRange() );
rangeResults.push_back( rHelper.getCellRangeAddressable()->getRangeAddress() );
}
}
}
ScRangeList aCellRanges;
std::vector< table::CellRangeAddress >::iterator it = rangeResults.begin();
std::vector< table::CellRangeAddress >::iterator it_end = rangeResults.end();
for ( ; it != it_end; ++ it )
{
ScRange refRange;
ScUnoConversion::FillScRange( refRange, *it );
aCellRanges.Append( refRange );
}
// Single range
if ( aCellRanges.size() == 1 )
{
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), *aCellRanges.front() ) );
return new ScVbaRange( mxParent, mxContext, xRange );
}
uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( getScDocShell(), aCellRanges ) );
return new ScVbaRange( mxParent, mxContext, xRanges );
}
else if ( bIsSingleCell )
{
pRangeToUse = static_cast< ScVbaRange* >( xUsedRange.get() );
}
break;
}
default:
DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
break;
}
if ( !pRangeToUse )
DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
return pRangeToUse->SpecialCellsImpl( nType, _oValue );
}
sal_Int32 lcl_getFormulaResultFlags(const uno::Any& aType) throw ( script::BasicErrorException )
{
sal_Int32 nType = excel::XlSpecialCellsValue::xlNumbers;
aType >>= nType;
sal_Int32 nRes = sheet::FormulaResult::VALUE;
switch(nType)
{
case excel::XlSpecialCellsValue::xlErrors:
nRes= sheet::FormulaResult::ERROR;
break;
case excel::XlSpecialCellsValue::xlLogical:
//TODO bc93774: ask NN if this is really an appropriate substitute
nRes = sheet::FormulaResult::VALUE;
break;
case excel::XlSpecialCellsValue::xlNumbers:
nRes = sheet::FormulaResult::VALUE;
break;
case excel::XlSpecialCellsValue::xlTextValues:
nRes = sheet::FormulaResult::STRING;
break;
default:
DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
}
return nRes;
}
uno::Reference< excel::XRange >
ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) throw ( script::BasicErrorException )
{
uno::Reference< excel::XRange > xRange;
try
{
uno::Reference< sheet::XCellRangesQuery > xQuery( mxRange, uno::UNO_QUERY_THROW );
uno::Reference< excel::XRange > oLocRangeImpl;
uno::Reference< sheet::XSheetCellRanges > xLocSheetCellRanges;
switch(nType)
{
case excel::XlCellType::xlCellTypeAllFormatConditions:
case excel::XlCellType::xlCellTypeSameFormatConditions:
case excel::XlCellType::xlCellTypeAllValidation:
case excel::XlCellType::xlCellTypeSameValidation:
// Shouldn't get here ( should be filtered out by
// ScVbaRange::SpecialCells()
DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
break;
case excel::XlCellType::xlCellTypeBlanks:
xLocSheetCellRanges = xQuery->queryEmptyCells();
break;
case excel::XlCellType::xlCellTypeComments:
xLocSheetCellRanges = xQuery->queryContentCells(sheet::CellFlags::ANNOTATION);
break;
case excel::XlCellType::xlCellTypeConstants:
xLocSheetCellRanges = xQuery->queryContentCells(23);
break;
case excel::XlCellType::xlCellTypeFormulas:
{
sal_Int32 nFormulaResult = lcl_getFormulaResultFlags(_oValue);
xLocSheetCellRanges = xQuery->queryFormulaCells(nFormulaResult);
break;
}
case excel::XlCellType::xlCellTypeLastCell:
xRange = Cells( uno::makeAny( getCount() ), uno::Any() );
case excel::XlCellType::xlCellTypeVisible:
xLocSheetCellRanges = xQuery->queryVisibleCells();
break;
default:
DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
break;
}
if (xLocSheetCellRanges.is())
{
xRange = lcl_makeXRangeFromSheetCellRanges( getParent(), mxContext, xLocSheetCellRanges, getScDocShell() );
}
}
catch (uno::Exception& )
{
DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_NOCELLSWEREFOUND);
}
return xRange;
}
void SAL_CALL
ScVbaRange::RemoveSubtotal( ) throw (script::BasicErrorException, uno::RuntimeException)
{
uno::Reference< sheet::XSubTotalCalculatable > xSub( mxRange, uno::UNO_QUERY_THROW );
xSub->removeSubTotals();
}
void SAL_CALL
ScVbaRange::Subtotal( ::sal_Int32 _nGroupBy, ::sal_Int32 _nFunction, const uno::Sequence< ::sal_Int32 >& _nTotalList, const uno::Any& aReplace, const uno::Any& PageBreaks, const uno::Any& /*SummaryBelowData*/ ) throw (script::BasicErrorException, uno::RuntimeException)
{
try
{
sal_Bool bDoReplace = false;
aReplace >>= bDoReplace;
sal_Bool bAddPageBreaks = false;
PageBreaks >>= bAddPageBreaks;
uno::Reference< sheet::XSubTotalCalculatable> xSub(mxRange, uno::UNO_QUERY_THROW );
uno::Reference< sheet::XSubTotalDescriptor > xSubDesc = xSub->createSubTotalDescriptor(sal_True);
uno::Reference< beans::XPropertySet > xSubDescPropertySet( xSubDesc, uno::UNO_QUERY_THROW );
xSubDescPropertySet->setPropertyValue(INSERTPAGEBREAKS, uno::makeAny( bAddPageBreaks));
sal_Int32 nLen = _nTotalList.getLength();
uno::Sequence< sheet::SubTotalColumn > aColumns( nLen );
for (int i = 0; i < nLen; i++)
{
aColumns[i].Column = _nTotalList[i] - 1;
switch (_nFunction)
{
case excel::XlConsolidationFunction::xlAverage:
aColumns[i].Function = sheet::GeneralFunction_AVERAGE;
break;
case excel::XlConsolidationFunction::xlCount:
aColumns[i].Function = sheet::GeneralFunction_COUNT;
break;
case excel::XlConsolidationFunction::xlCountNums:
aColumns[i].Function = sheet::GeneralFunction_COUNTNUMS;
break;
case excel::XlConsolidationFunction::xlMax:
aColumns[i].Function = sheet::GeneralFunction_MAX;
break;
case excel::XlConsolidationFunction::xlMin:
aColumns[i].Function = sheet::GeneralFunction_MIN;
break;
case excel::XlConsolidationFunction::xlProduct:
aColumns[i].Function = sheet::GeneralFunction_PRODUCT;
break;
case excel::XlConsolidationFunction::xlStDev:
aColumns[i].Function = sheet::GeneralFunction_STDEV;
break;
case excel::XlConsolidationFunction::xlStDevP:
aColumns[i].Function = sheet::GeneralFunction_STDEVP;
break;
case excel::XlConsolidationFunction::xlSum:
aColumns[i].Function = sheet::GeneralFunction_SUM;
break;
case excel::XlConsolidationFunction::xlUnknown:
aColumns[i].Function = sheet::GeneralFunction_NONE;
break;
case excel::XlConsolidationFunction::xlVar:
aColumns[i].Function = sheet::GeneralFunction_VAR;
break;
case excel::XlConsolidationFunction::xlVarP:
aColumns[i].Function = sheet::GeneralFunction_VARP;
break;
default:
DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString()) ;
return;
}
}
xSubDesc->addNew(aColumns, _nGroupBy - 1);
xSub->applySubTotals(xSubDesc, bDoReplace);
}
catch (uno::Exception& )
{
DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
}
}
uno::Any SAL_CALL ScVbaRange::AdvancedFilter( sal_Int32 Action, const uno::Any& CriteriaRange,
const uno::Any& CopyToRange, const uno::Any& Unique ) throw (script::BasicErrorException, uno::RuntimeException)
{
uno::Any aRet;
aRet <<= sal_True;
uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
ScDocument* pDoc = getScDocument();
if ( !pDoc )
{
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from range" ) ), uno::Reference< uno::XInterface >() );
}
// Action
if ( Action != excel::XlFilterAction::xlFilterInPlace && Action != excel::XlFilterAction::xlFilterCopy )
{
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid input parameter" ) ), uno::Reference< uno::XInterface >() );
}
if ( m_Areas->getCount() > 1 )
{
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid range" ) ), uno::Reference< uno::XInterface >() );
}
sal_Bool bCopyOut = ( Action != excel::XlFilterAction::xlFilterInPlace );
uno::Reference< sheet::XSheetFilterDescriptor > xFilterDesc;
uno::Reference< sheet::XSheetFilterable > xSheetFilter( mxRange, uno::UNO_QUERY_THROW );
// CriteriaRange
String aBuiltInCriteria; // Excel Built-In Filter Criteria.
table::CellRangeAddress refParentAddr;
uno::Any aCriteriaRange = CriteriaRange;
formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1;
if ( aCriteriaRange.hasValue() && aCriteriaRange.getValueTypeClass() == uno::TypeClass_STRING )
{
rtl::OUString rRangeString;
aCriteriaRange >>= rRangeString;
aConv = excel::IsR1C1ReferFormat( pDoc, rRangeString ) ? formula::FormulaGrammar::CONV_XL_R1C1 : aConv;
}
else
{
// Get Excel BuiltIn Filter Criteria.
ScRangeName* pRangeNames = pDoc->GetRangeName();
if (pRangeNames)
{
ScRangeName::const_iterator itr = pRangeNames->begin(), itrEnd = pRangeNames->end();
for (; itr != itrEnd; ++itr)
{
if (itr->second->HasType(RT_CRITERIA))
{
itr->second->GetSymbol( aBuiltInCriteria, formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
break;
}
}
}
aCriteriaRange = aBuiltInCriteria.Len() > 0 ? uno::makeAny( rtl::OUString( aBuiltInCriteria ) ) : aCriteriaRange;
}
if ( aCriteriaRange.hasValue() )
{
table::CellRangeAddress criteriaRangeAddress = getCellRangeAddressForVBARange( aCriteriaRange, getScDocShell(), aConv );
ScRange refRange;
ScUnoConversion::FillScRange( refRange, criteriaRangeAddress );
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), refRange ) );
uno::Reference< sheet::XSheetFilterableEx > xCriteria( xRange, uno::UNO_QUERY );
if ( xCriteria.is() )
{
xFilterDesc = xCriteria->createFilterDescriptorByObject( xSheetFilter );
}
}
else if ( mxRange.is() )
{
uno::Reference< sheet::XSheetFilterableEx > xCriteria( mxRange, uno::UNO_QUERY );
if ( xCriteria.is() )
{
xFilterDesc = xCriteria->createFilterDescriptorByObject( xSheetFilter );
}
}
uno::Reference< beans::XPropertySet > xPropertySet( xFilterDesc, uno::UNO_QUERY );
if ( xPropertySet.is() )
{
xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_COPYOUT ) ), uno::makeAny( bCopyOut ) );
}
// CopyToRange
if ( bCopyOut && CopyToRange.hasValue() && xPropertySet.is() )
{
formula::FormulaGrammar::AddressConvention aTmpConv = formula::FormulaGrammar::CONV_XL_A1;
if ( CopyToRange.getValueTypeClass() == uno::TypeClass_STRING )
{
rtl::OUString rRangeString;
CopyToRange >>= rRangeString;
aTmpConv = excel::IsR1C1ReferFormat( pDoc, rRangeString ) ? formula::FormulaGrammar::CONV_XL_R1C1 : aConv;
}
ScRange refRange;
ScUnoConversion::FillScRange( refRange, getCellRangeAddressForVBARange( CopyToRange, getScDocShell(), aTmpConv ) );
uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), refRange ) );
uno::Reference< sheet::XCellAddressable > xCellAddr( xRange->getCellByPosition( 0, 0 ), uno::UNO_QUERY_THROW );
xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_OUTPOS ) ), uno::makeAny( xCellAddr->getCellAddress() ) );
}
// Unique
if ( xPropertySet.is() )
{
sal_Bool bUnique = false;
uno::Any aUnique;
try
{
aUnique <<= bUnique;
aUnique = ( xConverter.is() && Unique.hasValue() ) ? xConverter->convertTo( Unique, getCppuType( ( sal_Bool* ) 0 ) ) : aUnique;
}
catch( const uno::Exception& )
{
}
xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SKIPDUP ) ), aUnique );
}
// Do filter.
if ( xFilterDesc.is() )
{
xSheetFilter->filter( xFilterDesc );
}
return aRet;
}
//Range.PivotTable.
//Returns a PivotTable object that represents the PivotTable report containing the upper-left corner of the specified range.
uno::Reference< excel::XPivotTable >
ScVbaRange::PivotTable() throw (uno::RuntimeException)
{
uno::Reference< excel::XPivotTable > xDestPVTable;
uno::Reference< sheet::XSpreadsheet > xSheet;
if ( mxRange.is() )
{
RangeHelper thisRange( mxRange );
xSheet = thisRange.getSpreadSheet();
}
else if ( mxRanges.is() )
{
uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
RangeHelper thisRange( xRange );
xSheet = thisRange.getSpreadSheet();
}
uno::Reference< sheet::XDataPilotTablesSupplier > xTables(xSheet, uno::UNO_QUERY_THROW ) ;
uno::Reference< container::XIndexAccess > xIndexAccess( xTables->getDataPilotTables(), uno::UNO_QUERY_THROW );
if ( xIndexAccess.is() )
{
//get the upper-left cell address
table::CellAddress aAddress = getLeftUpperCellAddress();
sal_Int32 nCount = xIndexAccess->getCount();
for (sal_Int32 i=0; i < nCount; i++)
{
uno::Reference< sheet::XDataPilotTable > xDPTable(xIndexAccess->getByIndex(i), uno::UNO_QUERY);
uno::Reference< sheet::XDataPilotTable2 > xDPTable2(xDPTable, uno::UNO_QUERY);
//check if the cell is in the pivot table
sheet::DataPilotTablePositionData posData = xDPTable2->getPositionData(aAddress);
table::CellRangeAddress aCellRangeAddress = xDPTable->getOutputRange();
ScRange aScRange( aCellRangeAddress.StartColumn, aCellRangeAddress.StartRow, aCellRangeAddress.Sheet,
aCellRangeAddress.EndColumn, aCellRangeAddress.EndRow, aCellRangeAddress.Sheet );
ScAddress aPos( aAddress.Column, aAddress.Row, aAddress.Sheet );
if( !(posData.PositionType == sheet::DataPilotTablePositionType::NOT_IN_TABLE) || aScRange.In( aPos ) )
{
xDestPVTable = new ScVbaPivotTable( mxContext, xDPTable );
break;
}
}
}
return xDestPVTable;
}
rtl::OUString&
ScVbaRange::getServiceImplName()
{
static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaRange") );
return sImplName;
}
uno::Sequence< rtl::OUString >
ScVbaRange::getServiceNames()
{
static uno::Sequence< rtl::OUString > aServiceNames;
if ( aServiceNames.getLength() == 0 )
{
aServiceNames.realloc( 1 );
aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Range" ) );
}
return aServiceNames;
}
sal_Bool SAL_CALL
ScVbaRange::hasError() throw (uno::RuntimeException)
{
double dResult = false;
uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
uno::Reference< script::XInvocation > xInvoc( xApplication->WorksheetFunction(), uno::UNO_QUERY_THROW );
static rtl::OUString FunctionName( RTL_CONSTASCII_USTRINGPARAM("IsError" ) );
uno::Sequence< uno::Any > Params(1);
uno::Reference< excel::XRange > aRange( this );
Params[0] = uno::makeAny( aRange );
uno::Sequence< sal_Int16 > OutParamIndex;
uno::Sequence< uno::Any > OutParam;
xInvoc->invoke( FunctionName, Params, OutParamIndex, OutParam ) >>= dResult;
if ( dResult > 0.0 )
return sal_True;
return false;
}
namespace range
{
namespace sdecl = comphelper::service_decl;
sdecl::vba_service_class_<ScVbaRange, sdecl::with_args<true> > serviceImpl;
extern sdecl::ServiceDecl const serviceDecl(
serviceImpl,
"SvVbaRange",
"ooo.vba.excel.Range" );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|