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
|
# -*- tab-width: 4; indent-tabs-mode: nil -*-
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import struct, sys
import globals, formula, xlsmodel, msodraw
from globals import debug
class RecordError(Exception): pass
# -------------------------------------------------------------------
# record handler classes
class Bes(object):
"""Boolean or error value"""
ErrorValues = {
0x00: "#NULL!",
0x07: "#DIV/0!",
0x0F: "#VALUE!",
0x17: "#REF!",
0x1D: "#NAME?",
0x24: "#NUM!",
0x2A: "#N/A",
0x2B: "#GETTING_DATA"
}
def __init__ (self, strm):
self.bBoolErr = strm.readUnsignedInt(1)
self.fError = strm.readUnsignedInt(1) != 0
def toString (self):
if self.fError:
return "(error:%s)"%globals.getValueOrUnknown(Bes.ErrorValues,self.bBoolErr,"???")
elif self.bBoolErr:
return "(boolean:true)"
else:
return "(boolean:false)"
class CellParsedFormula(object):
def __init__ (self, strm):
cce = strm.readUnsignedInt(2)
bytes = strm.readBytes(cce)
parser = formula.FormulaParser(strm.header, bytes)
parser.parse()
self.text = parser.getText()
def toString (self):
return self.text
class ColRelU(object):
def __init__ (self, strm):
self.col = strm.readUnsignedInt(2)
self.colRelative = (self.col & 0x4000) != 0
self.rowRelative = (self.col & 0x8000) != 0
self.col = self.col & 0x3FFF
class RgceLoc(object):
def __init__ (self, strm):
self.row = strm.readUnsignedInt(2)
self.column = ColRelU(strm)
def toString (self):
s = ''
if not self.column.colRelative:
s += '$'
s += formula.toColName(self.column.col)
if not self.column.rowRelative:
s += '$'
s += "%d"%(self.row+1)
return s
class Ref8(object):
def __init__ (self, strm):
self.row1 = strm.readUnsignedInt(2)
self.row2 = strm.readUnsignedInt(2)
self.col1 = strm.readUnsignedInt(2)
self.col2 = strm.readUnsignedInt(2)
def toString (self):
string = ("(col=%d,row=%d) - (col=%d,row=%d)"%
(self.col1, self.row1, self.col2, self.row2))
if self.col1 == 0 and self.col2 == 0xFF:
string += ", entire column"
if self.row1 == 0 and self.row2 == 0xFFFF:
string += ", entire row"
return string
class RefU(object):
def __init__ (self, strm):
self.row1 = strm.readUnsignedInt(2)
self.row2 = strm.readUnsignedInt(2)
self.col1 = strm.readUnsignedInt(1)
self.col2 = strm.readUnsignedInt(1)
def toString (self):
rge = formula.CellRange()
rge.firstRow = self.row1
rge.firstCol = self.col1
rge.lastRow = self.row2
rge.lastCol = self.col2
return rge.toString()
class Ref8U(object):
def __init__ (self, strm):
self.row1 = strm.readUnsignedInt(2)
self.row2 = strm.readUnsignedInt(2)
self.col1 = strm.readUnsignedInt(2)
self.col2 = strm.readUnsignedInt(2)
def toString (self):
rge = formula.CellRange()
rge.firstRow = self.row1
rge.firstCol = self.col1
rge.lastRow = self.row2
rge.lastCol = self.col2
return rge.toString()
class RKAuxData(object):
"""Store auxiliary data for RK value"""
def __init__ (self):
self.multi100 = False
self.signedInt = False
def decodeRK (rkval, auxData = None):
multi100 = ((rkval & 0x00000001) != 0)
signedInt = ((rkval & 0x00000002) != 0)
realVal = (rkval & 0xFFFFFFFC)
if signedInt:
# for integer, perform right-shift by 2 bits.
realVal = realVal/4
else:
# for floating-point, convert the value back to the bytes,
# pad the bytes to make it 8-byte long, and convert it back
# to the numeric value.
tmpBytes = struct.pack('<L', realVal)
tmpBytes = struct.pack('xxxx') + tmpBytes
realVal = struct.unpack('<d', tmpBytes)[0]
if multi100:
realVal /= 100.0
if auxData != None:
auxData.multi100 = multi100
auxData.signedInt = signedInt
return realVal
class LongRGB(object):
def __init__ (self, r, g, b):
self.red = r
self.green = g
self.blue = b
def toString (self):
return "(R=%d,G=%d,B=%d)"%(self.red, self.green, self.blue)
def dumpRgb(rgb):
return {'r': rgb.red,
'g': rgb.green,
'b': rgb.blue}
class ICV(object):
def __init__ (self, value):
self.value = value
def toString (self):
return "color=0x%2.2X"%self.value
def dumpIcv(icv):
return {'value': icv.value}
class CFRTID(object):
def __init__ (self, start, end):
self.start = start
self.end = end
def dumpCfrtid(cfrtid):
return {'start': cfrtid.start,
'end': cfrtid.end}
class FrtHeader(object):
def __init__ (self, rt, flags):
self.rt = rt
self.flags = flags
def dumpFrtHeader(header):
return {'rt': header.rt,
'flags': header.flags}
class PivotField(object):
"""Data about pivot cache field.
This is to be stored in the persistent stream data, to be used in the SXDBB
records."""
def __init__ (self):
self.hasMoreThan255 = False
self.values = []
class DXFN(object):
def __init__ (self, strm):
bits = strm.readUnsignedInt(4)
self.alchNinch = (bits & 0x00000001) != 0 # whether the value of dxfalc.alc MUST be ignored.
self.alcvNinch = (bits & 0x00000002) != 0 # whether the value of dxfalc.alcv MUST be ignored.
self.wrapNinch = (bits & 0x00000004) != 0 # whether the value of dxfalc.fWrap MUST be ignored.
self.trotNinch = (bits & 0x00000008) != 0 # whether the value of dxfalc.trot MUST be ignored.
self.kintoNinch = (bits & 0x00000010) != 0 # whether the value of dxfalc.fJustLast MUST be ignored.
self.cIndentNinch = (bits & 0x00000020) != 0 # whether the values of dxfalc.cIndent and dxfalc.iIndent MUST be ignored.
self.fShrinkNinch = (bits & 0x00000040) != 0 # whether the value of dxfalc.fShrinkToFit MUST be ignored.
self.fMergeCellNinch = (bits & 0x00000080) != 0 # whether the value of dxfalc.fMergeCell MUST be ignored.
self.lockedNinch = (bits & 0x00000100) != 0 # whether the value of dxfprot.fLocked MUST be ignored.
self.hiddenNinch = (bits & 0x00000200) != 0 # whether the value of dxfprot.fHidden MUST be ignored.
self.glLeftNinch = (bits & 0x00000400) != 0 # whether the values of dxfbdr.dgLeft and dxfbdr.icvLeft MUST be ignored .
self.glRightNinch = (bits & 0x00000800) != 0 # whether the values of dxfbdr.dgRight and dxfbdr.icvRight MUST be ignored.
self.glTopNinch = (bits & 0x00001000) != 0 # whether the values of dxfbdr.dgTop and dxfbdr.icvTop MUST be ignored.
self.glBottomNinch = (bits & 0x00002000) != 0 # whether the values of dxfbdr.dgBottom and dxfbdr.icvBottom MUST be ignored.
self.glDiagDownNinch = (bits & 0x00004000) != 0 # whether the value of dxfbdr.bitDiagDown MUST be ignored.
self.glDiagUpNinch = (bits & 0x00008000) != 0 # whether the value of dxfbdr.bitDiagUp MUST be ignored.
self.flsNinch = (bits & 0x00010000) != 0 # whether the value of dxfpat.fls MUST be ignored.
self.icvFNinch = (bits & 0x00020000) != 0 # whether the value of dxfpat.icvForeground MUST be ignored.
self.icvBNinch = (bits & 0x00040000) != 0 # whether the value of dxfpat.icvBackground MUST be ignored.
self.ifmtNinch = (bits & 0x00080000) != 0 # whether the value of dxfnum.ifmt MUST be ignored.
self.fIfntNinch = (bits & 0x00100000) != 0 # whether the value of dxffntd.ifnt MUST be ignored.
self.V = (bits & 0x00200000) != 0 # (unused)
self.W = (bits & 0x01C00000) != 0 # (reserved; 3-bits)
self.ibitAtrNum = (bits & 0x02000000) != 0 # whether number formatting information is part of this structure.
self.ibitAtrFnt = (bits & 0x04000000) != 0 # whether font information is part of this structure.
self.ibitAtrAlc = (bits & 0x08000000) != 0 # whether alignment information is part of this structure.
self.ibitAtrBdr = (bits & 0x10000000) != 0 # whether border formatting information is part of this structure.
self.ibitAtrPat = (bits & 0x20000000) != 0 # whether pattern information is part of this structure.
self.ibitAtrProt = (bits & 0x40000000) != 0 # whether rotation information is part of this structure.
self.iReadingOrderNinch = (bits & 0x80000000) != 0 # whether the value of dxfalc.iReadingOrder MUST be ignored.
bits = strm.readUnsignedInt(2)
self.fIfmtUser = (bits & 0x0001) != 0 # When set to 1, dxfnum contains a format string.
self.f = (bits & 0x0002) != 0 # (unused)
self.fNewBorder = (bits & 0x0004) != 0 # 0=border formats to all cells; 1=border formats to the range outline only
self.fZeroInited = (bits & 0x8000) != 0 # whether the value of dxfalc.iReadingOrder MUST be taken into account.
if self.ibitAtrNum:
# DXFNum (number format)
if self.fIfmtUser:
# DXFNumUser (string)
sizeDXFNumUser = strm.readUnsignedInt(2)
strBytes = strm.readBytes(sizeDXFNumUser)
text, textLen = globals.getRichText(strBytes)
self.numFmtName = text
else:
# DXFNumIFmt
strm.readBytes(1) # ignored
self.numFmtID = strm.readUnsignedInt(1)
if self.ibitAtrFnt:
# DXFFntD (font information)
nameLen = strm.readUnsignedInt(1)
if nameLen > 0:
# Note the text length may double in case of a double-byte string.
curPos = strm.getCurrentPos()
self.fontName, nameLen = globals.getRichText(strm.readRemainingBytes(), nameLen)
self.setCurrentPos(curPos) # Move back to the pre-text position.
self.moveForward(realLen) # Move for exactly the bytes read.
if 63 - nameLen < 0:
raise RecordError
strm.readBytes(63 - nameLen) # Ignore these bytes.
self.fontAttrs = strm.readBytes(16) # I'll process this later.
self.fontColor = strm.readUnsignedInt(4)
strm.readUnsignedInt(4) # ignored
tsNinch = strm.readUnsignedInt(4)
sssNinch = strm.readUnsignedInt(4) != 0
ulsNinch = strm.readUnsignedInt(4) != 0
blsNinch = strm.readUnsignedInt(4) != 0
strm.readUnsignedInt(4) # ignored
ich = strm.readUnsignedInt(4)
cch = strm.readUnsignedInt(4)
iFnt = strm.readUnsignedInt(2)
if self.ibitAtrAlc:
# DXFALC (text alignment properties)
strm.readUnsignedInt(8)
if self.ibitAtrBdr:
# DXFBdr (border properties)
strm.readUnsignedInt(8)
if self.ibitAtrPat:
# DXFPat (pattern and colors)
strm.readUnsignedInt(4)
if self.ibitAtrProt:
# DXFProt (protection attributes)
strm.readUnsignedInt(2)
def appendLines (self, hdl):
# (TODO: This is not complete)
if self.ibitAtrNum:
if self.fIfmtUser:
hdl.appendLine("number format to use: %s (name)"%self.numFmtName)
else:
hdl.appendLine("number format to use: %d (ID)"%self.numFmtID)
if self.fNewBorder:
s = "only outline of the range"
else:
s = "all cells in the range"
hdl.appendLineString("border formats applied", s)
class DXFN12NoCB(object):
def __init__ (self, strm):
self.dxfn = DXFN(strm)
def appendLines (self, hdl):
self.dxfn.appendLines(hdl)
class BaseRecordHandler(globals.ByteStream):
def __init__ (self, header, size, bytes, strmData, roflist = []):
globals.ByteStream.__init__(self, bytes)
self.header = header
self.lines = []
self.strmData = strmData
self.roflist = roflist
def parseBytes (self):
"""Parse the original bytes and generate human readable output.
The derived class should only worry about overwriting this function. The
bytes are given as self.bytes, and call self.appendLine([new line]) to
append a line to be displayed.
"""
pass
def fillModel (self, model):
"""Parse the original bytes and populate the workbook model.
Like parseBytes(), the derived classes must overwrite this method."""
pass
def dumpData (self):
"""Parse the original bytes and return the data dump as ('name', {'val1': val1,...})
Like parseBytes(), the derived classes must overwrite this method."""
pass
def __getHeaderStr (self):
return "%4.4Xh: "%self.header
def output (self):
headerStr = self.__getHeaderStr()
print (headerStr + "-"*(globals.OutputWidth-len(headerStr)))
try:
self.parseBytes()
for line in self.lines:
try:
print (headerStr + line)
except:
if not globals.params.catchExceptions:
raise
print (headerStr + "(xlsrecord:unprintable)")
except globals.ByteStreamError:
print(headerStr + "Error interpreting the record!")
def debug (self, msg):
print ("%4.4Xh: %s"%(self.header, msg))
def appendLine (self, line):
self.lines.append(line)
def appendMultiLine (self, line):
charWidth = globals.OutputWidth - len(self.__getHeaderStr())
singleLine = ''
testLine = ''
for word in line.split():
testLine += word + ' '
if len(testLine) > charWidth:
self.lines.append(singleLine)
testLine = word + ' '
singleLine = testLine
if len(singleLine) > 0:
self.lines.append(singleLine)
def appendLineString (self, name, value):
text = "%s: %s"%(name, value)
self.appendLine(text)
def appendLineInt (self, name, value):
text = "%s: %d"%(name, value)
self.appendLine(text)
def appendLineBoolean (self, name, value):
text = "%s: %s"%(name, self.getYesNo(value))
self.appendLine(text)
def appendCellPosition (self, col, row):
text = "cell position: (col: %d; row: %d)"%(col, row)
self.appendLine(text)
def getYesNo (self, boolVal):
if boolVal:
return 'yes'
else:
return 'no'
def getTrueFalse (self, boolVal):
if boolVal:
return 'true'
else:
return 'false'
def getEnabledDisabled (self, boolVal):
if boolVal:
return 'enabled'
else:
return 'disabled'
def getBoolVal (self, boolVal, trueStr, falseStr):
if boolVal:
return trueStr
else:
return falseStr
def readXLUnicodeString (self):
return self.readUnicodeString()
def readShortXLUnicodeString (self):
cch = self.readUnsignedInt(1)
return self.readUnicodeString(cch)
def readXLUnicodeStringNoCch (self, cch):
return self.readUnicodeString(cch)
def readXLUnicodeRichExtendedString (self):
cch = self.readUnsignedInt(2)
flags = self.readUnsignedInt(1)
fHighByte = (flags & 0x01) != 0 # double byte string
fExtSt = (flags & 0x04) != 0 # phonetic string data
fRichSt = (flags & 0x08) != 0 # rich text
cRun = 0
if fRichSt:
cRun = self.readUnsignedInt(2) # number of elemetns in rgRun
cbExtRst = 0
if fExtSt:
cbExtRst = self.readSignedInt(4) # byte count of ExtRst
if fHighByte:
rgb = unicode(self.readBytes(2*cch), 'UTF-16LE', errors='replace')
elif globals.params.utf8:
# Compressed Unicode-> latin1
rgb = self.readBytes(cch).decode('cp1252')
else:
# Old behaviour with hex dump
rgb = self.readBytes(cch)
# optional FormatRun array. Ignore this for now.
self.readBytes(cRun*4) # Each FormatRun is 4-byte long.
# optional ExtRst. Ignore this for now.
self.readBytes(cbExtRst)
return rgb
def readLongRGB (self):
r = self.readUnsignedInt(1)
g = self.readUnsignedInt(1)
b = self.readUnsignedInt(1)
self.readBytes(1) # reserved
return LongRGB(r, g, b)
def readICV (self):
return ICV(self.readUnsignedInt(2))
def readCFRTID (self):
return CFRTID(self.readUnsignedInt(2),self.readUnsignedInt(2))
def readFrtHeader (self):
return FrtHeader(self.readUnsignedInt(2), self.readUnsignedInt(2))
class AutofilterInfo(BaseRecordHandler):
def __parseBytes (self):
self.arrowCount = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine("number of autofilter arrows: %d"%self.arrowCount)
def fillModel (self, model):
self.__parseBytes()
sh = model.getCurrentSheet()
sh.setAutoFilterArrowSize(self.arrowCount)
class Autofilter(BaseRecordHandler):
class DoperType:
FilterNotUsed = 0x00 # filter condition not used
RKNumber = 0x02
Number = 0x04 # IEEE floating point nubmer
String = 0x06
BooleanOrError = 0x08
MatchAllBlanks = 0x0C
MatchAllNonBlanks = 0x0E
compareCodes = [
'< ', # 01
'= ', # 02
'<=', # 03
'> ', # 04
'<>', # 05
'>=' # 06
]
errorCodes = {
0x00: '#NULL! ',
0x07: '#DIV/0!',
0x0F: '#VALUE!',
0x17: '#REF! ',
0x1D: '#NAME? ',
0x24: '#NUM! ',
0x2A: '#N/A '
}
class Doper(object):
def __init__ (self, dataType=None):
self.dataType = dataType
self.sign = None
def appendLines (self, hdl):
# data type
s = '(unknown)'
if self.dataType == Autofilter.DoperType.RKNumber:
s = "RK number"
elif self.dataType == Autofilter.DoperType.Number:
s = "number"
elif self.dataType == Autofilter.DoperType.String:
s = "string"
elif self.dataType == Autofilter.DoperType.BooleanOrError:
s = "boolean or error"
elif self.dataType == Autofilter.DoperType.MatchAllBlanks:
s = "match all blanks"
elif self.dataType == Autofilter.DoperType.MatchAllNonBlanks:
s = "match all non-blanks"
hdl.appendLine(" data type: %s"%s)
# comparison code
if self.sign != None:
s = globals.getValueOrUnknown(Autofilter.compareCodes, self.sign)
hdl.appendLine(" comparison code: %s (%d)"%(s, self.sign))
class DoperRK(Doper):
def __init__ (self):
Autofilter.Doper.__init__(self, Autofilter.DoperType.RK)
self.rkval = None
def appendLines (self, hdl):
Autofilter.Doper.appendLines(self, hdl)
hdl.appendLine(" value: %g"%decodeRK(self.rkval))
class DoperNumber(Doper):
def __init__ (self):
Autofilter.Doper.__init__(self, Autofilter.DoperType.Number)
self.number = None
def appendLines (self, hdl):
Autofilter.Doper.appendLines(self, hdl)
hdl.appendLine(" value: %g"%self.number)
class DoperString(Doper):
def __init__ (self):
Autofilter.Doper.__init__(self, Autofilter.DoperType.String)
self.strLen = None
def appendLines (self, hdl):
Autofilter.Doper.appendLines(self, hdl)
if self.strLen != None:
hdl.appendLine(" string length: %d"%self.strLen)
class DoperBoolean(Doper):
def __init__ (self):
Autofilter.Doper.__init__(self, Autofilter.DoperType.Boolean)
self.flag = None
self.value = None
def appendLines (self, hdl):
Autofilter.Doper.appendLines(self, hdl)
hdl.appendLine(" boolean or error: %s"%hdl.getBoolVal(self.flag, "error", "boolean"))
if self.flag:
# error value
hdl.appendLine(" error value: %s (0x%2.2X)"%
(globals.getValueOrUnknown(Autofilter.errorCodes, self.value), self.value))
else:
# boolean value
hd.appendLine(" boolean value: %s"%hdl.getTrueFalse(self.value))
def __readDoper (self):
vt = self.readUnsignedInt(1)
if vt == Autofilter.DoperType.RKNumber:
doper = Autofilter.DoperRK()
doper.sign = self.readUnsignedInt(1)
doper.rkval = self.readUnsignedInt(4)
self.readBytes(4) # ignore 4 bytes
elif vt == Autofilter.DoperType.Number:
doper = Autofilter.DoperNumber()
doper.sign = self.readUnsignedInt(1)
doper.number = self.readDouble()
elif vt == Autofilter.DoperType.String:
doper = Autofilter.DoperString()
doper.sign = self.readUnsignedInt(1)
self.readBytes(4) # ignore 4 bytes
doper.strLen = self.readUnsignedInt(1)
self.readBytes(3) # ignore 3 bytes
elif vt == Autofilter.DoperType.BooleanOrError:
doper = Autofilter.DoperBoolean()
doper.sign = self.readUnsignedInt(1)
doper.flag = self.readUnsignedInt(1)
doper.value = self.readUnsignedInt(1)
self.readBytes(6) # ignore 6 bytes
else:
doper = Autofilter.Doper()
self.readBytes(9) # ignore the entire 10 bytes
return doper
def __parseBytes (self):
self.filterIndex = self.readUnsignedInt(2) # column ID?
flag = self.readUnsignedInt(2)
self.join = (flag & 0x0003) # 1 = ANDed 0 = ORed
self.simple1 = (flag & 0x0004) # 1st condition is simple equality (for optimization)
self.simple2 = (flag & 0x0008) # 2nd condition is simple equality (for optimization)
self.top10 = (flag & 0x0010) # top 10 autofilter
self.top = (flag & 0x0020) # 1 = top 10 filter shows the top item, 0 = shows the bottom item
self.percent = (flag & 0x0040) # 1 = top 10 shows percentage, 0 = shows items
self.itemCount = (flag & 0xFF80) / (2*7)
self.doper1 = self.__readDoper()
self.doper2 = self.__readDoper()
# pick up string(s)
self.string1 = None
self.string2 = None
try:
if self.doper1.dataType == Autofilter.DoperType.String:
self.string1 = self.readXLUnicodeStringNoCch(self.doper1.strLen)
if self.doper2.dataType == Autofilter.DoperType.String:
self.string2 = self.readXLUnicodeStringNoCch(self.doper2.strLen)
except:
pass
def parseBytes (self):
self.__parseBytes()
self.appendLine("filter index (relative column ID): %d"%self.filterIndex)
self.appendLine("joining: %s"%self.getBoolVal(self.join, "AND", "OR"))
self.appendLineBoolean("1st condition is simple equality", self.simple1)
self.appendLineBoolean("2nd condition is simple equality", self.simple2)
self.appendLineBoolean("top 10 autofilter", self.top10)
if self.top10:
self.appendLine("top 10 shows: %s"%self.getBoolVal(self.top, "top item", "bottom item"))
self.appendLine("top 10 shows: %s"%self.getBoolVal(self.percent, "percentage", "items"))
self.appendLine("top 10 item count: %d"%self.itemCount)
self.appendLine("1st condition:")
self.doper1.appendLines(self)
self.appendLine("2nd condition:")
self.doper2.appendLines(self)
if self.string1 != None:
self.appendLine("string for 1st condition: %s"%self.string1)
if self.string2 != None:
self.appendLine("string for 2nd condition: %s"%self.string2)
def fillModel (self, model):
self.__parseBytes()
sh = model.getCurrentSheet()
obj = xlsmodel.AutoFilterArrow(self.filterIndex)
obj.isActive = True
obj.equalString1 = self.string1
obj.equalString2 = self.string2
sh.setAutoFilterArrow(self.filterIndex, obj)
# TODO: Pick up more complex states as we need them.
class EOF(BaseRecordHandler):
pass
class BOF(BaseRecordHandler):
Type = {
0x0005: "Workbook globals",
0x0006: "Visual Basic module",
0x0010: "Worksheet or dialog sheet",
0x0020: "Chart",
0x0040: "Excel 4.0 macro sheet",
0x0100: "Workspace file"
}
# TODO: Add more build identifiers.
buildId = {
0x0DBB: 'Excel 97',
0x0EDE: 'Excel 97',
0x2775: 'Excel XP'
}
def getBuildIdName (self, value):
if BOF.buildId.has_key(value):
return BOF.buildId[value]
else:
return '(unknown)'
def __parseBytes (self):
# BIFF version
self.ver = self.readUnsignedInt(2)
# Substream type
self.dataType = self.readUnsignedInt(2)
# build ID and year
self.buildID = self.readUnsignedInt(2)
self.buildYear = self.readUnsignedInt(2)
# file history flags
try:
self.flags = self.readUnsignedInt(4)
self.win = (self.flags & 0x00000001)
self.risc = (self.flags & 0x00000002)
self.beta = (self.flags & 0x00000004)
self.winAny = (self.flags & 0x00000008)
self.macAny = (self.flags & 0x00000010)
self.betaAny = (self.flags & 0x00000020)
self.riscAny = (self.flags & 0x00000100)
self.lowestExcelVer = self.readSignedInt(4)
except:
self.flags = 0
self.win = 0
self.risc = 0
self.beta = 0
self.winAny = 0
self.macAny = 0
self.betaAny = 0
self.riscAny = 0
self.lowestExcelVer = 0
def parseBytes (self):
self.__parseBytes()
# BIFF version
s = 'not BIFF8'
if self.ver == 0x0600:
s = 'BIFF8'
self.appendLine("BIFF version: %s"%s)
# Substream type
self.appendLine("type: %s"%BOF.Type[self.dataType])
# build ID and year
self.appendLine("build ID: %s (%4.4Xh)"%(self.getBuildIdName(self.buildID), self.buildID))
self.appendLine("build year: %d"%self.buildYear)
# file history flags
self.appendLine("last edited by Excel on Windows: %s"%self.getYesNo(self.win))
self.appendLine("last edited by Excel on RISC: %s"%self.getYesNo(self.risc))
self.appendLine("last edited by beta version of Excel: %s"%self.getYesNo(self.beta))
self.appendLine("has ever been edited by Excel for Windows: %s"%self.getYesNo(self.winAny))
self.appendLine("has ever been edited by Excel for Macintosh: %s"%self.getYesNo(self.macAny))
self.appendLine("has ever been edited by beta version of Excel: %s"%self.getYesNo(self.betaAny))
self.appendLine("has ever been edited by Excel on RISC: %s"%self.getYesNo(self.riscAny))
self.appendLine("earliest Excel version that can read all records: %d"%self.lowestExcelVer)
def fillModel (self, model):
if model.modelType != xlsmodel.ModelType.Workbook:
return
self.__parseBytes()
sheet = model.appendSheet(self.dataType)
s = 'not BIFF8'
if self.ver == 0x0600:
s = 'BIFF8'
sheet.version = s
def dumpData(self):
self.__parseBytes()
return ('bof', {'ver': self.ver,
'data-type': self.dataType,
'build-id': self.buildID,
'build-year': self.buildYear,
'win': self.win,
'risc': self.risc,
'beta': self.beta,
'win-any': self.winAny,
'mac-any': self.macAny,
'beta-any': self.betaAny,
'risc-any': self.riscAny,
'lowest-version': self.lowestExcelVer})
class BoundSheet(BaseRecordHandler):
hiddenStates = {0x00: 'visible', 0x01: 'hidden', 0x02: 'very hidden'}
sheetTypes = {0x00: 'worksheet or dialog sheet',
0x01: 'Excel 4.0 macro sheet',
0x02: 'chart',
0x06: 'Visual Basic module'}
@staticmethod
def getHiddenState (flag):
if BoundSheet.hiddenStates.has_key(flag):
return BoundSheet.hiddenStates[flag]
else:
return 'unknown'
@staticmethod
def getSheetType (flag):
if BoundSheet.sheetTypes.has_key(flag):
return BoundSheet.sheetTypes[flag]
else:
return 'unknown'
def __parseBytes (self):
self.posBOF = self.readUnsignedInt(4)
flags = self.readUnsignedInt(2)
textLen = self.readUnsignedInt(1)
self.name, textLen = globals.getRichText(self.readRemainingBytes(), textLen)
self.hiddenState = (flags & 0x0003)
self.sheetType = (flags & 0xFF00)
def parseBytes (self):
self.__parseBytes()
self.appendLine("BOF position in this stream: %d"%self.posBOF)
self.appendLine("sheet name: %s"%self.name)
self.appendLine("hidden state: %s"%BoundSheet.getHiddenState(self.hiddenState))
self.appendLine("sheet type: %s"%BoundSheet.getSheetType(self.sheetType))
def fillModel (self, model):
self.__parseBytes()
wbglobal = model.getWorkbookGlobal()
data = xlsmodel.WorkbookGlobal.SheetData()
data.name = self.name
data.visible = not self.hiddenState
wbglobal.appendSheetData(data)
class CF(BaseRecordHandler):
def __parseBytes (self):
self.conditionType = self.readUnsignedInt(1)
self.compFunction = self.readUnsignedInt(1)
sizeFormula1 = self.readUnsignedInt(2)
sizeFormula2 = self.readUnsignedInt(2)
self.rgbdxf = DXFN(self)
self.formula1 = self.readBytes(sizeFormula1)
self.formula2 = self.readBytes(sizeFormula2)
conditionType = {
0x01: "use comparison function",
0x02: "use 1st formula"
}
compFunction = {
0x01: "(v1 <= v2 && (v1 <= cell || cell == v2)) || (v2 < v1 && v2 <= cell && cell <= v1)",
0x02: "v1 <= v2 && (cell < v1 || v2 < cell)",
0x03: "cell == v1",
0x04: "cell != v1",
0x05: "v1 < cell",
0x06: "cell < v1",
0x07: "v1 <= cell",
0x08: "cell <= v1"
}
def parseBytes (self):
self.__parseBytes()
# condition type
condTypeName = globals.getValueOrUnknown(CF.conditionType, self.conditionType)
self.appendLine("condition type: %s (0x%2.2X)"%(condTypeName, self.conditionType))
# comparison function
compFuncText = globals.getValueOrUnknown(CF.compFunction, self.compFunction)
self.appendLine("comparison function: %s (0x%2.2X)"%(compFuncText, self.compFunction))
self.rgbdxf.appendLines(self)
# formulas
if len(self.formula1) > 0:
self.appendLine("formula 1 (bytes): %s"%globals.getRawBytes(self.formula1, True, False))
parser = formula.FormulaParser(self.header, self.formula1)
parser.parse()
self.appendLine("formula 1 (displayed): " + parser.getText())
if len(self.formula2) > 0:
self.appendLine("formula 2 (bytes): %s"%globals.getRawBytes(self.formula2, True, False))
parser = formula.FormulaParser(self.header, self.formula2)
parser.parse()
self.appendLine("formula 2 (displayed): " + parser.getText())
class CondFmt(BaseRecordHandler):
def __parseBytes (self):
self.cfCount = self.readUnsignedInt(2)
tmp = self.readUnsignedInt(2)
self.toughRecalc = (tmp & 0x01) != 0
self.recordID = (tmp & 0xFE) / 2
self.refBound = Ref8U(self)
hitRangeCount = self.readUnsignedInt(2)
self.hitRanges = []
for i in xrange(0, hitRangeCount):
self.hitRanges.append(Ref8U(self))
def parseBytes (self):
self.__parseBytes()
self.appendLine("record count: %d"%self.cfCount)
self.appendLineBoolean("tough recalc", self.toughRecalc)
self.appendLine("ID of this record: %d"%self.recordID)
self.appendLine("format range: (col=%d,row=%d) - (col=%d,row=%d)"%
(self.refBound.col1, self.refBound.row1, self.refBound.col2, self.refBound.row2))
for hitRange in self.hitRanges:
self.appendLine("hit range: (col=%d,row=%d) - (col=%d,row=%d)"%
(hitRange.col1, hitRange.row1, hitRange.col2, hitRange.row2))
def fillModel (self, model):
self.__parseBytes()
formatRange = formula.CellRange()
formatRange.firstCol = self.refBound.col1
formatRange.lastCol = self.refBound.col2
formatRange.firstRow = self.refBound.row1
formatRange.lastRow = self.refBound.row2
obj = xlsmodel.CondFormat()
obj.formatRange = formatRange
sheet = model.getCurrentSheet()
sheet.setCondFormat(obj)
class Dimensions(BaseRecordHandler):
def __parseBytes (self):
self.rowMin = self.readUnsignedInt(4)
self.rowMax = self.readUnsignedInt(4)
self.colMin = self.readUnsignedInt(2)
self.colMax = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine("first defined row: %d"%self.rowMin)
self.appendLine("last defined row plus 1: %d"%self.rowMax)
self.appendLine("first defined column: %d"%self.colMin)
self.appendLine("last defined column plus 1: %d"%self.colMax)
def fillModel (self, model):
self.__parseBytes()
sh = model.getCurrentSheet()
if not isinstance(sh, xlsmodel.Chart):
sh.setFirstDefinedCell(self.colMin, self.rowMin)
sh.setFirstFreeCell(self.colMax, self.rowMax)
def dumpData(self):
self.__parseBytes()
return ('dimensions', {'row-min': self.rowMin,
'row-max': self.rowMax,
'col-min': self.colMin,
'col-max': self.colMax})
class Dv(BaseRecordHandler):
valueTypes = [
'any type of value', # 0x0
'whole number', # 0x1
'decimal value', # 0x2
'matches one in a list of values', # 0x3
'date value', # 0x4
'time value', # 0x5
'text value', # 0x6
'custom formula' # 0x7
]
errorStyles = [
'stop icon', # 0x00
'warning icon', # 0x01
'information icon' # 0x02
]
imeModes = [
'No Control', # 0x00
'On', # 0x01
'Off (English)', # 0x02
'Hiragana', # 0x04
'wide katakana', # 0x05
'narrow katakana', # 0x06
'Full-width alphanumeric', # 0x07
'Half-width alphanumeric', # 0x08
'Full-width hangul', # 0x09
'Half-width hangul' # 0x0A
]
operatorTypes = [
'Between', # 0x0
'Not Between', # 0x1
'Equals', # 0x2
'Not Equals', # 0x3
'Greater Than', # 0x4
'Less Than', # 0x5
'Greater Than or Equal To', # 0x6
'Less Than or Equal To' # 0x7
]
def __parseBytes (self):
bits = self.readUnsignedInt(4)
self.valType = (bits & 0x0000000F)
self.errStyle = (bits & 0x00000070) / (2**4)
self.strLookup = (bits & 0x00000080) != 0
self.allowBlank = (bits & 0x00000100) != 0
self.noDropDown = (bits & 0x00000200) != 0
self.imeMode = (bits & 0x0003FC00) / (2**10) # take 8 bits and shift by 10 bits
self.showInputMsg = (bits & 0x00040000) != 0
self.showErrorMsg = (bits & 0x00080000) != 0
self.operator = (bits & 0x00F00000) / (2**20)
self.promptTitle = self.readUnicodeString()
self.errorTitle = self.readUnicodeString()
self.prompt = self.readUnicodeString()
self.error = self.readUnicodeString()
formulaLen = self.readUnsignedInt(2)
self.readUnsignedInt(2) # ignore 2 bytes.
self.formula1 = self.readBytes(formulaLen)
self.strFormula1 = ''
if len(self.formula1) > 0:
parser = formula.FormulaParser(self.header, self.formula1)
parser.parse()
self.strFormula1 = parser.getText()
formulaLen = self.readUnsignedInt(2)
self.readUnsignedInt(2) # ignore 2 bytes.
self.formula2 = self.readBytes(formulaLen)
self.strFormula2 = ''
if len(self.formula2) > 0:
parser = formula.FormulaParser(self.header, self.formula2)
parser.parse()
self.strFormula2 = parser.getText()
rangeCount = self.readUnsignedInt(2)
self.ranges = []
for i in xrange(0, rangeCount):
obj = formula.CellRange()
obj.firstRow = self.readUnsignedInt(2)
obj.lastRow = self.readUnsignedInt(2)
obj.firstCol = self.readUnsignedInt(2)
obj.lastCol = self.readUnsignedInt(2)
self.ranges.append(obj)
def parseBytes (self):
self.__parseBytes()
s = globals.getValueOrUnknown(Dv.valueTypes, self.valType)
self.appendLine("type: %s (0x%1.1X)"%(s, self.valType))
s = globals.getValueOrUnknown(Dv.errorStyles, self.errStyle)
self.appendLine("error style: %s (0x%1.1X)"%(s, self.errStyle))
self.appendLineBoolean("list of valid inputs", self.strLookup)
self.appendLineBoolean("allow blank", self.allowBlank)
self.appendLineBoolean("suppress down-down in cell", self.noDropDown)
s = globals.getValueOrUnknown(Dv.imeModes, self.imeMode)
self.appendLine("IME mode: %s (0x%1.1X)"%(s, self.imeMode))
self.appendLineBoolean("show input message", self.showInputMsg)
self.appendLineBoolean("show error message", self.showErrorMsg)
s = globals.getValueOrUnknown(Dv.operatorTypes, self.operator)
self.appendLine("operator type: %s (0x%1.1X)"%(s, self.operator))
self.appendLine("prompt title: %s"%self.promptTitle)
self.appendLine("error title: %s"%self.errorTitle)
self.appendLine("prompt: %s"%self.prompt)
self.appendLine("error: %s"%self.error)
self.appendLine("formula 1 (bytes): %s"%globals.getRawBytes(self.formula1, True, False))
self.appendLine("formula 1 (displayed): %s"%self.strFormula1)
self.appendLine("formula 2 (bytes): %s"%globals.getRawBytes(self.formula2, True, False))
self.appendLine("formula 2 (displayed): %s"%self.strFormula2)
for rng in self.ranges:
self.appendLine("range: %s"%rng.getName())
def fillModel (self, model):
self.__parseBytes()
obj = xlsmodel.DataValidation(self.ranges)
obj.valueType = globals.getValueOrUnknown(Dv.valueTypes, self.valType)
obj.errorStyle = globals.getValueOrUnknown(Dv.errorStyles, self.errStyle)
obj.operator = globals.getValueOrUnknown(Dv.operatorTypes, self.operator)
obj.showInputMsg = self.showInputMsg
obj.showErrorMsg = self.showErrorMsg
obj.strLookup = self.strLookup
obj.allowBlank = self.allowBlank
obj.prompt = self.prompt
obj.promptTitle = self.promptTitle
obj.error = self.error
obj.errorTitle = self.errorTitle
obj.formula1 = self.strFormula1
obj.formula2 = self.strFormula2
sheet = model.getCurrentSheet()
sheet.setDataValidation(obj)
class DVal(BaseRecordHandler):
def __parseBytes (self):
bits = self.readUnsignedInt(2)
self.winClosed = (bits & 0x0001) != 0
self.left = self.readUnsignedInt(4)
self.top = self.readUnsignedInt(4)
self.objID = self.readSignedInt(4)
self.dvCount = self.readUnsignedInt(4)
def parseBytes (self):
self.__parseBytes()
self.appendLineBoolean("window was closed", self.winClosed)
self.appendLine("window position: (x=%d,y=%d)"%(self.left, self.top))
s = ''
if self.objID == -1:
s = '(no drop-down displayed)'
self.appendLine("drop-down button object ID: %d %s"%(self.objID, s))
self.appendLine("number of DV records: %d"%self.dvCount)
def fillModel (self, model):
self.__parseBytes()
class Fbi(BaseRecordHandler):
def __parseBytes (self):
self.fontWidth = self.readUnsignedInt(2)
self.fontHeight = self.readUnsignedInt(2)
self.defaultHeight = self.readUnsignedInt(2)
self.scaleType = self.readUnsignedInt(2)
self.fontID = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine("font width (twips): %d"%self.fontWidth)
self.appendLine("font height (twips): %d"%self.fontHeight)
self.appendLine("default font height (twips): %d"%self.defaultHeight)
if self.scaleType == 0:
s = "chart area"
else:
s = "plot area"
self.appendLine("scale by: %s"%s)
self.appendLine("font ID: %d"%self.fontID)
def dumpData(self):
self.__parseBytes()
return ('fbi', {'font-width': self.fontWidth,
'font-height': self.fontHeight,
'default-height': self.defaultHeight,
'scale-type': self.scaleType,
'font-id': self.fontID})
class FilePass(BaseRecordHandler):
def parseBytes (self):
mode = self.readUnsignedInt(2) # mode: 0 = BIFF5 1 = BIFF8
self.readUnsignedInt(2) # ignore 2 bytes.
subMode = self.readUnsignedInt(2) # submode: 1 = standard encryption 2 = strong encryption
modeName = 'unknown'
if mode == 0:
modeName = 'BIFF5'
elif mode == 1:
modeName = 'BIFF8'
encType = 'unknown'
if subMode == 1:
encType = 'standard'
elif subMode == 2:
encType = 'strong'
self.appendLine("mode: %s"%modeName)
self.appendLine("encryption type: %s"%encType)
self.appendLine("")
self.appendMultiLine("NOTE: Since this document appears to be encrypted, the dumper will not parse the record contents from this point forward.")
class FilterMode(BaseRecordHandler):
def parseBytes (self):
self.appendMultiLine("NOTE: The presence of this record indicates that the sheet has a filtered list.")
class Format(BaseRecordHandler):
def __parseBytes (self):
self.numfmtID = self.readUnsignedInt(2)
self.code = self.readUnicodeString()
def parseBytes (self):
self.__parseBytes()
self.appendLine("index: %d"%self.numfmtID)
self.appendLine("code: %s"%globals.encodeName(self.code))
class Formula(BaseRecordHandler):
def __parseBytes (self):
self.row = self.readUnsignedInt(2)
self.col = self.readUnsignedInt(2)
self.xf = self.readUnsignedInt(2)
self.fval = self.readDouble()
flag = self.readUnsignedInt(2)
self.recalc = (flag & 0x0001) != 0 # A
reserved = (flag & 0x0002) != 0 # B
self.fillAlignment = (flag & 0x0004) != 0 # C
self.sharedFormula = (flag & 0x0008) != 0 # D
reserved = (flag & 0x0010) != 0 # E
self.clearErrors = (flag & 0x0020) != 0 # F
self.appCacheInfo = self.readUnsignedInt(4) # used only for app-specific optimization. Ignore it for now.
tokenSize = self.readUnsignedInt(2)
self.tokens = self.readBytes(tokenSize)
def parseBytes (self):
self.__parseBytes()
fparser = formula.FormulaParser(self.header, self.tokens)
try:
fparser.parse()
ftext = fparser.getText()
except formula.FormulaParserError as e:
ftext = "(Error: %s)"%e.args[0]
self.appendCellPosition(self.col, self.row)
self.appendLine("XF record ID: %d"%self.xf)
self.appendLine("formula result: %g"%self.fval)
self.appendLineBoolean("recalculate always", self.recalc)
self.appendLineBoolean("fill or center across selection", self.fillAlignment)
self.appendLineBoolean("shared formula", self.sharedFormula)
self.appendLineBoolean("clear errors", self.clearErrors)
self.appendLine("formula bytes: %s"%globals.getRawBytes(self.tokens, True, False))
self.appendLine("formula string: "+ftext)
def fillModel (self, model):
self.__parseBytes()
sheet = model.getCurrentSheet()
cell = xlsmodel.FormulaCell()
cell.tokens = self.tokens
cell.cachedResult = self.fval
sheet.setCell(self.col, self.row, cell)
class HorBreaks(BaseRecordHandler):
"""Stores all horizontal breaks in a sheet."""
def __parseBytes (self):
self.count = self.readUnsignedInt(2)
self.breaks = []
for i in xrange(0, self.count):
row = self.readUnsignedInt(2)
col1 = self.readUnsignedInt(2)
col2 = self.readUnsignedInt(2)
self.breaks.append((row, col1, col2))
def parseBytes (self):
self.__parseBytes()
self.appendLine("count: %d"%self.count)
for i in xrange(0, self.count):
self.appendLine("break: (row: %d; colums: %d-%d)"%self.breaks[i])
class Array(BaseRecordHandler):
def __parseBytes (self):
self.ref = RefU(self)
flag = self.readUnsignedInt(2)
self.alwaysCalc = (flag & 0x0001) != 0
unused = self.readBytes(4)
tokenSize = self.readUnsignedInt(2)
self.tokens = self.readBytes(tokenSize)
def parseBytes (self):
self.__parseBytes()
self.appendLine("range: %s"%self.ref.toString())
self.appendLineBoolean("always calc", self.alwaysCalc)
self.appendLine("formula bytes: %s"%globals.getRawBytes(self.tokens, True, False))
try:
fparser = formula.FormulaParser(self.header, self.tokens)
fparser.parse()
self.appendLine("formula string: %s"%fparser.getText())
except formula.FormulaParserError:
self.appendLine("formula string: <error parsing token bytes>")
class Label(BaseRecordHandler):
def __parseBytes (self):
self.col = self.readUnsignedInt(2)
self.row = self.readUnsignedInt(2)
self.xfIdx = self.readUnsignedInt(2)
textLen = self.readUnsignedInt(2)
self.text, textLen = globals.getRichText(self.readRemainingBytes(), textLen)
def parseBytes (self):
self.__parseBytes()
self.appendCellPosition(self.col, self.row)
self.appendLine("XF record ID: %d"%self.xfIdx)
self.appendLine("label text: %s"%self.text)
def dumpData(self):
self.__parseBytes()
return ('label', {'col': self.col,
'row': self.row,
'xf-idx': self.xfIdx,
'text': self.text})
class LabelSST(BaseRecordHandler):
def __parseBytes (self):
self.row = self.readUnsignedInt(2)
self.col = self.readUnsignedInt(2)
self.xfIdx = self.readUnsignedInt(2)
self.strId = self.readUnsignedInt(4)
def parseBytes (self):
self.__parseBytes()
self.appendCellPosition(self.col, self.row)
self.appendLine("XF record ID: %d"%self.xfIdx)
self.appendLine("string ID in SST: %d"%self.strId)
def fillModel (self, model):
self.__parseBytes()
sheet = model.getCurrentSheet()
cell = xlsmodel.LabelCell()
cell.strID = self.strId
sheet.setCell(self.col, self.row, cell)
class MulRK(BaseRecordHandler):
class RKRec(object):
def __init__ (self):
self.xfIdx = None # XF record index
self.number = None # RK number
def __parseBytes (self):
self.row = self.readUnsignedInt(2)
self.col1 = self.readUnsignedInt(2)
self.rkrecs = []
rkCount = (self.getSize() - self.getCurrentPos() - 2) / 6
for i in xrange(0, rkCount):
rec = MulRK.RKRec()
rec.xfIdx = self.readUnsignedInt(2)
rec.number = self.readUnsignedInt(4)
self.rkrecs.append(rec)
self.col2 = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine("row: %d"%self.row)
self.appendLine("columns: %d - %d"%(self.col1, self.col2))
for rkrec in self.rkrecs:
self.appendLine("XF record ID: %d"%rkrec.xfIdx)
self.appendLine("RK number: %g"%decodeRK(rkrec.number))
def fillModel (self, model):
self.__parseBytes()
sheet = model.getCurrentSheet()
n = len(self.rkrecs)
for i in xrange(0, n):
rkrec = self.rkrecs[i]
col = self.col1 + i
cell = xlsmodel.NumberCell(decodeRK(rkrec.number))
sheet.setCell(col, self.row, cell)
class MulBlank(BaseRecordHandler):
def __parseBytes (self):
self.row = self.readUnsignedInt(2)
self.col1 = self.readUnsignedInt(2)
self.col2 = -1
self.xfCells = []
while True:
val = self.readUnsignedInt(2)
if self.isEndOfRecord():
self.col2 = val
break
self.xfCells.append(val)
def parseBytes (self):
self.__parseBytes()
self.appendLine("row: %d"%self.row)
self.appendLine("columns: %d-%d"%(self.col1, self.col2))
s = "XF Record IDs:"
for xfCell in self.xfCells:
s += " %d"%xfCell
self.appendMultiLine(s)
class Number(BaseRecordHandler):
def __parseBytes (self):
self.row = self.readSignedInt(2)
self.col = self.readSignedInt(2)
self.xf = self.readSignedInt(2)
self.fval = self.readDouble()
def parseBytes (self):
self.__parseBytes()
self.appendCellPosition(self.col, self.row)
self.appendLine("XF record ID: %d"%self.xf)
self.appendLine("value: %g"%self.fval)
def dumpData(self):
self.__parseBytes()
return ('number', {'row': self.row,
'col': self.col,
'xf': self.xf,
'fval': self.fval})
class Obj(BaseRecordHandler):
ftEnd = 0x00 # End of OBJ record
# 0x01 - 0x03 (reserved)
ftMacro = 0x04 # Fmla-style macro
ftButton = 0x05 # Command button
ftGmo = 0x06 # Group marker
ftCf = 0x07 # Clipboard format
ftPioGrbit = 0x08 # Picture option flags
ftPictFmla = 0x09 # Picture fmla-style macro
ftCbls = 0x0A # Check box link
ftRbo = 0x0B # Radio button
ftSbs = 0x0C # Scroll bar
ftNts = 0x0D # Note structure
ftSbsFmla = 0x0E # Scroll bar fmla-style macro
ftGboData = 0x0F # Group box data
ftEdoData = 0x10 # Edit control data
ftRboData = 0x11 # Radio button data
ftCblsData = 0x12 # Check box data
ftLbsData = 0x13 # List box data
ftCblsFmla = 0x14 # Check box link fmla-style macro
ftCmo = 0x15 # Common object data
class Cmo:
Types = [
'Group', # 0x00
'Line', # 0x01
'Rectangle', # 0x02
'Oval', # 0x03
'Arc', # 0x04
'Chart', # 0x05
'Text', # 0x06
'Button', # 0x07
'Picture', # 0x08
'Polygon', # 0x09
'(Reserved)', # 0x0A
'Check box', # 0x0B
'Option button', # 0x0C
'Edit box', # 0x0D
'Label', # 0x0E
'Dialog box', # 0x0F
'Spinner', # 0x10
'Scroll bar', # 0x11
'List box', # 0x12
'Group box', # 0x13
'Combo box', # 0x14
'(Reserved)', # 0x15
'(Reserved)', # 0x16
'(Reserved)', # 0x17
'(Reserved)', # 0x18
'Comment', # 0x19
'(Reserved)', # 0x1A
'(Reserved)', # 0x1B
'(Reserved)', # 0x1C
'(Reserved)', # 0x1D
'Microsoft Office drawing' # 0x1E
]
@staticmethod
def getType (typeID):
if len(Obj.Cmo.Types) > typeID:
return Obj.Cmo.Types[typeID]
return "(unknown) (0x%2.2X)"%typeID
def parseBytes (self):
while not self.isEndOfRecord():
fieldType = self.readUnsignedInt(2)
fieldSize = self.readUnsignedInt(2)
if fieldType == Obj.ftEnd:
# reached the end of OBJ record.
return
if fieldType == Obj.ftCmo:
self.parseCmo(fieldSize)
else:
fieldBytes = self.readBytes(fieldSize)
self.appendLine("field 0x%2.2X: %s"%(fieldType, globals.getRawBytes(fieldBytes, True, False)))
def parseCmo (self, size):
if size != 18:
# size of Cmo must be 18. Something is wrong here.
self.readBytes(size)
globals.error("parsing of common object field in OBJ failed due to invalid size.")
return
objType = self.readUnsignedInt(2)
objID = self.readUnsignedInt(2)
flag = self.readUnsignedInt(2)
# the rest of the bytes are reserved & should be all zero.
unused1 = self.readUnsignedInt(4)
unused2 = self.readUnsignedInt(4)
unused3 = self.readUnsignedInt(4)
self.appendLine("common object: ")
self.appendLine(" type: %s (0x%2.2X)"%(Obj.Cmo.getType(objType), objType))
self.appendLine(" object ID: %d"%objID)
# 0 0001h fLocked =1 if the object is locked when the sheet is protected
# 3-1 000Eh (Reserved) Reserved; must be 0 (zero)
# 4 0010h fPrint =1 if the object is printable
# 12-5 1FE0h (Reserved) Reserved; must be 0 (zero)
# 13 2000h fAutoFill =1 if the object uses automatic fill style
# 14 4000h fAutoLine =1 if the object uses automatic line style
# 15 8000h (Reserved) Reserved; must be 0 (zero)
locked = (flag & 0x0001) != 0 # A
# B
defaultSize = (flag & 0x0004) != 0 # C
published = (flag & 0x0008) != 0 # D
printable = (flag & 0x0010) != 0 # E
# F
# G
disabled = (flag & 0x0080) != 0 # H
UIObj = (flag & 0x0100) != 0 # I
recalcObj = (flag & 0x0200) != 0 # J
# K
# L
recalcObjAlways = (flag & 0x1000) != 0 # M
autoFill = (flag & 0x2000) != 0 # N
autoLine = (flag & 0x4000) != 0 # O
self.appendLineBoolean(" locked", locked)
self.appendLineBoolean(" default size", defaultSize)
self.appendLineBoolean(" printable", printable)
self.appendLineBoolean(" automatic fill style", autoFill)
self.appendLineBoolean(" automatic line style", autoLine)
class PlotGrowth(BaseRecordHandler):
def __parseBytes (self):
self.dx = self.readFixedPoint()
self.dy = self.readFixedPoint()
def parseBytes (self):
self.__parseBytes()
self.appendLine("horizontal growth: %g"%self.dx)
self.appendLine("vertical growth: %g"%self.dy)
def dumpData(self):
self.__parseBytes()
return ('plot-growth', {'dx': self.dx,
'dy': self.dy})
class PrintSize(BaseRecordHandler):
Types = [
"unchanged from the defaults in the workbook",
"resized non-proportionally to fill the entire page",
"resized proportionally to fill the entire page",
"size defined in the chart record"
]
def __parseBytes (self):
self.typeID = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine(globals.getValueOrUnknown(PrintSize.Types, self.typeID))
def dumpData(self):
self.__parseBytes()
return ('print-size', {'type-id': self.typeID})
class Protect(BaseRecordHandler):
def __parseBytes (self):
self.locked = self.readUnsignedInt(2) != 0
def parseBytes (self):
self.__parseBytes()
self.appendLineBoolean("workbook locked", self.locked)
def dumpData(self):
self.__parseBytes()
return ('protect', {'locked': self.locked})
class RK(BaseRecordHandler):
"""Cell with encoded integer or floating-point value"""
def __parseBytes (self):
self.row = globals.getSignedInt(self.bytes[0:2])
self.col = globals.getSignedInt(self.bytes[2:4])
self.xf = globals.getSignedInt(self.bytes[4:6])
rkval = globals.getSignedInt(self.bytes[6:10])
self.auxData = RKAuxData()
self.realVal = decodeRK(rkval, self.auxData)
def parseBytes (self):
self.__parseBytes()
self.appendCellPosition(self.col, self.row)
self.appendLine("XF record ID: %d"%self.xf)
self.appendLine("multiplied by 100: %d"%self.auxData.multi100)
if self.auxData.signedInt:
self.appendLine("type: signed integer")
else:
self.appendLine("type: floating point")
self.appendLine("value: %g"%self.realVal)
def fillModel (self, model):
self.__parseBytes()
sheet = model.getCurrentSheet()
cell = xlsmodel.NumberCell(self.realVal)
sheet.setCell(self.col, self.row, cell)
class Scl(BaseRecordHandler):
def __parseBytes (self):
self.numerator = self.readSignedInt(2)
self.denominator = self.readSignedInt(2)
def parseBytes (self):
self.__parseBytes()
val = 0.0 # force the value to be treated as double precision.
val += self.numerator
val /= self.denominator
self.appendLine("zoom level: %g"%val)
def dumpData(self):
self.__parseBytes()
return ('scl', {'numer': self.numerator,
'denom': self.denominator})
class SeriesText(BaseRecordHandler):
def __parseBytes (self):
self.readBytes(2) # must be zero, ignored.
self.text = self.readShortXLUnicodeString()
def parseBytes (self):
self.__parseBytes()
self.appendLine("text: '%s'"%self.text)
class String(BaseRecordHandler):
"""Cached string formula result for preceding formula record."""
def __parseBytes (self):
strLen = globals.getSignedInt(self.bytes[0:1])
self.name, byteLen = globals.getRichText(self.bytes[2:], strLen)
def parseBytes (self):
self.__parseBytes()
self.appendLine("string value: '%s'"%self.name)
def fillModel (self, model):
self.__parseBytes()
cell = model.getCurrentSheet().getLastCell()
if cell.modelType == xlsmodel.CellBase.Type.Formula:
cell.cachedResult = self.name
class Style(BaseRecordHandler):
BuiltInStyleNames = [
"Normal",
"RowLevel_#",
"ColLevel_#",
"Comma",
"Currency",
"Percent",
"Comma[0]",
"Currency[0]",
"Hyperlink",
"Followed Hyperlink",
"Note",
"Warning Text"
]
def __parseBytes (self):
flags = self.readUnsignedInt(2)
self.Xf = (flags & 0x0FFF)
self.builtIn = (flags & 0x8000) != 0
self.builtInType = self.readUnsignedInt(1)
self.builtInLevel = self.readUnsignedInt(1)
def parseBytes (self):
self.__parseBytes()
self.appendLine("XF record ID: %d"%self.Xf)
self.appendLineBoolean("built-in", self.builtIn)
if self.builtIn:
self.appendLine("built-in type: %d (%s)"%(
self.builtInType, globals.getValueOrUnknown(Style.BuiltInStyleNames, self.builtInType)))
if self.builtInType == 1 or self.builtInType == 2:
self.appendLine("built-in level: %d"%self.builtInLevel)
class SST(BaseRecordHandler):
def __parseBytes (self):
self.refCount = self.readSignedInt(4) # total number of references in workbook
self.strCount = self.readSignedInt(4) # total number of unique strings.
self.sharedStrings = []
for i in xrange(0, self.strCount):
extText, bytesRead = globals.getUnicodeRichExtText(self.bytes, self.getCurrentPos(), self.roflist)
self.readBytes(bytesRead) # advance current position.
self.sharedStrings.append(extText)
def parseBytes (self):
self.__parseBytes()
self.appendLine("total number of references: %d"%self.refCount)
self.appendLine("total number of unique strings: %d"%self.strCount)
i = 0
for s in self.sharedStrings:
self.appendLine("s%d: %s"%(i, globals.encodeName(s.baseText)))
i += 1
def fillModel (self, model):
self.__parseBytes()
wbg = model.getWorkbookGlobal()
for sst in self.sharedStrings:
wbg.appendSharedString(sst)
class Blank(BaseRecordHandler):
def parseBytes (self):
row = globals.getSignedInt(self.bytes[0:2])
col = globals.getSignedInt(self.bytes[2:4])
xf = globals.getSignedInt(self.bytes[4:6])
self.appendCellPosition(col, row)
self.appendLine("XF record ID: %d"%xf)
class DBCell(BaseRecordHandler):
def parseBytes (self):
rowRecOffset = self.readUnsignedInt(4)
self.appendLine("offset to first ROW record: %d"%rowRecOffset)
while not self.isEndOfRecord():
cellOffset = self.readUnsignedInt(2)
self.appendLine("offset to CELL record: %d"%cellOffset)
return
class DefColWidth(BaseRecordHandler):
def parseBytes (self):
w = self.readUnsignedInt(2)
self.appendLine("default column width (in characters): %d"%w)
class DefRowHeight(BaseRecordHandler):
def __parseBytes (self):
flag = self.readUnsignedInt(1)
self.readUnsignedInt(1) # ignore 1 byte.
self.unsynced = (flag & 0x01) != 0
self.dyZero = (flag & 0x02) != 0
self.exAsc = (flag & 0x04) != 0
self.exDsc = (flag & 0x08) != 0
self.rowHeight = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLineBoolean("default row height settings changed", self.unsynced)
self.appendLineBoolean("empty rows have a height of zero", self.dyZero)
self.appendLineBoolean("empty rows have a thick border style at top", self.exAsc)
self.appendLineBoolean("empty rows have a thick border style at bottom", self.exDsc)
if self.dyZero:
self.appendLine("default height for hidden rows: %d"%self.rowHeight)
else:
self.appendLine("default height for empty rows: %d"%self.rowHeight)
class ColInfo(BaseRecordHandler):
def parseBytes (self):
colFirst = self.readUnsignedInt(2)
colLast = self.readUnsignedInt(2)
coldx = self.readUnsignedInt(2)
ixfe = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
isHidden = (flags & 0x0001)
outlineLevel = (flags & 0x0700)/4
isCollapsed = (flags & 0x1000)/4
self.appendLine("formatted columns: %d - %d"%(colFirst,colLast))
self.appendLine("column width (in 1/256s of a char): %d"%coldx)
self.appendLine("XF record index: %d"%ixfe)
self.appendLine("hidden: %s"%self.getYesNo(isHidden))
self.appendLine("outline level: %d"%outlineLevel)
self.appendLine("collapsed: %s"%self.getYesNo(isCollapsed))
class Row(BaseRecordHandler):
def __parseBytes (self):
self.row = self.readUnsignedInt(2)
self.col1 = self.readUnsignedInt(2)
self.col2 = self.readUnsignedInt(2)
flag = self.readUnsignedInt(2)
self.rowHeight = (flag & 0x7FFF)
self.defaultHeight = ((flag & 0x8000) != 0)
self.irwMac = self.readUnsignedInt(2)
dummy = self.readUnsignedInt(2)
flag = self.readUnsignedInt(2)
self.outLevel = (flag & 0x0007)
self.collapsed = (flag & 0x0010)
self.zeroHeight = (flag & 0x0020)
self.unsynced = (flag & 0x0040)
self.ghostDirty = (flag & 0x0080)
def parseBytes (self):
self.__parseBytes()
self.appendLine("row: %d; col: %d - %d"%(self.row, self.col1, self.col2))
self.appendLine("row height (twips): %d"%self.rowHeight)
if self.defaultHeight:
self.appendLine("row height type: default")
else:
self.appendLine("row height type: custom")
self.appendLine("optimize flag (0 for BIFF): %d"%self.irwMac)
self.appendLine("outline level: %d"%self.outLevel)
self.appendLine("collapsed: %s"%self.getYesNo(self.collapsed))
self.appendLine("zero height: %s"%self.getYesNo(self.zeroHeight))
self.appendLine("unsynced: %s"%self.getYesNo(self.unsynced))
self.appendLine("ghost dirty: %s"%self.getYesNo(self.ghostDirty))
def fillModel (self, model):
self.__parseBytes()
sh = model.getCurrentSheet()
# store whether or not this row is hidden.
if self.zeroHeight:
sh.setRowHidden(self.row)
sh.setRowHeight(self.row, self.rowHeight)
class Name(BaseRecordHandler):
"""Internal defined name (aka Lbl)"""
builtInNames = [
"Consolidate_Area", # 0x00
"Auto_Open ", # 0x01
"Auto_Close ", # 0x02
"Extract ", # 0x03
"Database ", # 0x04
"Criteria ", # 0x05
"Print_Area ", # 0x06
"Print_Titles ", # 0x07
"Recorder ", # 0x08
"Data_Form ", # 0x09
"Auto_Activate ", # 0x0A
"Auto_Deactivate ", # 0x0B
"Sheet_Title ", # 0x0C
"_FilterDatabase " # 0x0D
]
funcCategories = [
'All', # 00
'Financial', # 01
'DateTime', # 02
'MathTrigonometry', # 03
'Statistical', # 04
'Lookup', # 05
'Database', # 06
'Text', # 07
'Logical', # 08
'Info', # 09
'Commands', # 10
'Customize', # 11
'MacroControl', # 12
'DDEExternal', # 13
'UserDefined', # 14
'Engineering', # 15
'Cube' # 16
]
@staticmethod
def getBuiltInName (name):
return globals.getValueOrUnknown(Name.builtInNames, ord(name[0]))
@staticmethod
def getFuncCategory (val):
return globals.getValueOrUnknown(Name.funcCategories, val)
def __writeOptionFlags (self):
self.appendLine("option flags:")
if self.isHidden:
self.appendLine(" hidden")
else:
self.appendLine(" visible")
if self.isMacroName:
self.appendLine(" macro name")
if self.isFuncMacro:
self.appendLine(" function macro")
self.appendLine(" function group: %d"%self.funcGrp)
else:
self.appendLine(" command macro")
if self.isVBMacro:
self.appendLine(" visual basic macro")
else:
self.appendLine(" sheet macro")
else:
self.appendLine(" standard name")
if self.isComplFormula:
self.appendLine(" complex formula - can return an array")
else:
self.appendLine(" simple formula")
if self.isBuiltinName:
self.appendLine(" built-in name")
else:
self.appendLine(" user-defined name")
self.appendLineBoolean(" published", self.isPublished)
self.appendLineBoolean(" workbook parameter", self.isWorkbookParam)
def __parseBytes (self):
flag = self.readUnsignedInt(2)
self.isHidden = (flag & 0x0001) != 0
self.isFuncMacro = (flag & 0x0002) != 0
self.isVBMacro = (flag & 0x0004) != 0
self.isMacroName = (flag & 0x0008) != 0
self.isComplFormula = (flag & 0x0010) != 0
self.isBuiltinName = (flag & 0x0020) != 0
self.funcGrp = (flag & 0x0FC0) / 64
reserved = (flag & 0x1000) != 0
self.isPublished = (flag & 0x2000) != 0
self.isWorkbookParam = (flag & 0x4000) != 0
reserved = (flag & 0x8000) != 0
self.keyShortCut = self.readUnsignedInt(1)
nameLen = self.readUnsignedInt(1)
self.formulaLen = self.readUnsignedInt(2)
self.readUnsignedInt(2) # 2-bytes reserved
# 1-based index into the sheets in the current book, where the list is
# arranged by the visible order of the tabs.
self.sheetId = self.readUnsignedInt(2)
# these optional texts may come after the formula token bytes.
# NOTE: [MS-XLS] spec says these bytes are reserved and to be ignored.
self.menuTextLen = self.readUnsignedInt(1)
self.descTextLen = self.readUnsignedInt(1)
self.helpTextLen = self.readUnsignedInt(1)
self.statTextLen = self.readUnsignedInt(1)
pos = self.getCurrentPos()
self.name, byteLen = globals.getRichText(self.bytes[pos:], nameLen)
self.readBytes(byteLen)
self.tokenBytes = self.readBytes(self.formulaLen)
def parseBytes (self):
self.__parseBytes()
self.appendLine("name: %s"%globals.encodeName(self.name))
# is this name global or sheet-local?
s = "global or local: "
if self.sheetId == 0:
s += "global"
else:
s += "local (1-based sheet ID = %d)"%self.sheetId
self.appendLine(s)
if self.isBuiltinName:
self.appendLine("built-in name: %s"%Name.getBuiltInName(self.name))
self.appendLine("function category: %s (%d)"%(Name.getFuncCategory(self.funcGrp), self.funcGrp))
self.__writeOptionFlags()
# self.appendLine("menu text length: %d"%self.menuTextLen)
# self.appendLine("description length: %d"%self.descTextLen)
# self.appendLine("help tip text length: %d"%self.helpTextLen)
# self.appendLine("status bar text length: %d"%self.statTextLen)
tokenText = globals.getRawBytes(self.tokenBytes, True, False)
o = formula.FormulaParser(self.header, self.tokenBytes)
self.appendLine("formula length: %d"%self.formulaLen)
self.appendLine("formula bytes: " + tokenText)
try:
o.parse()
formulaText = o.getText()
self.appendLine("formula: " + formulaText)
except formula.FormulaParserError as e:
self.appendLine("Error while parsing the formula tokens (%s)"%e.args[0])
def fillModel (self, model):
self.__parseBytes()
wbg = model.getWorkbookGlobal()
if self.isBuiltinName and len(self.name) == 1 and ord(self.name[0]) == 0x0D:
# Pick up a database range for autofilter.
wbg.setFilterRange(self.sheetId-1, self.tokenBytes)
class SupBook(BaseRecordHandler):
"""Supporting workbook"""
class Type:
Self = 0x0401
AddIn = 0x3A01
def __parseBytes (self):
self.ctab = self.readUnsignedInt(2)
self.sbType = self.readUnsignedInt(2)
if self.sbType > 0x00FF or self.sbType == 0x0000:
return
self.names = []
isFirst = True
self.moveBack(2)
pos = self.getCurrentPos()
while pos < self.size:
ret, bytesLen = globals.getUnicodeRichExtText(self.bytes, pos)
name = ret.baseText
self.moveForward(bytesLen)
self.names.append(name)
pos = self.getCurrentPos()
def parseBytes (self):
self.__parseBytes()
if self.sbType == SupBook.Type.Self:
# self-referencing supbook
self.appendLine("type: self-referencing")
self.appendLine("sheet name count: %d"%self.ctab)
return
if self.sbType == SupBook.Type.AddIn:
self.appendLine("type: add-in referencing")
self.appendMultiLine("Add-in function name stored in the following EXTERNNAME record.")
return
self.appendLine("sheet name count: %d"%self.ctab)
if len(self.names) == 0:
return
self.appendLine("document URL: %s"%globals.encodeName(self.names[0]))
for name in self.names[1:]:
name = globals.encodeName(name)
self.appendLine("sheet name: %s"%name)
def fillModel (self, model):
self.__parseBytes()
wbg = model.getWorkbookGlobal()
if self.sbType == SupBook.Type.Self:
sb = xlsmodel.SupbookSelf(self.ctab)
wbg.appendSupbook(sb)
elif self.sbType == SupBook.Type.AddIn:
# generic supbook instance just to keep the indices in sync.
wbg.appendSupbook(xlsmodel.Supbook())
else:
# external document supbook
sb = xlsmodel.SupbookExternal()
sb.docURL = self.names[0]
for name in self.names[1:]:
sb.appendSheetName(name)
wbg.appendSupbook(sb)
class ExternSheet(BaseRecordHandler):
def __parseBytes (self):
self.sheets = []
num = self.readUnsignedInt(2)
for i in xrange(0, num):
book = self.readUnsignedInt(2)
sheet1 = self.readUnsignedInt(2)
sheet2 = self.readUnsignedInt(2)
self.sheets.append((book, sheet1, sheet2))
def parseBytes (self):
self.__parseBytes()
for sh in self.sheets:
self.appendLine("SUPBOOK record ID: %d (sheet ID range: %d - %d)"%(sh[0], sh[1], sh[2]))
def fillModel (self, model):
self.__parseBytes()
wbg = model.getWorkbookGlobal()
for sh in self.sheets:
wbg.appendExternSheet(sh[0], sh[1], sh[2])
class ExternName(BaseRecordHandler):
class MOper(object):
Errors = {
0x00: '#NULL!' ,
0x07: '#DIV/0!',
0x0F: '#VALUE!',
0x17: '#REF!' ,
0x1D: '#NAME?' ,
0x24: '#NUM!' ,
0x2A: '#N/A'
}
def __init__ (self, bytes):
self.strm = globals.ByteStream(bytes)
def parse (self):
self.lastCol = self.strm.readUnsignedInt(1)
self.lastRow = self.strm.readUnsignedInt(2)
self.values = []
n = (self.lastCol+1)*(self.lastRow+1)
for i in xrange(0, n):
# parse each value
oc = self.strm.readUnsignedInt(1)
if oc == 0x01:
# number
val = self.strm.readDouble()
self.values.append(val)
elif oc == 0x02:
# string
s = self.strm.readUnicodeString()
self.values.append(s)
elif oc == 0x04:
# boolean
b = self.strm.readUnsignedInt(1) != 0
self.strm.readBytes(7)
self.values.append(b)
elif oc == 0x10:
# error
err = self.strm.readUnsignedInt(1)
self.strm.readBytes(7)
self.values.append(err)
else:
# null value
self.strm.readBytes(8)
self.values.append(None)
def output (self, hdl):
hdl.appendLine("last column: %d"%self.lastCol)
hdl.appendLine("last row: %d"%self.lastRow)
for value in self.values:
if type(value) == type(0.0):
hdl.appendLine("value: %g"%value)
elif type(value) == type("s"):
hdl.appendLine("value: %s"%value)
elif type(value) == type(True):
hdl.appendLine("value: %d (boolean)"%value)
elif type(value) == type(1):
# error code stored as an integer.
if ExternName.MOper.Errors.has_key(value):
hdl.appendLine("value: %s"%ExternName.MOper.Errors[value])
else:
hdl.appendLine("value: 0x%2.2X (unknown error)"%value)
else:
hdl.appendLine("value: (unknown)")
def __parseBytes (self):
flag = self.readUnsignedInt(2)
self.isBuiltinName = (flag & 0x0001) != 0
self.automatic = (flag & 0x0002) != 0
self.wantPict = (flag & 0x0004) != 0
self.isOLE = (flag & 0x0008) != 0
self.isOLELink = (flag & 0x0010) != 0
# 5 - 14 bits stores last successful clip format
self.clipFormat = (flag & 0x7FE0) / 2**5
self.displayAsIcon = (flag & 0x8000) != 0
if self.isOLELink:
# next 4 bytes are 32-bit storage ID
self.storageID = self.readUnsignedInt(4)
nameLen = self.readUnsignedInt(1)
self.name = self.readUnicodeString(nameLen)
self.moper = self.readRemainingBytes()
else:
# assume external defined name (could be DDE link).
# TODO: differentiate DDE link from external defined name.
self.supbookID = self.readUnsignedInt(2)
reserved = self.readUnsignedInt(2)
nameLen = self.readUnsignedInt(1)
self.name = self.readUnicodeString(nameLen)
self.tokens = self.readRemainingBytes()
def parseBytes (self):
self.__parseBytes()
self.appendLineBoolean("built-in name", self.isBuiltinName)
self.appendLineBoolean("auto DDE or OLE", self.automatic)
self.appendLineBoolean("use picture format", self.wantPict)
self.appendLineBoolean("OLE", self.isOLE)
self.appendLineBoolean("OLE Link", self.isOLELink)
self.appendLine("clip format: %d"%self.clipFormat)
self.appendLineBoolean("display as icon", self.displayAsIcon)
if self.isOLELink:
self.appendLine("type: OLE")
self.appendLine("storage ID: 0x%4.4X"%self.storageID)
self.appendLine("name: %s"%self.name)
if len(self.moper) > 0:
try:
parser = ExternName.MOper(self.moper)
parser.parse()
parser.output(self)
except:
self.appendLine("Error while parsing the moper bytes.")
else:
# TODO: Test this.
self.appendLine("type: defined name")
if self.supbookID == 0:
self.appendLine("sheet ID: 0 (global defined names)")
else:
self.appendLine("sheet ID: %d"%self.supbookID)
self.appendLine("name: %s"%self.name)
tokenText = globals.getRawBytes(self.tokens, True, False)
self.appendLine("formula bytes: %s"%tokenText)
# parse formula tokens
o = formula.FormulaParser(self.header, self.tokens)
o.parse()
ftext = o.getText()
self.appendLine("formula: %s"%ftext)
class Xct(BaseRecordHandler):
def __parseBytes (self):
self.crnCount = self.readSignedInt(2)
self.sheetIndex = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine("CRN count: %d"%self.crnCount)
self.appendLine("index of referenced sheet in the SUPBOOK record: %d"%self.sheetIndex)
def fillModel (self, model):
self.__parseBytes()
sb = model.getWorkbookGlobal().getLastSupbook()
# this must be an external document supbook.
if sb.type != xlsmodel.Supbook.Type.External:
return
sb.setCurrentSheet(self.sheetIndex)
class Crn(BaseRecordHandler):
def __parseBytes (self):
self.lastCol = self.readUnsignedInt(1)
self.firstCol = self.readUnsignedInt(1)
self.rowIndex = self.readUnsignedInt(2)
self.cells = []
for i in xrange(0, self.lastCol-self.firstCol+1):
typeId = self.readUnsignedInt(1)
if typeId == 0x00:
# empty value
self.readBytes(8)
self.cells.append((typeId, None))
elif typeId == 0x01:
# number
val = self.readDouble()
self.cells.append((typeId, val))
elif typeId == 0x02:
# string
pos = self.getCurrentPos()
ret, length = globals.getUnicodeRichExtText(self.bytes, pos)
text = ret.baseText
text = globals.encodeName(text)
self.moveForward(length)
self.cells.append((typeId, text))
elif typeId == 0x04:
# boolean
val = self.readUnsignedInt(1)
self.readBytes(7) # next 7 bytes not used
self.cells.append((typeId, val))
elif typeId == 0x10:
# error value
val = self.readUnsignedInt(1)
self.readBytes(7) # next 7 bytes not used
self.cells.append((typeId, val))
else:
globals.error("error parsing CRN record\n")
sys.exit(1)
def parseBytes (self):
self.__parseBytes()
self.appendLine("first column: %d"%self.firstCol)
self.appendLine("last column: %d"%self.lastCol)
self.appendLine("row index: %d"%self.rowIndex)
for cell in self.cells:
typeId, val = cell[0], cell[1]
if typeId == 0x00:
# empty value
self.appendLine("* empty value")
elif typeId == 0x01:
# number
self.appendLine("* numeric value (%g)"%val)
elif typeId == 0x02:
# string
self.appendLine("* string value (%s)"%val)
elif typeId == 0x04:
# boolean
self.appendLine("* boolean value (%d)"%val)
elif typeId == 0x10:
# error value
self.appendLine("* error value (%d)"%val)
else:
error("error parsing CRN record\n")
sys.exit(1)
def fillModel (self, model):
self.__parseBytes()
sb = model.getWorkbookGlobal().getLastSupbook()
# this must be an external document supbook.
if sb.type != xlsmodel.Supbook.Type.External:
return
cache = sb.getCurrentSheetCache()
for col in xrange(self.firstCol, self.lastCol+1):
cell = self.cells[col-self.firstCol]
typeId, val = cell[0], cell[1]
cache.setValue(self.rowIndex, col, typeId, val)
class RefreshAll(BaseRecordHandler):
def parseBytes (self):
boolVal = globals.getSignedInt(self.bytes[0:2])
strVal = "no"
if boolVal:
strVal = "yes"
self.appendLine("refresh all external data ranges and pivot tables: %s"%strVal)
class Hyperlink(BaseRecordHandler):
def parseBytes (self):
rowFirst = self.readUnsignedInt(2)
rowLast = self.readUnsignedInt(2)
colFirst = self.readUnsignedInt(2)
colLast = self.readUnsignedInt(2)
# Rest of the stream stores undocumented hyperlink stream. Refer to
# page 128 of MS Excel binary format spec.
self.appendLine("rows: %d - %d"%(rowFirst, rowLast))
self.appendLine("columns: %d - %d"%(colFirst, colLast))
msg = "NOTE: The stream after the first 8 bytes stores undocumented hyperlink stream. "
msg += "Refer to page 128 of the MS Excel binary format spec."
self.appendLine('')
self.appendMultiLine(msg)
class PhoneticInfo(BaseRecordHandler):
phoneticType = [
'narrow Katakana', # 0x00
'wide Katakana', # 0x01
'Hiragana', # 0x02
'any type' # 0x03
]
@staticmethod
def getPhoneticType (flag):
return globals.getValueOrUnknown(PhoneticInfo.phoneticType, flag)
alignType = [
'general alignment', # 0x00
'left aligned', # 0x01
'center aligned', # 0x02
'distributed alignment' # 0x03
]
@staticmethod
def getAlignType (flag):
return globals.getValueOrUnknown(PhoneticInfo.alignType, flag)
def parseBytes (self):
fontIdx = self.readUnsignedInt(2)
self.appendLine("font ID: %d"%fontIdx)
flags = self.readUnsignedInt(1)
# flags: 0 0 0 0 0 0 0 0
# | unused| B | A |
phType = (flags) & 0x03
alignType = (flags/4) & 0x03
self.appendLine("phonetic type: %s"%PhoneticInfo.getPhoneticType(phType))
self.appendLine("alignment: %s"%PhoneticInfo.getAlignType(alignType))
self.readUnsignedInt(1) # unused byte
# TODO: read cell ranges.
return
class Font(BaseRecordHandler):
fontFamilyNames = [
'not applicable', # 0x00
'roman', # 0x01
'swiss', # 0x02
'modern', # 0x03
'script', # 0x04
'decorative' # 0x05
]
@staticmethod
def getFontFamily (code):
return globals.getValueOrUnknown(Font.fontFamilyNames, code)
scriptNames = [
'normal script',
'superscript',
'subscript'
]
@staticmethod
def getScriptName (code):
return globals.getValueOrUnknown(Font.scriptNames, code)
underlineTypes = {
0x00: 'no underline',
0x01: 'single underline',
0x02: 'double underline',
0x21: 'single accounting',
0x22: 'double accounting'
}
@staticmethod
def getUnderlineStyleName (val):
return globals.getValueOrUnknown(Font.underlineTypes, val)
charSetNames = {
0x00: 'ANSI_CHARSET',
0x01: 'DEFAULT_CHARSET',
0x02: 'SYMBOL_CHARSET',
0x4D: 'MAC_CHARSET',
0x80: 'SHIFTJIS_CHARSET',
0x81: 'HANGEUL_CHARSET',
0x81: 'HANGUL_CHARSET',
0x82: 'JOHAB_CHARSET',
0x86: 'GB2312_CHARSET',
0x88: 'CHINESEBIG5_CHARSET',
0xA1: 'GREEK_CHARSET',
0xA2: 'TURKISH_CHARSET',
0xA3: 'VIETNAMESE_CHARSET',
0xB1: 'HEBREW_CHARSET',
0xB2: 'ARABIC_CHARSET',
0xBA: 'BALTIC_CHARSET',
0xCC: 'RUSSIAN_CHARSET',
0xDD: 'THAI_CHARSET',
0xEE: 'EASTEUROPE_CHARSET'
}
@staticmethod
def getCharSetName (code):
return globals.getValueOrUnknown(Font.charSetNames, code)
def parseBytes (self):
height = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
colorId = self.readUnsignedInt(2)
boldStyle = self.readUnsignedInt(2)
boldStyleName = '(unknown)'
if boldStyle == 400:
boldStyleName = 'normal'
elif boldStyle == 700:
boldStyleName = 'bold'
superSub = self.readUnsignedInt(2)
ulStyle = self.readUnsignedInt(1)
fontFamily = self.readUnsignedInt(1)
charSet = self.readUnsignedInt(1)
reserved = self.readUnsignedInt(1)
nameLen = self.readUnsignedInt(1)
fontName, nameLen = globals.getRichText(self.readRemainingBytes(), nameLen)
self.appendLine("font height: %d"%height)
self.appendLine("color ID: %d"%colorId)
self.appendLine("bold style: %s (%d)"%(boldStyleName, boldStyle))
self.appendLine("script type: %s"%Font.getScriptName(superSub))
self.appendLine("underline type: %s"%Font.getUnderlineStyleName(ulStyle))
self.appendLine("character set: %s"%Font.getCharSetName(charSet))
self.appendLine("font family: %s"%Font.getFontFamily(fontFamily))
self.appendLine("font name: %s (%d)"%(fontName, nameLen))
class Window2(BaseRecordHandler):
def __parseBytes (self):
flag = self.readUnsignedInt(2)
self.displayFormula = (flag & 0x0001) != 0
self.displayGrid = (flag & 0x0002) != 0
self.displayHeadings = (flag & 0x0004) != 0
self.frozen = (flag & 0x0008) != 0
def parseBytes (self):
self.__parseBytes()
self.appendLineBoolean("display formula", self.displayFormula)
self.appendLineBoolean("display grid", self.displayGrid)
self.appendLineBoolean("display headings", self.displayHeadings)
self.appendLineBoolean("frozen window", self.frozen)
class Pane(BaseRecordHandler):
activePanes = [
"bottom-right",
"top-right",
"bottom-left",
"top-left"
]
def __parseBytes (self):
self.x = self.readUnsignedInt(2)
self.y = self.readUnsignedInt(2)
self.bottomRow = self.readUnsignedInt(2)
self.rightCol = self.readUnsignedInt(2)
self.activePane = self.readUnsignedInt(1)
def parseBytes (self):
self.__parseBytes()
self.appendLine("split position: (x=%d,y=%d)"%(self.x,self.y))
self.appendLine("top-left position of SE pane: (row=%d,col=%d)"%
(self.bottomRow,self.rightCol))
self.appendLine("active pane: %s"%
globals.getValueOrUnknown(Pane.activePanes, self.activePane))
class XF(BaseRecordHandler):
horAlignTypes = [
'', # 0x00
'left alignment', # ALCLEFT 0x01
'centered alignment', # ALCCTR 0x02
'right alignment', # ALCRIGHT 0x03
'fill alignment', # ALCFILL 0x04
'justify alignment', # ALCJUST 0x05
'center-across-selection alignment', # ALCCONTCTR 0x06
'distributed alignment', # ALCDIST 0x07
'alignment not specified' # ALCNIL 0xFF
]
vertAlignTypes = [
'top alignment', # ALCVTOP 0x00
'center alignment', # ALCVCTR 0x01
'bottom alignment', # ALCVBOT 0x02
'justify alignment', # ALCVJUST 0x03
'distributed alignment' # ALCVDIST 0x04
]
readOrderTypes = [
'context', # READING_ORDER_CONTEXT 0x00
'left-to-right', # READING_ORDER_LTR 0x01
'right-to-left' # READING_ORDER_RTL 0x02
]
borderStyles = [
['NONE','No border'], # 0x0000
['THIN','Thin line'], # 0x0001
['MEDIUM','Medium line'], # 0x0002
['DASHED','Dashed line'], # 0x0003
['DOTTED','Dotted line'], # 0x0004
['THICK','Thick line'], # 0x0005
['DOUBLE','Double line'], # 0x0006
['HAIR','Hairline'], # 0x0007
['MEDIUMDASHED','Medium dashed line'], # 0x0008
['DASHDOT','Dash-dot line'], # 0x0009
['MEDIUMDASHDOT','Medium dash-dot line'], # 0x000A
['DASHDOTDOT','Dash-dot-dot line'], # 0x000B
['MEDIUMDASHDOTDOT','Medium dash-dot-dot line'], # 0x000C
['SLANTDASHDOT','Slanted dash-dot-dot line'] # 0x000D
]
@staticmethod
def printBorderStyle (val):
if val >= len(XF.borderStyles):
return '(unknown)'
return "%s - %s (0x%2.2X)"%(XF.borderStyles[val][0], XF.borderStyles[val][1], val)
class XFBase(object):
def __init__ (self):
pass
def parseHeaderBytes (self, strm):
byte = strm.readUnsignedInt(1)
self.horAlign = (byte & 0x07)
self.wrapText = (byte & 0x08) != 0
self.verAlign = (byte & 0x70) / (2**4)
self.distributed = (byte & 0x80) != 0
self.textRotation = strm.readUnsignedInt(1)
byte = strm.readUnsignedInt(1)
self.indentLevel = (byte & 0x0F)
self.shrinkToFit = (byte & 0x10) != 0
self.readOrder = (byte & 0xC0) / (2**6)
def parseBorderStyles (self, strm):
byte = strm.readUnsignedInt(1)
self.leftBdrStyle = (byte & 0x0F)
self.rightBdrStyle = (byte & 0xF0) / (2**4)
byte = strm.readUnsignedInt(1)
self.topBdrStyle = (byte & 0x0F)
self.bottomBdrStyle = (byte & 0xF0) / (2**4)
class CellXF(XFBase):
def __init__ (self):
pass
def parseBytes (self, strm):
self.parseHeaderBytes(strm)
byte = strm.readUnsignedInt(1)
self.atrNum = (byte & 0x04) != 0
self.atrFnt = (byte & 0x08) != 0
self.atrAlc = (byte & 0x10) != 0
self.atrBdr = (byte & 0x20) != 0
self.atrPat = (byte & 0x40) != 0
self.atrProt = (byte & 0x80) != 0
self.parseBorderStyles(strm)
class CellStyleXF(XFBase):
def __init__ (self):
pass
def parseBytes (self, strm):
self.parseHeaderBytes(strm)
strm.readUnsignedInt(1) # skip 1 byte.
self.parseBorderStyles(strm)
byte = strm.readUnsignedInt(2)
self.leftColor = (byte & 0x007F) # 7-bits
self.rightColor = (byte & 0x0780) / (2**7) # 7-bits
self.diagBorder = (byte & 0xC000) / (2**14) # 2-bits
def __parseBytes (self):
self.fontId = self.readUnsignedInt(2)
self.numId = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
self.locked = (flags & 0x0001) != 0
self.hidden = (flags & 0x0002) != 0
self.style = (flags & 0x0004) != 0
self.prefix = (flags & 0x0008) != 0
# ID of cell style XF record which it inherits styles from. Should be
# 0xFFF it the style flag is on.
self.cellStyleXFIndex = (flags & 0xFFF0) / (2**4)
if self.style:
self.data = XF.CellStyleXF()
self.data.parseBytes(self)
else:
self.data = XF.CellXF()
self.data.parseBytes(self)
def parseBytes (self):
self.__parseBytes()
if self.style:
self.appendLine("parent style ID: 0x%2.2X (should be 0xFFF for cell style XF)"%self.cellStyleXFIndex)
else:
self.appendLine("parent style ID: %d"%self.cellStyleXFIndex)
self.appendLine("font ID: %d"%self.fontId)
self.appendLine("number format ID: %d"%self.numId)
self.appendLineBoolean("locked protection", self.locked)
self.appendLineBoolean("hidden protection", self.hidden)
self.appendLineBoolean("prefix characters present", self.prefix)
s = "cell XF"
if self.style:
s = "cell style XF"
self.appendLine("stored data type: " + s)
# common data between cell XF and cell style XF
# Horizontal alignment
horAlignName = globals.getValueOrUnknown(
XF.horAlignTypes[:-1], self.data.horAlign, 'not specified')
self.appendLine("horizontal alignment: %s (0x%2.2X)"%(horAlignName, self.data.horAlign))
self.appendLineBoolean("distributed", self.data.distributed)
self.appendLineBoolean("wrap text", self.data.wrapText)
# Vertical alignment
verAlignName = globals.getValueOrUnknown(
XF.vertAlignTypes, self.data.verAlign, 'unknown')
self.appendLine("vertical alignment: %s (0x%2.2X)"%(verAlignName, self.data.verAlign))
# Text rotation
s = "text rotation: "
if self.data.textRotation == 0xFF:
s += "vertical"
elif self.data.textRotation >= 0 and self.data.textRotation <= 90:
s += "%d degrees (counterclockwise)"%self.data.textRotation
elif self.data.textRotation > 90 and self.data.textRotation <= 180:
s += "%d degrees (clockwise)"%(self.data.textRotation - 90)
self.appendLine(s)
self.appendLine("indent level: %d"%self.data.indentLevel)
self.appendLineBoolean("shrink to fit", self.data.shrinkToFit)
self.appendLine("reading order: %s"%globals.getValueOrUnknown(XF.readOrderTypes, self.data.readOrder))
self.appendLine("border style (l): %s"%XF.printBorderStyle(self.data.leftBdrStyle))
self.appendLine("border style (r): %s"%XF.printBorderStyle(self.data.rightBdrStyle))
self.appendLine("border style (t): %s"%XF.printBorderStyle(self.data.topBdrStyle))
self.appendLine("border style (b): %s"%XF.printBorderStyle(self.data.bottomBdrStyle))
if self.style:
# cell style XF data
pass
else:
# cell XF data
pass
class FeatureHeader(BaseRecordHandler):
"""Beginning of a collection of records."""
def parseBytes (self):
recordType = self.readUnsignedInt(2)
frtFlag = self.readUnsignedInt(2) # currently 0
self.readBytes(8) # reserved (currently all 0)
featureTypeId = self.readUnsignedInt(2)
featureTypeText = 'unknown'
if featureTypeId == 2:
featureTypeText = 'enhanced protection'
elif featureTypeId == 3:
featureTypeText = 'ignored formula errors'
elif featureTypeId == 4:
featureTypeText = 'smart tag'
featureHdr = self.readUnsignedInt(1) # must be 1
sizeHdrData = self.readSignedInt(4)
sizeHdrDataText = 'byte size'
if sizeHdrData == -1:
sizeHdrDataText = 'size depends on feature type'
self.appendLine("record type: 0x%4.4X (must match the header)"%recordType)
self.appendLine("feature type: %d (%s)"%(featureTypeId, featureTypeText))
self.appendLine("size of header data: %d (%s)"%(sizeHdrData, sizeHdrDataText))
if featureTypeId == 2 and sizeHdrData == -1:
# enhanced protection options
flags = self.readUnsignedInt(4)
self.appendLine("enhanced protection flag: 0x%8.8X"%flags)
optEditObj = (flags & 0x00000001)
optEditScenario = (flags & 0x00000002)
optFormatCells = (flags & 0x00000004)
optFormatColumns = (flags & 0x00000008)
optFormatRows = (flags & 0x00000010)
optInsertColumns = (flags & 0x00000020)
optInsertRows = (flags & 0x00000040)
optInsertLinks = (flags & 0x00000080)
optDeleteColumns = (flags & 0x00000100)
optDeleteRows = (flags & 0x00000200)
optSelectLockedCells = (flags & 0x00000400)
optSort = (flags & 0x00000800)
optUseAutofilter = (flags & 0x00001000)
optUsePivotReports = (flags & 0x00002000)
optSelectUnlockedCells = (flags & 0x00004000)
self.appendLine(" edit object: %s"%self.getEnabledDisabled(optEditObj))
self.appendLine(" edit scenario: %s"%self.getEnabledDisabled(optEditScenario))
self.appendLine(" format cells: %s"%self.getEnabledDisabled(optFormatCells))
self.appendLine(" format columns: %s"%self.getEnabledDisabled(optFormatColumns))
self.appendLine(" format rows: %s"%self.getEnabledDisabled(optFormatRows))
self.appendLine(" insert columns: %s"%self.getEnabledDisabled(optInsertColumns))
self.appendLine(" insert rows: %s"%self.getEnabledDisabled(optInsertRows))
self.appendLine(" insert hyperlinks: %s"%self.getEnabledDisabled(optInsertLinks))
self.appendLine(" delete columns: %s"%self.getEnabledDisabled(optDeleteColumns))
self.appendLine(" delete rows: %s"%self.getEnabledDisabled(optDeleteRows))
self.appendLine(" select locked cells: %s"%self.getEnabledDisabled(optSelectLockedCells))
self.appendLine(" sort: %s"%self.getEnabledDisabled(optSort))
self.appendLine(" use autofilter: %s"%self.getEnabledDisabled(optUseAutofilter))
self.appendLine(" use pivot table reports: %s"%self.getEnabledDisabled(optUsePivotReports))
self.appendLine(" select unlocked cells: %s"%self.getEnabledDisabled(optSelectUnlockedCells))
return
class FeatureData(BaseRecordHandler):
def parseBytes (self):
recordType = self.readUnsignedInt(2)
frtFlag = self.readUnsignedInt(2) # currently 0
self.readBytes(8) # reserved (currently all 0)
featureTypeId = self.readUnsignedInt(2)
featureTypeText = 'unknown'
if featureTypeId == 2:
featureTypeText = 'enhanced protection'
elif featureTypeId == 3:
featureTypeText = 'ignored formula errors'
elif featureTypeId == 4:
featureTypeText = 'smart tag'
self.readBytes(1) # reserved1, must be 0
self.readBytes(4) # reserved2, must be 0
cref = self.readUnsignedInt(2)
cbFeatData = self.readUnsignedInt(4)
cbFeatDataText = 'byte size'
self.readBytes(2) # reserved3, must be 0
refs = []
for i in xrange(0, cref):
refs.append(Ref8U(self))
self.appendLine("record type: 0x%4.4X (must match the header)"%recordType)
self.appendLine("feature type: %d (%s)"%(featureTypeId, featureTypeText))
self.appendLine("size of feature data: %d (%s)"%(cbFeatData, cbFeatDataText))
if featureTypeId == 2:
# enhanced protection, ISFPROTECTION, FeatProtection structure
Areserved = self.readUnsignedInt(4)
wPassword = self.readUnsignedInt(4)
stTitle = self.readXLUnicodeString()
self.appendLine("A and reserved: 0x%8.8X"%Areserved)
self.appendLine("wPassword: 0x%8.8X"%wPassword)
self.appendLine("stTitle: %s"%stTitle)
if Areserved & 0x00000001 == 0x00000001:
# SDContainer
cbSD = self.readUnsignedInt(4)
self.appendLine("cbSD: %d"%cbSD)
self.readBytes(cbSD)
elif featureTypeId == 3 and cbFeatData > 0:
# ignored formula errors, ISFFEC2, FeatFormulaErr2 structure
self.readBytes(cbFeatData)
self.appendLine("FeatFormulaErr2 not handled")
elif featureTypeId == 4:
# smart tag, ISFFACTOID, FeatSmartTag structure
self.appendLine("FeatSmartTag not handled")
for ref in refs:
self.appendLine("applied to range: (col=%d,row=%d) - (col=%d,row=%d)"%
(ref.col1, ref.row1, ref.col2, ref.row2))
return
class ShrFmla(BaseRecordHandler):
def __parseBytes (self):
self.ref = RefU(self)
self.readBytes(1) # 8-bits reserved
self.cUse = self.readUnsignedInt(1)
lenFormula = self.readUnsignedInt(2)
self.tokens = self.readBytes(lenFormula)
def parseBytes (self):
self.__parseBytes()
self.appendLine("range: %s"%self.ref.toString())
self.appendLine("cell count: %d"%self.cUse)
self.appendLine("formula token length: %d"%len(self.tokens))
if len(self.tokens):
ftext = None
try:
parser = formula.FormulaParser(self.header, self.tokens)
parser.parse(formula.ParsedFormulaType.Shared)
ftext = parser.getText()
except formula.FormulaParserError as e:
ftext = "(Error: %s)"%e.args[0]
if ftext != None:
self.appendLine("formula: %s"%ftext)
# -------------------------------------------------------------------
# SX - Pivot Table
class FrtFlags(object):
def __init__ (self, strm):
grbitFrt = strm.readUnsignedInt(2)
self.fFrtRef = (grbitFrt & 0x0001) # record specifies a range of cells
self.fFrtAlert = (grbitFrt & 0x0002) # whether to alert the user of possible problems when saving the file
def appendLines (self, hdl):
pass
class XLUnicodeStringSegmentedSXAddl(object):
def __init__ (self, strm):
self.cchTotal = strm.readUnsignedInt(4)
strm.readBytes(2) # ignored
def appendLines (self, hdl):
if self.cchTotal <= 65535:
hdl.appendLineInt("cchTotal", self.cchTotal)
class DConName(BaseRecordHandler):
def __parseBytes (self):
self.rangeName = self.readUnicodeString()
self.flag = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine("defined name: %s"%self.rangeName)
if self.flag == 0:
self.appendMultiLine("This defined name has a workbook scope and is contained in this file.")
else:
# The additional bytes contain info about the workbook and
# worksheet where the defined name is located. We don't handle
# this yet.
pass
class DConRef(BaseRecordHandler):
def __parseBytes (self):
self.ref = RefU(self)
textLen = self.readUnsignedInt(2)
bytes = self.bytes[self.pos:]
text, byteLen = globals.getRichText(bytes, textLen)
self.sheetName = globals.encodeName(text)
def parseBytes (self):
self.__parseBytes()
self.appendLine("range: %s"%self.ref.toString())
self.appendLine("sheet name: %s"%self.sheetName)
class SxIvd(BaseRecordHandler):
def __parseBytes (self):
self.ids = []
n = self.getSize() / 2
for i in xrange(0, n):
self.ids.append(self.readSignedInt(2))
def parseBytes (self):
self.__parseBytes()
for id in self.ids:
if id == -2:
self.appendLine("pivot field index: %d (data layout field)"%id)
else:
self.appendLineInt("pivot field index", id)
self.appendLine("")
self.appendMultiLine("NOTE: The first one of this record is for row fields, whereas the second one is for column fields.")
class SXViewEx9(BaseRecordHandler):
def parseBytes (self):
rt = self.readUnsignedInt(2)
dummy = self.readBytes(6)
flags = self.readUnsignedInt(4)
autoFmtId = self.readUnsignedInt(2)
self.appendLine("record type: %4.4Xh (always 0x0810)"%rt)
self.appendLine("autoformat index: %d"%autoFmtId)
nameLen = self.readSignedInt(2)
if nameLen > 0:
name, nameLen = globals.getRichText(self.readRemainingBytes(), nameLen)
self.appendLine("grand total name: %s"%name)
else:
self.appendLine("grand total name: (none)")
return
class SXAddlInfo(BaseRecordHandler):
SxcClassList = {
0x00: 'sxcView',
0x01: 'sxcField',
0x02: 'sxcHierarchy',
0x03: 'sxcCache',
0x04: 'sxcCacheField',
0x05: 'sxcQsi',
0x06: 'sxcQuery',
0x07: 'sxcGrpLevel',
0x08: 'sxcGroup',
0x09: 'sxcCacheItem',
0x0C: 'sxcSxrule',
0x0D: 'sxcSxfilt',
0x10: 'sxcSxdh',
0x12: 'sxcAutoSort',
0x13: 'sxcSxmgs',
0x14: 'sxcSxmg',
0x17: 'sxcField12',
0x1A: 'sxcSxcondfmts',
0x1B: 'sxcSxcondfmt',
0x1C: 'sxcSxfilters12',
0x1D: 'sxcSxfilter12'
}
SxcViewTypes = {
0x00: 'sxdId',
0x01: 'sxdVerUpdInv',
0x02: 'sxdVer10Info',
0x03: 'sxdCalcMember',
0x0A: 'sxdCalcMemString',
0x19: 'sxdVer12Info',
0x1E: 'sxdTableStyleClient',
0x21: 'sxdCompactRwHdr',
0x22: 'sxdCompactColHdr',
0x26: 'sxdSxpiIvmb',
0xFF: 'sxdEnd'
}
def __parseBytes (self):
self.flags = FrtFlags(self) # ignored
self.sxc = self.readUnsignedInt(1)
self.sxd = self.readUnsignedInt(1)
if self.sxc == 0x00:
# SxcView
self.__parseBytesView()
def __parseBytesView (self):
assert(self.sxc == 0x00)
if self.sxd == 0x00:
# sxdId
self.__parseSxcViewSxdId()
def __parseSxcViewSxdId (self):
self.stName = XLUnicodeStringSegmentedSXAddl(self)
def parseBytes (self):
self.__parseBytes()
self.appendLineString("classs name", globals.getValueOrUnknown(SXAddlInfo.SxcClassList, self.sxc))
if self.sxc == 0x00:
# SxcView
self.appendLineString("record type", globals.getValueOrUnknown(SXAddlInfo.SxcViewTypes, self.sxd))
if self.sxd == 0x00:
# sxdId
self.stName.appendLines(self)
class SXDb(BaseRecordHandler):
def parseBytes (self):
recCount = self.readUnsignedInt(4)
strmId = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
self.appendLine("number of records in database: %d"%recCount)
self.appendLine("stream ID: %4.4Xh"%strmId)
# self.appendLine("flags: %4.4Xh"%flags)
saveLayout = (flags & 0x0001)
invalid = (flags & 0x0002)
refreshOnLoad = (flags & 0x0004)
optimizeCache = (flags & 0x0008)
backQuery = (flags & 0x0010)
enableRefresh = (flags & 0x0020)
self.appendLine("save data with table layout: %s"%self.getYesNo(saveLayout))
self.appendLine("invalid table (must be refreshed before next update): %s"%self.getYesNo(invalid))
self.appendLine("refresh table on load: %s"%self.getYesNo(refreshOnLoad))
self.appendLine("optimize cache for least memory use: %s"%self.getYesNo(optimizeCache))
self.appendLine("query results obtained in the background: %s"%self.getYesNo(backQuery))
self.appendLine("refresh is enabled: %s"%self.getYesNo(enableRefresh))
dbBlockRecs = self.readUnsignedInt(2)
baseFields = self.readUnsignedInt(2)
allFields = self.readUnsignedInt(2)
self.appendLine("number of records for each database block: %d"%dbBlockRecs)
self.appendLine("number of base fields: %d"%baseFields)
self.appendLine("number of all fields: %d"%allFields)
dummy = self.readBytes(2)
type = self.readUnsignedInt(2)
typeName = '(unknown)'
if type == 1:
typeName = 'Excel worksheet'
elif type == 2:
typeName = 'External data'
elif type == 4:
typeName = 'Consolidation'
elif type == 8:
typeName = 'Scenario PivotTable'
self.appendLine("type: %s (%d)"%(typeName, type))
textLen = self.readUnsignedInt(2)
changedBy, textLen = globals.getRichText(self.readRemainingBytes(), textLen)
self.appendLine("changed by: %s"%changedBy)
class SXDBB(BaseRecordHandler):
def __parseBytes (self):
self.items = []
for fld in self.strmData.pivotCacheFields:
if fld.hasMoreThan255:
# read 2 bytes
idx = self.readUnsignedInt(2)
else:
idx = self.readUnsignedInt(1)
s = fld.values[idx]
self.items.append(s)
def parseBytes (self):
self.__parseBytes()
for item in self.items:
self.appendLine(item)
class SXDbEx(BaseRecordHandler):
def parseBytes (self):
lastChanged = self.readDouble()
sxFmlaRecs = self.readUnsignedInt(4)
self.appendLine("last changed: %g"%lastChanged)
self.appendLine("count of SXFORMULA records for this cache: %d"%sxFmlaRecs)
class SXEx(BaseRecordHandler):
def __parseBytes (self):
self.csxformat = self.readUnsignedInt(2)
self.cchErrorString = self.readUnsignedInt(2)
self.cchNullString = self.readUnsignedInt(2)
self.cchTag = self.readUnsignedInt(2)
self.csxselect = self.readUnsignedInt(2)
self.crwPage = self.readUnsignedInt(2)
self.ccolPage = self.readUnsignedInt(2)
flag = self.readUnsignedInt(2)
# Page field layout
# 0 = top to bottom then left to right
# 1 = left to right then top to bottom
self.fAcrossPageLay = (flag & 0x0001)
# Rows in each page field column
self.cWrapPage = (flag & 0x01FE) / 2
flag = self.readUnsignedInt(2)
self.fEnableWizard = (flag & 0x0001) != 0 # D
self.fEnableDrilldown = (flag & 0x0002) != 0 # E
self.fEnableFieldDialog = (flag & 0x0004) != 0 # F
self.fPreserveFormatting = (flag & 0x0008) != 0 # G
self.fMergeLabels = (flag & 0x0010) != 0 # H
self.fDisplayErrorString = (flag & 0x0020) != 0 # I
self.fDisplayNullString = (flag & 0x0040) != 0 # J
self.fSubtotalHiddenPageItems = (flag & 0x0080) != 0 # K
self.cchPageFieldStyle = self.readUnsignedInt(2)
self.cchTableStyle = self.readUnsignedInt(2)
self.cchVacateStyle = self.readUnsignedInt(2)
self.stError = ""
if self.cchErrorString != 0xFFFF:
self.stError = self.readXLUnicodeStringNoCch(self.cchErrorString)
self.stDisplayNull = ""
if self.cchNullString != 0xFFFF:
self.stDisplayNull = self.readXLUnicodeStringNoCch(self.cchNullString)
self.stTag = ""
if self.cchTag != 0xFFFF:
self.stTag = self.readXLUnicodeStringNoCch(self.cchTag)
self.stPageFieldStyle = ""
if self.cchPageFieldStyle != 0xFFFF and self.cchPageFieldStyle > 0:
self.stPageFieldStyle = self.readXLUnicodeStringNoCch(self.cchPageFieldStyle)
self.stTableStyle = ""
if self.cchTableStyle != 0xFFFF and self.cchTableStyle > 0:
self.stTableStyle = self.readXLUnicodeStringNoCch(self.cchTableStyle)
self.stVacateStyle = ""
if self.cchVacateStyle != 0xFFFF and self.cchVacateStyle > 0:
self.stVacateStyle = self.readXLUnicodeStringNoCch(self.cchVacateStyle)
def parseBytes (self):
self.__parseBytes()
self.appendLineInt("number of SxFormat records", self.csxformat)
self.appendLineString("error string", self.stError)
self.appendLineString("null string", self.stDisplayNull)
self.appendLineString("custom string", self.stTag)
self.appendLineString("style used in page area", self.stPageFieldStyle)
self.appendLineString("style used in table body", self.stTableStyle)
self.appendLineString("style used in empty cells", self.stVacateStyle)
if self.fAcrossPageLay:
self.appendLine("page area layout: left to right, then top to bottom")
else:
self.appendLine("page area layout: top to bottom, then left to right")
self.appendLineInt("rows in each page column", self.cWrapPage)
self.appendLineBoolean("enable wizard", self.fEnableWizard)
self.appendLineBoolean("enable drilldown", self.fEnableDrilldown)
self.appendLineBoolean("enable field properties dialog", self.fEnableFieldDialog)
self.appendLineBoolean("preserve formatting", self.fPreserveFormatting)
self.appendLineBoolean("merge labels", self.fMergeLabels)
self.appendLineBoolean("display custom error string", self.fDisplayErrorString)
self.appendLineBoolean("display custom empty string", self.fDisplayNullString)
self.appendLineBoolean("subtotal hidden page items", self.fSubtotalHiddenPageItems)
class SXDtr(BaseRecordHandler):
def __parseBytes (self):
self.yr = self.readUnsignedInt(2)
self.mon = self.readUnsignedInt(2)
self.dom = self.readUnsignedInt(1)
self.hr = self.readUnsignedInt(1)
self.min = self.readUnsignedInt(1)
self.sec = self.readUnsignedInt(1)
s = "%d-%d-%dT%2.2d-%2.2d-%2.2d"%(self.yr, self.mon, self.dom, self.hr, self.min, self.sec)
self.strmData.pivotCacheFields[-1].values.append(s)
def parseBytes (self):
self.__parseBytes()
self.appendLine("year (1900-9999) : %d"%self.yr)
self.appendLine("month (1-12) : %d"%self.mon)
self.appendLine("day of month (0-31) : %d"%self.dom)
self.appendLine("hour (0-23) : %d"%self.hr)
self.appendLine("minutes (0-59) : %d"%self.min)
self.appendLine("seconds (0-59) : %d"%self.sec)
self.appendLine("")
self.appendMultiLine("The month value must be 1 if the day of month value is 0.")
class SxDXF(BaseRecordHandler):
def __parseBytes (self):
self.dxf = DXFN12NoCB(self)
def parseBytes (self):
self.__parseBytes()
self.dxf.appendLines(self)
class SXFDBType(BaseRecordHandler):
types = {
0x0000: "SQL_TYPE_NULL",
0x0001: "SQL_CHAR",
0x0003: "SQL_DECIMAL",
0x0004: "SQL_INTEGER",
0x0005: "SQL_SMALLINT",
0x0006: "SQL_FLOAT",
0x0007: "SQL_REAL",
0x0008: "SQL_DOUBLE",
0x000B: "SQL_TIMESTAMP",
0x000C: "SQL_VARCHAR",
0xFFF9: "SQL_BIT",
0xFFFE: "SQL_BINARY"
}
def __parseBytes (self):
self.wTypeSql = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
s = globals.getValueOrUnknown(SXFDBType.types, self.wTypeSql)
self.appendLine("ODBC Type: %s"%s)
class SXFDB(BaseRecordHandler):
dataTypeNames = {
0x0000: 'spc',
0x0480: 'str',
0x0520: 'int[+dbl]',
0x0560: 'dbl',
0x05A0: 'str+int[+dbl]',
0x05E0: 'str+dbl',
0x0900: 'dat',
0x0D00: 'dat+int/dbl',
0x0D80: 'dat+str[+int/dbl]'
}
def __parseBytes (self):
# parse flag
bits = self.readUnsignedInt(2)
self.fAllAtoms = (bits & 0x0001) != 0 # A
self.fSomeUnhashed = (bits & 0x0002) != 0 # B (undefined, must be ignored)
self.fUsed = (bits & 0x0004) != 0 # C (undefined, must be ignored)
self.fHasParent = (bits & 0x0008) != 0 # D
self.fRangeGroup = (bits & 0x0010) != 0 # E
self.fNumField = (bits & 0x0020) != 0 # F
unused = (bits & 0x0040) != 0 # G (unused)
self.fTextEtcField = (bits & 0x0080) != 0 # H
self.fnumMinMaxValid = (bits & 0x0100) != 0 # I
self.fShortIitms = (bits & 0x0200) != 0 # J
self.fNonDates = (bits & 0x0400) != 0 # K
self.fDateInField = (bits & 0x0800) != 0 # L
unused = (bits & 0x1000) != 0 # M
self.fServerBased = (bits & 0x2000) != 0 # N
self.fCantGetUniqueItems = (bits & 0x4000) != 0 # O
self.fCalculatedField = (bits & 0x8000) != 0 # P
self.ifdbParent = self.readUnsignedInt(2)
self.ifdbBase = self.readUnsignedInt(2)
self.citmUnq = self.readUnsignedInt(2) # (undefined, must be ignored)
self.csxoper = self.readUnsignedInt(2)
self.cisxoper = self.readUnsignedInt(2)
self.catm = self.readUnsignedInt(2)
self.stFieldName = self.readXLUnicodeString()
if self.fAllAtoms:
# this cached field has a collection of items in the following
# SXDBB records.
obj = PivotField()
obj.hasMoreThan255 = self.fShortIitms
self.strmData.pivotCacheFields.append(obj)
def parseBytes (self):
self.__parseBytes()
self.appendLineBoolean("collection of items", self.fAllAtoms)
self.appendLineBoolean("has parent grouping cache field", self.fHasParent)
self.appendLineBoolean("numeric or date grouping", self.fRangeGroup)
self.appendLineBoolean("has numeric cache item", self.fNumField)
self.appendLineBoolean("has text data", self.fTextEtcField)
self.appendLineBoolean("min/max values can be computed", self.fnumMinMaxValid)
self.appendLineBoolean("has more than 255 items", self.fShortIitms)
self.appendLineBoolean("has non-date values", self.fNonDates)
self.appendLineBoolean("has date item", self.fDateInField)
self.appendLineBoolean("server-based page field (for ODBC PivotCache)", self.fServerBased)
self.appendLineBoolean("unique values unavailable (for ODBC source data)", self.fCantGetUniqueItems)
self.appendLineBoolean("calculated field", self.fCalculatedField)
self.appendLineInt("field index of parent (for grouped field)", self.ifdbParent)
self.appendLineInt("field index of base (for grouped field)", self.ifdbBase)
self.appendLineInt("number of cache items (for grouped field)", self.csxoper)
self.appendLineInt("number of cache items in base field (for grouped field)", self.cisxoper)
self.appendLineInt("number of cache items in collection", self.catm)
self.appendLineString("field name", self.stFieldName)
class SxFormat(BaseRecordHandler):
def __parseBytes (self):
flag = self.readUnsignedInt(2)
self.rlType = (flag & 0x000F) != 0
self.cbData = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLineBoolean("formatting applied", self.rlType)
self.appendLineInt("number of byts in next SxDXF", self.cbData)
class SXLI(BaseRecordHandler):
itemTypes = {
0x00: 'value in the data',
0x01: 'automatic subtotal selection',
0x02: 'SUM',
0x03: 'COUNTA',
0x04: 'COUNT',
0x05: 'AVERAGE',
0x06: 'MAX',
0x07: 'MIN',
0x08: 'PRODUCT',
0x09: 'STDEV',
0x0A: 'STDEVP',
0x0B: 'VAR',
0x0C: 'VARP',
0x0D: 'grand total',
0x0E: 'blank line'
}
class Item(object):
def __init__ (self, strm):
self.cSic = strm.readSignedInt(2)
flag = strm.readUnsignedInt(2)
self.itmType = (flag & 0x7FFF)
self.isxviMac = strm.readSignedInt(2)
flag = strm.readUnsignedInt(2)
self.fMultiDataName = (flag & 0x0001) != 0
self.iData = (flag & 0x01FE) / 2
self.fSbt = (flag & 0x0200) != 0
self.fBlock = (flag & 0x0400) != 0
self.fGrand = (flag & 0x0800) != 0
self.fMultiDataOnAxis = (flag & 0x1000) != 0
G = (flag & 0x2000) != 0 # unused
H = (flag & 0x4000) != 0 # unused
I = (flag & 0x8000) != 0 # reserved
self.rgisxvi = []
if self.isxviMac > 0:
for i in xrange(0, self.isxviMac):
id = strm.readSignedInt(2)
self.rgisxvi.append(id)
def appendLines (self, parent):
parent.appendLine("------------")
parent.appendLine(" pivot line")
parent.appendLine("------------")
parent.appendLineInt("pivot item index count", self.cSic)
parent.appendLineString("item type", globals.getValueOrUnknown(SXLI.itemTypes, self.itmType))
parent.appendLineInt("number of elements", self.isxviMac)
if self.fMultiDataName:
parent.appendLineString("data field name", "subtotal")
else:
parent.appendLineString("data field name", "total")
parent.appendLineInt("data item index", self.iData)
parent.appendLineBoolean("subtotal", self.fSbt)
parent.appendLineBoolean("block total", self.fBlock)
parent.appendLineBoolean("grand total", self.fGrand)
parent.appendLineBoolean("multi data on axis", self.fMultiDataOnAxis)
s = ""
first = True
for id in self.rgisxvi:
if first:
first = False
else:
s += ","
s += "%d"%id
parent.appendLineString("pivot line entry", s)
def __parseBytes (self):
self.items = []
while not self.isEndOfRecord():
obj = SXLI.Item(self)
self.items.append(obj)
def parseBytes (self):
self.__parseBytes()
for item in self.items:
item.appendLines(self)
class SXStreamID(BaseRecordHandler):
def parseBytes (self):
if self.size != 2:
return
strmId = globals.getSignedInt(self.bytes)
self.strmData.appendPivotCacheId(strmId)
self.appendLine("pivot cache stream ID in SX DB storage: %4.4X"%strmId)
class SxRule(BaseRecordHandler):
viewAreaTypes = [
"does not refer to any area.",
"refers to one or more pivot fields specified by SxFilt records that follow this record.",
"refers to cells displaying values of data items specified by SxFilt records that follow this record.",
"refers to the entire PivotTable view.",
"refers to the cells at the top-left of the PivotTable view, or at the top-right for a right-to-left sheet. For more information about this area, see Location and Body.",
"refers to a cell displaying a pivot field caption. The pivot field is specified by isxvd.",
"refers to the cells at the top-right of the PivotTable view, or at the top-left for a right-to-left sheet. For more information about this area, see Location and Body."
]
def __parseBytes (self):
self.iDim = self.readUnsignedInt(1)
self.isvxd = self.readUnsignedInt(1)
flag = self.readUnsignedInt(2)
self.sxaxisRw = (flag & 0x0001) != 0
self.sxaxisCol = (flag & 0x0002) != 0
self.sxaxisPage = (flag & 0x0004) != 0
self.sxaxisData = (flag & 0x0008) != 0
self.sxrType = (flag & 0x00F0) / (2**4)
flag /= 2**8 # shift 8 bits
self.fPart = (flag & 0x01) != 0
self.fDataOnly = (flag & 0x02) != 0
self.fLabelOnly = (flag & 0x04) != 0
self.fGrandRw = (flag & 0x08) != 0
self.fGrandCol = (flag & 0x10) != 0
self.fGrandRwSav = (flag & 0x20) != 0
self.fCacheBased = (flag & 0x40) != 0
self.fGrandColSav = (flag & 0x80) != 0
self.readBytes(2) # 2 bytes reserved
self.csxFilt = self.readUnsignedInt(2)
if not self.fPart:
return
# following should exist only when fPart is true
self.irwFirst = self.readUnsignedInt(1)
self.irwLast = self.readUnsignedInt(1)
self.icolFirst = self.readUnsignedInt(1)
self.icolLast = self.readUnsignedInt(1)
def parseBytes (self):
self.__parseBytes()
self.appendLineInt("pivot field position", self.iDim)
if self.isvxd <= 0xFD:
if self.fCacheBased:
self.appendLineInt("cache field index", self.isvxd)
else:
self.appendLineInt("pivot field index", self.isvxd)
elif self.isvxd == 0xFE:
self.appendLine("this record refers to data field")
elif self.isvxd == 0xFF:
if self.fCacheBased:
self.appendLine("cache fields specified by SxFilt records.")
else:
self.appendLine("pivot fields specified by SxFilt records.")
self.appendLineBoolean("references row axis", self.sxaxisRw)
self.appendLineBoolean("references column axis", self.sxaxisCol)
self.appendLineBoolean("references page axis", self.sxaxisPage)
self.appendLineBoolean("references value axis", self.sxaxisData)
self.appendMultiLine("view area type: " + globals.getValueOrUnknown(SxRule.viewAreaTypes, self.sxrType))
self.appendLineBoolean("this rule includes data cells only", self.fDataOnly)
self.appendLineBoolean("this rule includes labels only", self.fDataOnly)
self.appendLineBoolean("this rule includes grand total row", self.fGrandRw)
self.appendLineBoolean("this rule includes grand total column", self.fGrandCol)
self.appendLineBoolean("this rule previosly included grand total row", self.fGrandRwSav)
self.appendLineBoolean("this rule previosly included grand total column", self.fGrandColSav)
self.appendLineInt("number of SxFilt records", self.csxFilt)
if not self.fPart:
return
# following should exist only when fPart is true
self.appendLineInt("offset to first row", self.irwFirst)
self.appendLineInt("offset to last row", self.irwLast)
self.appendLineInt("offset to first column", self.icolFirst)
self.appendLineInt("offset to last column", self.icolLast)
class SXView(BaseRecordHandler):
def parseBytes (self):
rowFirst = self.readUnsignedInt(2)
rowLast = self.readUnsignedInt(2)
self.appendLine("row range: %d - %d"%(rowFirst, rowLast))
colFirst = self.readUnsignedInt(2)
colLast = self.readUnsignedInt(2)
self.appendLine("col range: %d - %d"%(colFirst,colLast))
rowHeadFirst = self.readUnsignedInt(2)
rowDataFirst = self.readUnsignedInt(2)
colDataFirst = self.readUnsignedInt(2)
self.appendLine("heading row: %d"%rowHeadFirst)
self.appendLine("data row: %d"%rowDataFirst)
self.appendLine("data col: %d"%colDataFirst)
cacheIndex = self.readUnsignedInt(2)
self.appendLine("cache index: %d"%cacheIndex)
self.readBytes(2)
dataFieldAxis = self.readUnsignedInt(2)
self.appendLine("default data field axis: %d"%dataFieldAxis)
dataFieldPos = self.readUnsignedInt(2)
self.appendLine("default data field pos: %d"%dataFieldPos)
numFields = self.readUnsignedInt(2)
numRowFields = self.readUnsignedInt(2)
numColFields = self.readUnsignedInt(2)
numPageFields = self.readUnsignedInt(2)
numDataFields = self.readUnsignedInt(2)
numDataRows = self.readUnsignedInt(2)
numDataCols = self.readUnsignedInt(2)
self.appendLine("field count: %d"%numFields)
self.appendLine("row field count: %d"%numRowFields)
self.appendLine("col field count: %d"%numColFields)
self.appendLine("page field count: %d"%numPageFields)
self.appendLine("data field count: %d"%numDataFields)
self.appendLine("data row count: %d"%numDataRows)
self.appendLine("data col count: %d"%numDataCols)
# option flags (TODO: display these later.)
flags = self.readUnsignedInt(2)
# autoformat index
autoFmtIndex = self.readUnsignedInt(2)
self.appendLine("autoformat index: %d"%autoFmtIndex)
nameLenTable = self.readUnsignedInt(2)
nameLenDataField = self.readUnsignedInt(2)
text, nameLenTable = globals.getRichText(self.readBytes(nameLenTable+1), nameLenTable)
self.appendLine("PivotTable name: %s"%text)
text, nameLenDataField = globals.getRichText(self.readBytes(nameLenDataField+1), nameLenDataField)
self.appendLine("data field name: %s"%text)
class SXViewSource(BaseRecordHandler):
def parseBytes (self):
if self.size != 2:
return
src = globals.getSignedInt(self.bytes)
srcType = 'unknown'
if src == 0x01:
srcType = 'internal range (followed by DConRef, DConName or DConBin)'
elif src == 0x02:
srcType = 'external data source (followed by DbQuery)'
elif src == 0x04:
srcType = 'multiple consolidation ranges (followed by SXTbl)'
elif src == 0x10:
srcType = 'scenario (temporary internal structure)'
self.appendLine("data source type: %s"%srcType)
class MergeCells(BaseRecordHandler):
def __parseBytes (self):
self.cmcs = self.readUnsignedInt(2)
self.rgref = []
for i in xrange(0, self.cmcs):
self.rgref.append(Ref8(self))
def parseBytes (self):
self.__parseBytes()
self.appendLine("%d merge ranges:"%self.cmcs)
i = 0
for ref in self.rgref:
i += 1
self.appendLine("%d: %s"%(i,ref.toString()))
class Sxvd(BaseRecordHandler):
def __parseBytes (self):
flag = self.readUnsignedInt(2)
self.sxaxisRw = (flag & 0x0001) != 0
self.sxaxisCol = (flag & 0x0002) != 0
self.sxaxisPage = (flag & 0x0004) != 0
self.sxaxisData = (flag & 0x0008) != 0
self.cSub = self.readUnsignedInt(2)
flag = self.readUnsignedInt(2)
self.fDefault = (flag & 0x0001) != 0 # A
self.fSum = (flag & 0x0002) != 0 # B
self.fCounta = (flag & 0x0004) != 0 # C
self.fAverage = (flag & 0x0008) != 0 # D
self.fMax = (flag & 0x0010) != 0 # E
self.fMin = (flag & 0x0020) != 0 # F
self.fProduct = (flag & 0x0040) != 0 # G
self.fCount = (flag & 0x0080) != 0 # H
self.fStdev = (flag & 0x0100) != 0 # I
self.fStdevp = (flag & 0x0200) != 0 # J
self.fVariance = (flag & 0x0400) != 0 # K
self.fVariancep = (flag & 0x0800) != 0 # L
self.cItm = self.readSignedInt(2)
cchName = self.readUnsignedInt(2)
self.stName = '(null)'
if cchName != 0xFFFF:
self.stName = self.readXLUnicodeStringNoCch(cchName)
def parseBytes (self):
self.__parseBytes()
self.appendLine("axes type")
self.appendLineBoolean(" row", self.sxaxisRw)
self.appendLineBoolean(" column", self.sxaxisCol)
self.appendLineBoolean(" page", self.sxaxisPage)
self.appendLineBoolean(" data", self.sxaxisData)
self.appendLineInt("subtotal count", self.cSub)
self.appendLineBoolean(" default", self.fDefault)
self.appendLineBoolean(" sum", self.fSum)
self.appendLineBoolean(" counta", self.fCounta)
self.appendLineBoolean(" average", self.fAverage)
self.appendLineBoolean(" max", self.fMax)
self.appendLineBoolean(" min", self.fMin)
self.appendLineBoolean(" product", self.fProduct)
self.appendLineBoolean(" count", self.fCount)
self.appendLineBoolean(" stdev", self.fStdev)
self.appendLineBoolean(" stdevp", self.fStdevp)
self.appendLineBoolean(" variance", self.fVariance)
self.appendLineBoolean(" variancep", self.fVariancep)
self.appendLineInt("number of SXVI records that follow", self.cItm)
self.appendLineString("caption", self.stName)
class SXViewFieldsEx(BaseRecordHandler):
def __parseBytes (self):
flag = self.readUnsignedInt(2)
self.showAllItems = (flag & 0x0001) != 0 # A
self.dragToRow = (flag & 0x0002) != 0 # B
self.dragToColumn = (flag & 0x0004) != 0 # C
self.dragToPage = (flag & 0x0008) != 0 # D
self.dragToHide = (flag & 0x0010) != 0 # E
self.disableDragToData = (flag & 0x0020) != 0 # F
reserved = (flag & 0x0040) != 0 # G
self.serverBased = (flag & 0x0080) != 0 # H
reserved = (flag & 0x0100) != 0 # I
self.autoSort = (flag & 0x0200) != 0 # J
self.ascendSort = (flag & 0x0400) != 0 # K
self.autoShow = (flag & 0x0800) != 0 # L
self.topAutoShow = (flag & 0x1000) != 0 # M
self.calculatedField = (flag & 0x2000) != 0 # N
self.insertPageBreaks = (flag & 0x4000) != 0 # O
self.hideNewItems = (flag & 0x8000) != 0 # P
flag = self.readUnsignedInt(1)
# skip the first 5 bits.
self.outlineForm = (flag & 0x20) != 0 # Q
self.insertBlankRow = (flag & 0x40) != 0 # R
self.subtotalAtTop = (flag & 0x80) != 0 # S
# number of items to show in auto show mode.
self.autoShowCount = self.readUnsignedInt(1)
self.autoSortItem = self.readSignedInt(2)
self.autoShowItem = self.readSignedInt(2)
self.numberFormat = self.readUnsignedInt(2)
nameLen = self.readUnsignedInt(2)
self.subName = None
if nameLen != 0xFFFF:
self.readBytes(8) # ignored
self.subName, byteLen = getRichText(self.readRemainingBytes(), nameLen)
def parseBytes (self):
self.__parseBytes()
self.appendLineBoolean("show all items", self.showAllItems)
self.appendLineBoolean("drag to row", self.dragToRow)
self.appendLineBoolean("drag to column", self.dragToColumn)
self.appendLineBoolean("drag to page", self.dragToPage)
self.appendLineBoolean("drag to hide", self.dragToHide)
self.appendLineBoolean("disable drag to data", self.disableDragToData)
self.appendLineBoolean("server based", self.serverBased)
self.appendLineBoolean("auto sort", self.autoSort)
self.appendLineBoolean("ascending sort", self.ascendSort)
self.appendLineBoolean("auto show", self.autoShow)
self.appendLineBoolean("top auto show", self.topAutoShow)
self.appendLineBoolean("calculated field", self.calculatedField)
self.appendLineBoolean("insert page breaks", self.insertPageBreaks)
self.appendLineBoolean("hide new items after refresh", self.hideNewItems)
self.appendLineBoolean("outline form", self.outlineForm)
self.appendLineBoolean("insert blank row", self.insertBlankRow)
self.appendLineBoolean("subtotal at top", self.subtotalAtTop)
self.appendLine("items to show in auto show: %d"%self.autoShowCount)
if self.autoSort:
if self.autoSortItem == -1:
self.appendLine("auto sort: sort by pivot items themselves")
else:
self.appendLine("auto sort: sort by data item %d"%self.autoSortItem)
if self.autoShow:
if self.autoShowItem == -1:
self.appendLine("auto show: not enabled")
else:
self.appendLine("auto show: use data item %d"%self.autoShowItem)
self.appendLine("number format: %d"%self.numberFormat)
if self.subName == None:
self.appendLine("aggregate function: none")
else:
self.appendLine("aggregate function: %s"%self.subName)
class SXDataItem(BaseRecordHandler):
functionType = {
0x00: 'sum',
0x01: 'count',
0x02: 'average',
0x03: 'max',
0x04: 'min',
0x05: 'product',
0x06: 'count nums',
0x07: 'stddev',
0x08: 'stddevp',
0x09: 'var',
0x0A: 'varp'
}
displayFormat = {
0x00: 'normal',
0x01: 'difference from',
0x02: 'percentage of',
0x03: 'perdentage difference from',
0x04: 'running total in',
0x05: 'percentage of row',
0x06: 'percentage of column',
0x07: 'percentage of total',
0x08: 'index'
}
def parseBytes (self):
isxvdData = self.readUnsignedInt(2)
funcIndex = self.readUnsignedInt(2)
# data display format
df = self.readUnsignedInt(2)
# index to the SXVD/SXVI records used by the data display format
sxvdIndex = self.readUnsignedInt(2)
sxviIndex = self.readUnsignedInt(2)
# index to the format table for this item
fmtIndex = self.readUnsignedInt(2)
# name
nameLen = self.readSignedInt(2)
name, nameLen = globals.getRichText(self.readRemainingBytes(), nameLen)
self.appendLine("field that this data item is based on: %d"%isxvdData)
funcName = '(unknown)'
if SXDataItem.functionType.has_key(funcIndex):
funcName = SXDataItem.functionType[funcIndex]
self.appendLine("aggregate function: %s"%funcName)
dfName = '(unknown)'
if SXDataItem.displayFormat.has_key(df):
dfName = SXDataItem.displayFormat[df]
self.appendLine("data display format: %s"%dfName)
self.appendLine("SXVD record index: %d"%sxvdIndex)
self.appendLine("SXVI record index: %d"%sxviIndex)
self.appendLine("format table index: %d"%fmtIndex)
if nameLen == -1:
self.appendLine("name: null (use name in the cache)")
else:
self.appendLine("name: %s"%name)
return
class SXPageItem(BaseRecordHandler):
class Item(object):
def __init__ (self, strm):
self.isxvd = strm.readSignedInt(2)
self.isxvi = strm.readSignedInt(2)
self.idObj = strm.readSignedInt(2)
def appendLines (self, parent):
parent.appendLine("item")
parent.appendLine(" field index: %d"%self.isxvd)
if self.isxvi == 0x7FFD:
parent.appendLine(" index of selected item: all")
else:
# Index of SXVI record, not of cache item in pivot cache.
# SXVI record holds the index of the cache item in pivot cache.
# Don't get confused.
parent.appendLine(" index of selected item: %d"%self.isxvi)
parent.appendLine(" OBJ record ID for page item drop-down arrow: %d"%self.idObj)
def __parseBytes (self):
self.items = []
while not self.isEndOfRecord():
item = SXPageItem.Item(self)
self.items.append(item)
def parseBytes (self):
self.__parseBytes()
for item in self.items:
item.appendLines(self)
class SXVI(BaseRecordHandler):
itemTypes = {
0xFE: 'Page',
0xFF: 'Null',
0x00: 'Data value',
0x01: 'Default subtotal',
0x02: 'SUM',
0x03: 'COUNTA',
0x04: 'COUNT',
0x05: 'AVERAGE',
0x06: 'MAX',
0x07: 'MIN',
0x08: 'PRODUCT',
0x09: 'STDEV',
0x0A: 'STDEVP',
0x0B: 'VAR',
0x0C: 'VARP',
0x0D: 'Grand total',
0x0E: 'blank'
}
def __parseBytes (self):
self.itmType = self.readSignedInt(2)
flag = self.readUnsignedInt(1)
self.fHidden = (flag & 0x01) != 0
self.fHideDetail = (flag & 0x02) != 0
reserved = (flag & 0x04) != 0
self.fFormula = (flag & 0x08) != 0
self.fMissing = (flag & 0x10) != 0
self.readBytes(1) # reserved
self.iCache = self.readSignedInt(2)
cch = self.readSignedInt(2)
if cch > 0:
self.name = self.readXLUnicodeStringNoCch()
else:
self.name = "null (use name in the cache)"
def parseBytes (self):
self.__parseBytes()
self.appendLineString("item type", globals.getValueOrUnknown(SXVI.itemTypes, self.itmType))
self.appendLineBoolean("hidden", self.fHidden)
self.appendLineBoolean("collapsed", self.fHideDetail)
self.appendLineBoolean("calcualted", self.fFormula)
self.appendLineBoolean("missing in data source", self.fMissing)
if self.iCache >= 0:
self.appendLineInt("cache item index", self.iCache)
else:
self.appendLine("cache item index: %d (no cache item is referenced)"%self.iCache)
self.appendLineString("name", self.name)
class PivotQueryTableEx(BaseRecordHandler):
"""QSISXTAG: Pivot Table and Query Table Extensions (802h)"""
excelVersionList = [
'Excel 2000',
'Excel XP',
'Excel 2003',
'Excel 2007'
]
class TableType:
QueryTable = 0
PivotTable = 1
def getExcelVersion (self, lastExcelVer):
s = '(unknown)'
if lastExcelVer < len(PivotQueryTableEx.excelVersionList):
s = PivotQueryTableEx.excelVersionList[lastExcelVer]
return s
def parseBytes (self):
recordType = self.readUnsignedInt(2)
self.appendLine("record type (always 0802h): %4.4Xh"%recordType)
dummyFlags = self.readUnsignedInt(2)
self.appendLine("flags (must be zero): %4.4Xh"%dummyFlags)
tableType = self.readUnsignedInt(2)
s = '(unknown)'
if tableType == PivotQueryTableEx.TableType.QueryTable:
s = 'query table'
elif tableType == PivotQueryTableEx.TableType.PivotTable:
s = 'pivot table'
self.appendLine("this record is for: %s"%s)
# general flags
flags = self.readUnsignedInt(2)
enableRefresh = (flags & 0x0001)
invalid = (flags & 0x0002)
tensorEx = (flags & 0x0004)
s = '(unknown)'
if enableRefresh:
s = 'ignore'
else:
s = 'check'
self.appendLine("check for SXDB or QSI for table refresh: %s"%s)
self.appendLine("PivotTable cache is invalid: %s"%self.getYesNo(invalid))
self.appendLine("This is an OLAP PivotTable report: %s"%self.getYesNo(tensorEx))
# feature-specific options
featureOptions = self.readUnsignedInt(4)
if tableType == PivotQueryTableEx.TableType.QueryTable:
# query table
preserveFormat = (featureOptions & 0x00000001)
autoFit = (featureOptions & 0x00000002)
self.appendLine("keep formatting applied by the user: %s"%self.getYesNo(preserveFormat))
self.appendLine("auto-fit columns after refresh: %s"%self.getYesNo(autoFit))
elif tableType == PivotQueryTableEx.TableType.PivotTable:
# pivot table
noStencil = (featureOptions & 0x00000001)
hideTotAnnotation = (featureOptions & 0x00000002)
includeEmptyRow = (featureOptions & 0x00000008)
includeEmptyCol = (featureOptions & 0x00000010)
self.appendLine("no large drop zones if no data fields: %s"%self.getTrueFalse(noStencil))
self.appendLine("no asterisk for the total in OLAP table: %s"%self.getTrueFalse(hideTotAnnotation))
self.appendLine("retrieve and show empty rows from OLAP source: %s"%self.getTrueFalse(includeEmptyRow))
self.appendLine("retrieve and show empty columns from OLAP source: %s"%self.getTrueFalse(includeEmptyCol))
self.appendLine("table last refreshed by: %s"%
self.getExcelVersion(self.readUnsignedInt(1)))
self.appendLine("minimal version that can refresh: %s"%
self.getExcelVersion(self.readUnsignedInt(1)))
offsetBytes = self.readUnsignedInt(1)
self.appendLine("offset from first FRT byte to first cchName byte: %d"%offsetBytes)
self.appendLine("first version that created the table: %s"%
self.getExcelVersion(self.readUnsignedInt(1)))
textLen = self.readUnsignedInt(2)
name, textLen = globals.getRichText(self.readRemainingBytes(), textLen)
self.appendLine("table name: %s"%name)
return
class SXDouble(BaseRecordHandler):
def __parseBytes (self):
self.val = self.readDouble()
self.strmData.pivotCacheFields[-1].values.append("%g"%self.val)
def parseBytes (self):
self.__parseBytes()
self.appendLine("value: %g"%self.val)
class SXBoolean(BaseRecordHandler):
def parseBytes (self):
pass
class SXError(BaseRecordHandler):
def parseBytes (self):
pass
class SXInt(BaseRecordHandler):
def __parseBytes (self):
self.num = self.readSignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLineInt("value", self.num)
class SXString(BaseRecordHandler):
def __parseBytes (self):
self.text = self.readXLUnicodeString()
self.strmData.pivotCacheFields[-1].values.append(self.text)
def parseBytes (self):
self.__parseBytes()
self.appendLineString("value", self.text)
class SXRng(BaseRecordHandler):
groupTypes = [
"numeric value",
"seconds",
"minutes",
"hours",
"days",
"months",
"quarters",
"years"
]
def __parseBytes (self):
flag = self.readUnsignedInt(2)
self.fAutoStart = (flag & 0x0001) != 0 # A
self.fAutoEnd = (flag & 0x0002) != 0 # B
self.iByType = (flag & 0x001C) / 4 # C
def parseBytes (self):
self.__parseBytes()
self.appendLineBoolean("auto start", self.fAutoStart)
self.appendLineBoolean("auto end", self.fAutoEnd)
self.appendLineString("group type", globals.getValueOrUnknown(SXRng.groupTypes, self.iByType))
# -------------------------------------------------------------------
# CT - Change Tracking
class RRD(object):
RevType = {
0x0000: "insert row", # REVTINSRW
0x0001: "insert column", # REVTINSCOL
0x0002: "delete row", # REVTDELRW
0x0003: "delete column", # REVTDELCOL
0x0004: "cell move", # REVTMOVE
0x0005: "insert sheet", # REVTINSERTSH
0x0007: "sort", # REVTSORT
0x0008: "cell change", # REVTCHANGECELL
0x0009: "rename sheet", # REVTRENSHEET
0x000A: "defined name change", # REVTDEFNAME
0x000B: "format revision", # REVTFORMAT
0x000C: "autoformat revision", # REVTAUTOFMT
0x000D: "comment revision", # REVTNOTE
0x0020: "header (meta-data) revision", # REVTHEADER
0x0025: "conflict", # REVTCONFLICT
0x002B: "custom view add", # REVTADDVIEW
0x002C: "custom view delete", # REVTDELVIEW
0x002E: "query table field removal" # REVTTRASHQTFIELD
}
def __init__ (self, parent):
self.parent = parent
self.cbMemory = parent.readUnsignedInt(4)
self.revid = parent.readSignedInt(4)
self.revt = parent.readUnsignedInt(2)
flags = parent.readUnsignedInt(2)
self.fAccepted = (flags & 0x0001) != 0
self.fUndoAction = (flags & 0x0002) != 0
unused = (flags & 0x0004) != 0
self.fDelAtEdgeOfSort = (flags & 0x0008) != 0
self.tabid = parent.readUnsignedInt(2)
def parseBytes (self):
self.parent.appendLineInt("memory size", self.cbMemory)
self.parent.appendLine("revision ID: %d"%self.revid)
self.parent.appendLine("revision type: %s (0x%4.4X)"%(globals.getValueOrUnknown(RRD.RevType, self.revt), self.revt))
self.parent.appendLineBoolean("accepted", self.fAccepted)
self.parent.appendLineBoolean("undo action", self.fUndoAction)
self.parent.appendLineBoolean("deleted at edge of sorted range", self.fDelAtEdgeOfSort)
self.parent.appendLineInt("sheet index", self.tabid)
class RRDChgCell(BaseRecordHandler):
class CellType:
Blank = 0x0000
RKNumber = 0x0001
Xnum = 0x0002
XLUnicodeRichExtendedString = 0x0003
Bes = 0x0004
CellParsedFormula = 0x0005
CellTypes = [
"blank", # 0x0
"RK", # 0x1
"double", # 0x2
"string", # 0x3
"boolean or error", # 0x4
"formula" # 0x5
]
NumFmtTypes = {
0x0000: "automatic",
0x0004: "number, two decimal places, use the 1000 separator (,)",
0x000B: "currency, two decimal places, use parentheses for negative values",
0x000D: "percentage, zero decimal places",
0x000E: "percentage, two decimal places",
0x000F: "scientific",
0x0010: "engineering",
0x0011: "fraction, up to one digit numerator and denominator",
0x0012: "fraction, up to two digit numerator and denominator",
0x0013: "date (MM-DD-YY)",
0x0015: "date (DD-MMM)",
0x0017: "time (H:MM AM/PM)",
0x001B: "date/time, 24 hour format (M/D/YY H:MM)",
0x0022: "accounting (currency with decimal point aligned, and centered minus-sign for 0-value), two decimal places, use currency symbol"
}
def __parseBytes (self):
self.rrd = RRD(self)
flags = self.readUnsignedInt(2)
self.vt = (flags & 0x0007)
flags /= 2**3 # shift 3 bits
self.vtOld = (flags & 0x0007)
flags /= 2**3 # shift 3 bits
self.f123Prefix = (flags & 0x0001)
unused = (flags & 0x0002)
self.fOldFmt = (flags & 0x0004)
self.fOldFmtNull = (flags & 0x0008)
self.fXfDxf = (flags & 0x0010)
self.fStyXfDxf = (flags & 0x0020)
self.fDxf = (flags & 0x0040)
self.fDxfNull = (flags & 0x0080)
self.ifmtDisp = self.readUnsignedInt(1)
flags = self.readUnsignedInt(1)
self.fPhShow = (flags & 0x01)
self.fPhShowOld = (flags & 0x02)
self.fEOLFmlaUpdate = (flags & 0x04)
self.loc = RgceLoc(self)
self.cbOldVal = self.readUnsignedInt(4)
self.cetxpRst = self.readUnsignedInt(2)
if self.fOldFmt or self.fDxf:
# TODO : Parse DXFN
return
# old value
if self.vtOld == RRDChgCell.CellType.Blank:
pass
elif self.vtOld == RRDChgCell.CellType.RKNumber:
self.rkOld = decodeRK(self.readUnsignedInt(4))
elif self.vtOld == RRDChgCell.CellType.Xnum:
self.numOld = self.readDouble()
elif self.vtOld == RRDChgCell.CellType.XLUnicodeRichExtendedString:
self.stOld = self.readXLUnicodeRichExtendedString()
elif self.vtOld == RRDChgCell.CellType.Bes:
self.besOld = Bes(self)
elif self.vtOld == RRDChgCell.CellType.CellParsedFormula:
self.xpeOld = CellParsedFormula(self)
# new value
if self.vt == RRDChgCell.CellType.Blank:
pass
elif self.vt == RRDChgCell.CellType.RKNumber:
self.rk = decodeRK(self.readUnsignedInt(4))
elif self.vt == RRDChgCell.CellType.Xnum:
self.num = self.readDouble()
elif self.vt == RRDChgCell.CellType.XLUnicodeRichExtendedString:
self.st = self.readXLUnicodeRichExtendedString()
elif self.vt == RRDChgCell.CellType.Bes:
self.bes = Bes(self)
elif self.vt == RRDChgCell.CellType.CellParsedFormula:
self.xpe = CellParsedFormula(self)
def parseBytes (self):
self.__parseBytes()
self.rrd.parseBytes()
self.appendLineString("old cell type", globals.getValueOrUnknown(RRDChgCell.CellTypes,self.vtOld))
self.appendLineString("new cell type", globals.getValueOrUnknown(RRDChgCell.CellTypes,self.vt))
self.appendLineBoolean("prefix characters present", self.f123Prefix)
self.appendLineBoolean("old formatting available", self.fOldFmt)
self.appendLineBoolean("old formatting empty", self.fOldFmtNull)
self.appendLineBoolean("reset to cell style first", self.fXfDxf)
self.appendLineBoolean("clear cell format first", self.fStyXfDxf)
self.appendLineBoolean("format has changed", self.fDxf)
self.appendLineBoolean("new formatting empty", self.fDxfNull)
self.appendLineString("number format for new value", globals.getValueOrUnknown(RRDChgCell.NumFmtTypes,self.ifmtDisp))
self.appendLineBoolean("new cell has phonetic string", self.fPhShow)
self.appendLineBoolean("old cell has phonetic string", self.fPhShowOld)
self.appendLineBoolean("new cell is formula update", self.fEOLFmlaUpdate)
self.appendLineString("cell position", self.loc.toString())
self.appendLineInt("old cell content size", self.cbOldVal)
self.appendLineInt("number of RRDRstEtxp records", self.cetxpRst)
if self.fOldFmt or self.fDxf:
# TODO : Parse DXFN.
return
# old value
if self.vtOld == RRDChgCell.CellType.Blank:
self.appendLine("old value: blank")
elif self.vtOld == RRDChgCell.CellType.RKNumber:
self.appendLine("old value: %g"%self.rkOld)
elif self.vtOld == RRDChgCell.CellType.Xnum:
self.appendLine("old value: %g"%self.numOld)
elif self.vtOld == RRDChgCell.CellType.XLUnicodeRichExtendedString:
self.appendLineString("old value", self.stOld)
elif self.vtOld == RRDChgCell.CellType.Bes:
self.appendLineString("old value", self.besOld.toString())
elif self.vtOld == RRDChgCell.CellType.CellParsedFormula:
self.appendLineString("old value", self.xpeOld.toString())
# new value
if self.vt == RRDChgCell.CellType.Blank:
self.appendLine("new value: blank")
elif self.vt == RRDChgCell.CellType.RKNumber:
self.appendLine("new value: %g"%self.rk)
elif self.vt == RRDChgCell.CellType.Xnum:
self.appendLine("new value: %g"%self.num)
elif self.vt == RRDChgCell.CellType.XLUnicodeRichExtendedString:
self.appendLineString("new value", self.st)
elif self.vt == RRDChgCell.CellType.Bes:
self.appendLineString("new value", self.bes.toString())
elif self.vt == RRDChgCell.CellType.CellParsedFormula:
self.appendLineString("new value", self.xpe.toString())
class RRDInsDel(BaseRecordHandler):
def __parseBytes (self):
self.rrd = RRD(self)
flags = self.readUnsignedInt(2)
self.fEndOfList = (flags & 0x0001) != 0
self.refn = Ref8U(self)
self.cUcr = self.readUnsignedInt(4)
# TODO : parse optional undo data.
def parseBytes (self):
self.__parseBytes()
self.rrd.parseBytes()
self.appendLineBoolean("row inserted at bottom", self.fEndOfList)
self.appendLineString("range", self.refn.toString())
self.appendLineInt("number of items in undo data", self.cUcr)
# -------------------------------------------------------------------
# CH - Chart
class Header(BaseRecordHandler):
def dumpData(self):
return ('header', {})
class Footer(BaseRecordHandler):
def dumpData(self):
return ('footer', {})
class HCenter(BaseRecordHandler):
def __parseBytes(self):
self.val = self.readUnsignedInt(2)
def dumpData(self):
self.__parseBytes()
return ('hcenter', {'val': self.val})
class VCenter(BaseRecordHandler):
def __parseBytes(self):
self.val = self.readUnsignedInt(2)
def dumpData(self):
self.__parseBytes()
return ('vcenter', {'val': self.val})
class Setup(BaseRecordHandler):
def dumpData(self):
return ('setup', {})
class Units(BaseRecordHandler):
def dumpData(self):
return ('units', {})
class Begin(BaseRecordHandler):
pass
class PlotArea(BaseRecordHandler):
def dumpData(self):
return ('plot-area', {})
class CrtLink(BaseRecordHandler): # it's unused
def dumpData(self):
return ('crt-link', {})
class End(BaseRecordHandler):
pass
class Chart(BaseRecordHandler):
def __parseBytes(self):
self.x = globals.getSignedInt(self.bytes[0:4])
self.y = globals.getSignedInt(self.bytes[4:8])
self.w = globals.getSignedInt(self.bytes[8:12])
self.h = globals.getSignedInt(self.bytes[12:16])
def parseBytes (self):
self.__parseBytes()
self.appendLine("position: (x, y) = (%d, %d)"%(self.x, self.y))
self.appendLine("size: (width, height) = (%d, %d)"%(self.w, self.h))
def dumpData(self):
self.__parseBytes()
return ('chart-xfrm', {'x': self.x,
'y': self.y,
'w': self.w,
'h': self.h})
class Frame(BaseRecordHandler):
__frt_table = {0x0000: "frame surrounding the chart element",
0x0004: "frame with a shadow surrounding the chart element"}
def __parseBytes(self):
self.frt = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
self.autoSize = (flags & 0x001) != 0
self.autoPosition = (flags & 0x002) != 0
def parseBytes (self):
self.__parseBytes()
self.appendLine("frame type: %s" % Frame.__frt_table[self.frt])
self.appendLine("autoSize: %s" % self.autoSize)
self.appendLine("autoPosition: %s" % self.autoPosition)
def dumpData(self):
self.__parseBytes()
return ('frame', {'frt': self.frt,
'auto-size': self.autoSize,
'auto-position': self.autoPosition})
class LineFormat(BaseRecordHandler):
lineStyles = [
'Solid', # 0x0000
'Dash', # 0x0001
'Dot', # 0x0002
'Dash-dot', # 0x0003
'Dash dot-dot ', # 0x0004
'None', # 0x0005
'Dark gray pattern', # 0x0006
'Medium gray pattern', # 0x0007
'Light gray pattern ' # 0x0008
]
def __parseBytes(self):
self.rgb = self.readLongRGB()
self.lns = self.readUnsignedInt(2)
self.we = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
self.auto = (flags & 0x001) != 0 # A
unused = (flags & 0x002) != 0 # B (unused)
self.axisOn = (flags & 0x004) != 0 # C
self.autoCo = (flags & 0x008) != 0 # D
self.icv = self.readICV()
def parseBytes (self):
self.__parseBytes()
self.appendLineString("line color", self.rgb.toString())
self.appendLineString("line style",
globals.getValueOrUnknown(LineFormat.lineStyles, self.lns))
def dumpData(self):
self.__parseBytes()
return ('line-format', {'lns': self.lns,
'we': self.we,
'auto': self.auto,
'axis-on': self.axisOn,
'auto-co': self.autoCo},
[('rgb', dumpRgb(self.rgb)),
('icv', dumpIcv(self.icv))])
class AreaFormat(BaseRecordHandler):
def __parseBytes(self):
self.foreColor = self.readLongRGB()
self.backColor = self.readLongRGB()
self.fls = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
self.auto = (flags & 0x001) != 0 # A
self.invertNeg = (flags & 0x002) != 0 # B
self.icvFore = self.readICV()
self.icvBack = self.readICV()
def parseBytes (self):
self.__parseBytes()
self.appendLineString("foreground color", self.foreColor.toString())
self.appendLineString("background color", self.backColor.toString())
self.appendLineBoolean("automatic fill color", self.auto)
self.appendLineBoolean("foreground and background colors inverted", self.invertNeg)
def dumpData(self):
self.__parseBytes()
return ('area-format', {'fls': self.fls,
'auto': self.auto,
'invert-neg': self.invertNeg},
[('fore-color', dumpRgb(self.foreColor)),
('back-color', dumpRgb(self.backColor)),
('icv-fore', dumpIcv(self.icvFore)),
('icv-back', dumpIcv(self.icvBack))])
class PieFormat(BaseRecordHandler):
def __parseBytes(self):
self.pcExplode = self.readSignedInt(2)
def parseBytes (self):
self.__parseBytes()
# TODO: dump all data
def dumpData(self):
self.__parseBytes()
return ('pie-format', {'pc-explode': self.pcExplode})
class MarkerFormat(BaseRecordHandler):
def __parseBytes(self):
self.rgbFore = self.readLongRGB()
self.rgbBack = self.readLongRGB()
self.imk = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
self.auto = (flags & 0x001) != 0 # A
# next 3 bits are reserved
self.notShowInt = (flags & 0x010) != 0 # C
self.notShowBrd = (flags & 0x020) != 0 # D
self.icvFore = self.readICV()
self.icvBack = self.readICV()
self.miSize = self.readUnsignedInt(4)
def parseBytes (self):
self.__parseBytes()
self.appendLineString("foreground color", self.rgbFore.toString())
self.appendLineString("background color", self.rgbBack.toString())
def dumpData(self):
self.__parseBytes()
return ('marker-format', {'imk': self.imk,
'auto': self.auto,
'not-show-int': self.notShowInt,
'not-show-brd': self.notShowBrd,
'mi-size': self.miSize},
[('rgb-fore', dumpRgb(self.rgbFore)),
('rgb-back', dumpRgb(self.rgbBack)),
('icv-fore', dumpIcv(self.icvFore)),
('icv-back', dumpIcv(self.icvBack))])
class DataFormat(BaseRecordHandler):
def __parseBytes(self):
self.xi = self.readUnsignedInt(2)
self.yi = self.readUnsignedInt(2)
self.iss = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
unused = (flags & 0x001) != 0 # A (??? - not described in docs)
def parseBytes (self):
self.__parseBytes()
# TODO: dump all data
def dumpData(self):
self.__parseBytes()
return ('data-format', {'xi': self.xi,
'yi': self.yi,
'iss': self.iss})
class SerFmt(BaseRecordHandler):
def __parseBytes(self):
flags = self.readUnsignedInt(2)
self.smoothedLine = (flags & 0x001) != 0
self.bubbles3D = (flags & 0x002) != 0
self.arShadow = (flags & 0x004) != 0
def parseBytes (self):
self.__parseBytes()
self.appendLine("Smoothed line: %s" % self.getTrueFalse(self.smoothedLine))
self.appendLine("3D bubbles: %s" % self.getTrueFalse(self.bubbles3D))
self.appendLine("With shadow: %s" % self.getTrueFalse(self.arShadow))
def dumpData(self):
self.__parseBytes()
return ('ser-fmt', {'smoothed-line': self.smoothedLine,
'bubbles-3d': self.bubbles3D,
'ar-shadow': self.arShadow})
class ChartFormat(BaseRecordHandler):
def __parseBytes(self):
reserved1 = self.readUnsignedInt(4)
reserved2 = self.readUnsignedInt(4)
reserved3 = self.readUnsignedInt(4)
reserved4 = self.readUnsignedInt(4)
flags = self.readUnsignedInt(2)
self.varied = (flags & 0x001) != 0 # A
self.icrt = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
# TODO: dump all data
def dumpData(self):
self.__parseBytes()
return ('chart-format', {'varied': self.varied,
'icrt': self.icrt})
class DataLabExtContents(BaseRecordHandler):
def __parseBytes(self):
self.header = self.readFrtHeader()
flags = self.readUnsignedInt(2)
self.serName = (flags & 0x001) != 0 # A
self.catName = (flags & 0x002) != 0 # B
self.value = (flags & 0x004) != 0 # C
self.percent = (flags & 0x008) != 0 # D
self.bubSizes = (flags & 0x010) != 0 # E
self.sep = self.readUnicodeString()
def parseBytes (self):
self.__parseBytes()
self.appendLine("Header: %s, %s" % (str(self.header.rt), str(self.header.flags)))
self.appendLine("Display series name: %s" % self.getTrueFalse(self.serName))
self.appendLine("Display categories name: %s" % self.getTrueFalse(self.catName))
self.appendLine("Display value: %s" % self.getTrueFalse(self.value))
self.appendLine("Is a percent: %s" % self.getTrueFalse(self.percent))
self.appendLine("Display bubble size: %s" % self.getTrueFalse(self.bubSizes))
self.appendLine("Separator: %s" % str(self.sep))
def dumpData(self):
self.__parseBytes()
return ('datalab-ext-contents', {'ser-name': self.serName,
'cat-name': self.catName,
'value': self.value,
'percent': self.percent,
'bub-sizes': self.bubSizes,
'sep': self.sep},
[('header', dumpFrtHeader(self.header))])
class ChartFrtInfo(BaseRecordHandler):
def __parseBytes(self):
self.headerOld = self.readUnsignedInt(4)
self.verOriginator = self.readUnsignedInt(1)
self.verWriter = self.readUnsignedInt(1)
self.cCFRTID = self.readUnsignedInt(2)
self.cfrtids = []
for x in xrange(self.cCFRTID):
self.cfrtids.append(self.readCFRTID())
def parseBytes (self):
self.__parseBytes()
self.appendLine("Header old: %s" % str(self.headerOld))
self.appendLine("verOriginator (version of app that created the file): %s" % str(self.verOriginator))
self.appendLine("verWriter (version of app that last saved the file): %s" % str(self.verWriter))
self.appendLine("Count of CFRTID records: %s" % str(self.cCFRTID))
for cfrtid in self.cfrtids:
self.appendLine("CFRTID: [%s, %s]" % (cfrtid.start, cfrtid.end))
def dumpData(self):
self.__parseBytes()
return ('chart-frt-info', {'header-old': self.headerOld,
'ver-originator': self.verOriginator,
'ver-writer': self.verWriter,
'cfrtid-count': self.cCFRTID},
[('cfrtid-list', map(lambda x: ('cfrtid', dumpCfrtid(x)),
self.cfrtids))])
class StartBlock(BaseRecordHandler):
def __parseBytes(self):
self.headerOld = self.readUnsignedInt(4)
self.objectKind = self.readUnsignedInt(2)
self.objectContext = self.readUnsignedInt(2)
self.objectInstance1 = self.readUnsignedInt(2)
self.objectInstance2 = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine("Header old: %s" % str(self.headerOld))
self.appendLine("Object kind: %s" % str(self.objectKind))
self.appendLine("Object context: %s" % str(self.objectContext))
self.appendLine("Object instance 1: %s" % str(self.objectInstance1))
self.appendLine("Object instance 2: %s" % str(self.objectInstance2))
def dumpData(self):
self.__parseBytes()
return ('start-block', {'header-old': self.headerOld,
'object-kind': self.objectKind,
'object-context': self.objectContext,
'object-instance1': self.objectInstance1,
'object-instance2': self.objectInstance2})
class EndBlock(BaseRecordHandler):
def __parseBytes(self):
self.headerOld = self.readUnsignedInt(4)
self.objectKind = self.readUnsignedInt(2)
unused = self.readUnsignedInt(2)
unused = self.readUnsignedInt(2)
unused = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine("Header old: %s" % str(self.headerOld))
self.appendLine("Object kind: %s" % str(self.objectKind))
def dumpData(self):
self.__parseBytes()
return ('end-block', {'header-old': self.headerOld,
'object-kind': self.objectKind})
class CatLab(BaseRecordHandler):
def __parseBytes(self):
self.headerOld = self.readUnsignedInt(4)
self.offset = self.readUnsignedInt(2)
self.at = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
self.autoCatLabelReal = (flags & 0x0001) != 0 # A
reserved = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine("Header old: %s" % str(self.headerOld))
self.appendLine("Offset: %s" % str(self.offset))
self.appendLine("At(alignment): %s" % str(self.at))
self.appendLine("Auto category label real: %s" % str(self.autoCatLabelReal))
def dumpData(self):
self.__parseBytes()
return ('catlab', {'header-old': self.headerOld,
'offset': self.offset,
'at': self.at,
'auto-catlabel-real': self.autoCatLabelReal})
class Chart3DBarShape(BaseRecordHandler):
def __parseBytes(self):
self.riser = self.readUnsignedInt(1)
self.taper = self.readUnsignedInt(1)
def parseBytes (self):
self.__parseBytes()
s = ''
if self.riser:
s = 'ellipse'
else:
s = 'rectangle'
self.appendLineString("base shape of data points", s)
self.appendLineInt("taper style", self.taper)
def dumpData(self):
self.__parseBytes()
return ('chart-3dbar-shape', {'riser': self.riser,
'taper': self.taper})
class DropBar(BaseRecordHandler):
def __parseBytes(self):
self.gap = self.readSignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine('Gap: %s' % str(self.gap))
def dumpData(self):
self.__parseBytes()
return ('drop-bar', {'gap': self.gap})
class CrtLine(BaseRecordHandler):
def __parseBytes(self):
self.id = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine('ID: %s' % str(self.id))
def dumpData(self):
self.__parseBytes()
return ('crt-line', {'id': self.id})
class ObjectLink(BaseRecordHandler):
def __parseBytes(self):
self.linkObj = self.readUnsignedInt(2)
self.linkVar1 = self.readUnsignedInt(2)
self.linkVar2 = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine('Link object: %s' % str(self.linkObj))
self.appendLine('Link var1: %s' % str(self.linkVar1))
self.appendLine('Link var2: %s' % str(self.linkVar2))
def dumpData(self):
self.__parseBytes()
return ('object-link', {'link-obj': self.linkObj,
'link-var1': self.linkVar1,
'link-var2': self.linkVar2})
class AttachedLabel(BaseRecordHandler):
def __parseBytes(self):
flag = self.readUnsignedInt(2)
self.showValue = (flag & 0x0001) != 0 # A
self.showPercent = (flag & 0x0002) != 0 # B
self.showLabelAndPerc = (flag & 0x0004) != 0 # C
unused = (flag & 0x0008) != 0 # D
self.showLabel = (flag & 0x0010) != 0 # E
self.showBubbleSizes = (flag & 0x0020) != 0 # F
self.showSeriesName = (flag & 0x0040) != 0 # G
def parseBytes (self):
self.__parseBytes()
self.appendLine("Show value: %s" % self.getTrueFalse(self.showValue))
self.appendLine("Show percent: %s" % self.getTrueFalse(self.showPercent))
self.appendLine("Show label and percent: %s" % self.getTrueFalse(self.showLabelAndPerc))
self.appendLine("Show bubble sizes: %s" % self.getTrueFalse(self.showBubbleSizes))
self.appendLine("Show series name: %s" % self.getTrueFalse(self.showSeriesName))
# TODO: dump all data
def dumpData(self):
self.__parseBytes()
return ('attached-label', {'show-value': self.showValue,
'show-percent': self.showPercent,
'show-label-and-perc': self.showLabelAndPerc,
'show-label': self.showLabel,
'show-bubble-sizes': self.showBubbleSizes,
'show-series-name': self.showSeriesName})
class Chart3d(BaseRecordHandler):
def __parseBytes(self):
self.rot = self.readSignedInt(2)
self.elev = self.readSignedInt(2)
self.dist = self.readSignedInt(2)
self.height = self.readUnsignedInt(2) # TODO: it can be a signed int too
self.depth = self.readUnsignedInt(2)
self.gap = self.readUnsignedInt(2)
flag = self.readUnsignedInt(2)
self.perspective = (flag & 0x0001) != 0 # A
self.cluster = (flag & 0x0002) != 0 # B
self.scaling = (flag & 0x0004) != 0 # C
reserved = (flag & 0x0008) != 0 # D
self.notPieChart = (flag & 0x0010) != 0 # E
self.walls2D = (flag & 0x0020) != 0 # F
def parseBytes (self):
self.__parseBytes()
# TODO: dump all data
def dumpData(self):
self.__parseBytes()
return ('chart-3d', {'rot': self.rot,
'elev': self.elev,
'dist': self.dist,
'height': self.height,
'depth': self.depth,
'gap': self.gap,
'perspective': self.perspective,
'cluster': self.cluster,
'scaling': self.scaling,
'not-pie-chart': self.notPieChart,
'walls-2d': self.walls2D})
class SerToCrt(BaseRecordHandler):
def __parseBytes(self):
self.id = self.readUnsignedInt(2)
def dumpData(self):
self.__parseBytes()
return ('ser-to-crt', {'id': self.id})
class Pos(BaseRecordHandler):
def __parseBytes(self):
self.mdTopLt = self.readUnsignedInt(2)
self.mdBotRt = self.readUnsignedInt(2)
self.x1 = self.readSignedInt(2)
unused = self.readUnsignedInt(2)
self.y1 = self.readSignedInt(2)
unused = self.readUnsignedInt(2)
self.x2 = self.readSignedInt(2)
unused = self.readUnsignedInt(2)
self.y2 = self.readSignedInt(2)
unused = self.readUnsignedInt(2)
def dumpData(self):
self.__parseBytes()
return ('pos', {'md-top-lt': self.mdTopLt,
'md-bot-rt': self.mdBotRt,
'x1': self.x1,
'y1': self.y1,
'x2': self.x2,
'y2': self.y2})
class FontX(BaseRecordHandler):
def __parseBytes(self):
self.iFont = self.readUnsignedInt(2)
def dumpData(self):
self.__parseBytes()
return ('font-x', {'i-font': self.iFont})
class AxesUsed(BaseRecordHandler):
def __parseBytes(self):
self.cAxes = self.readUnsignedInt(2)
def dumpData(self):
self.__parseBytes()
return ('axes-used', {'c-axes': self.cAxes})
class AxisParent(BaseRecordHandler):
def __parseBytes(self):
self.iax = self.readUnsignedInt(2)
# 16 bytes are unused
def dumpData(self):
self.__parseBytes()
return ('axis-parent', {'iax': self.iax})
class BobPop(BaseRecordHandler):
def __parseBytes(self):
self.pst = self.readUnsignedInt(1)
self.autoSplit = self.readUnsignedInt(1)
self.split = self.readUnsignedInt(2)
self.splitPos = self.readSignedInt(2)
self.splitPercent = self.readSignedInt(2)
self.pie2Size = self.readSignedInt(2)
self.gap = self.readSignedInt(1)
self.splitValue = self.readDouble()
flag = self.readUnsignedInt(2)
self.hasShadow = (flag & 0x0001) != 0 # A
def dumpData(self):
self.__parseBytes()
return ('bobpop', {'pst': self.pst,
'auto-split': self.autoSplit,
'split': self.split,
'split-pos': self.splitPos,
'split-percent': self.splitPercent,
'pie-2-size': self.pie2Size,
'gap': self.gap,
'split-balue': self.splitValue,
'has-shadow': self.hasShadow})
def parseBytes (self):
self.__parseBytes()
self.appendLine("Chart group type: %s" % str(self.pst))
self.appendLine("Auto split: %s" % self.getTrueFalse(self.autoSplit))
self.appendLine("Split type: %s" % str(self.split))
if self.split == 0x0: # pos
self.appendLine("Split pos: %s" % str(self.splitPos))
elif self.split == 0x1: # value
self.appendLine("Split value: %s" % str(self.splitValue))
elif self.split == 0x2: # percent
self.appendLine("Split percent: %s" % str(self.splitPercent))
else:
self.appendLine("Custom split is specified in BopPopCustom record that follows")
self.appendLine("Size of a secondary pie/bar: %s" % str(self.pie2Size))
self.appendLine("Gap: %s" % str(self.gap))
self.appendLine("Has shadow: %s" % self.getTrueFalse(self.hasShadow))
class Dat(BaseRecordHandler):
def __parseBytes(self):
flag = self.readUnsignedInt(2)
self.hasBordHorz = (flag & 0x0001) != 0 # A
self.hasBordVert = (flag & 0x0002) != 0 # B
self.hasBordOutline = (flag & 0x0004) != 0 # C
self.showSeriesKey = (flag & 0x0008) != 0 # D
def dumpData(self):
self.__parseBytes()
return ('dat', {'has-bord-horz': self.hasBordHorz,
'has-bord-vert': self.hasBordVert,
'has-bord-outline': self.hasBordOutline,
'show-series-key': self.showSeriesKey})
def parseBytes (self):
self.__parseBytes()
self.appendLine("Has horizontal borders: %s" % self.getTrueFalse(self.hasBordHorz))
self.appendLine("Has vertical borders: %s" % self.getTrueFalse(self.hasBordVert))
self.appendLine("Has outline borders: %s" % self.getTrueFalse(self.hasBordOutline))
self.appendLine("Show series key: %s" % self.getTrueFalse(self.showSeriesKey))
class AxcExt(BaseRecordHandler):
def __parseBytes (self):
self.catMin = self.readUnsignedInt(2)
self.catMax = self.readUnsignedInt(2)
self.catMajor = self.readUnsignedInt(2)
self.duMajor = self.readUnsignedInt(2)
self.catMinor = self.readUnsignedInt(2)
self.duMinor = self.readUnsignedInt(2)
self.duBase = self.readUnsignedInt(2)
self.catCrossDate = self.readUnsignedInt(2)
flag = self.readUnsignedInt(2)
self.autoMin = (flag & 0x0001) != 0 # A
self.autoMax = (flag & 0x0002) != 0 # B
self.autoMajor = (flag & 0x0004) != 0 # C
self.autoMinor = (flag & 0x0008) != 0 # D
self.dateAxis = (flag & 0x0010) != 0 # E
self.autoBase = (flag & 0x0020) != 0 # F
self.autoCross = (flag & 0x0040) != 0 # G
self.autoDate = (flag & 0x0080) != 0 # H
def dumpData(self):
self.__parseBytes()
return ('axc-ext', {'cat-min': self.catMin,
'cat-max': self.catMax,
'cat-major': self.catMajor,
'du-major': self.duMajor,
'cat-minor': self.catMinor,
'du-minor': self.duMinor,
'du-base': self.duBase,
'cat-cross-date': self.catCrossDate,
'auto-min': self.autoMin,
'auto-max': self.autoMax,
'auto-major': self.autoMajor,
'auto-minor': self.autoMinor,
'date-axis': self.dateAxis,
'auto-base': self.autoBase,
'auto-cross': self.autoCross,
'auto-date': self.autoDate})
class Tick(BaseRecordHandler):
def __parseBytes (self):
self.tktMajor = self.readUnsignedInt(1)
self.tktMinor = self.readUnsignedInt(1)
self.tlt = self.readUnsignedInt(1)
self.wBkgMode = self.readUnsignedInt(1)
self.rgb = self.readLongRGB()
reserved1 = self.readUnsignedInt(4)
reserved2 = self.readUnsignedInt(4)
reserved3 = self.readUnsignedInt(4)
reserved4 = self.readUnsignedInt(4)
flag = self.readUnsignedInt(2)
# TODO: recheck it
self.autoCo = (flag & 0x0001) != 0 # A
self.autoMode = (flag & 0x0002) != 0 # B
self.rot = (flag & (0x4+0x8+0x10)) >> 2
self.readingOrder = (flag >>14)
self.icv = self.readICV()
self.trot = self.readUnsignedInt(2)
def dumpData(self):
self.__parseBytes()
return ('tick', {'tkt-major': self.tktMajor,
'tkt-minor': self.tktMinor,
'tlt': self.tlt,
'w-bkg-mode': self.wBkgMode,
'auto-co': self.autoCo,
'auto-mode': self.autoMode,
'rot': self.rot,
'reading-order': self.readingOrder,
'trot': self.trot},
[('rgb', dumpRgb(self.rgb)),
('icv', dumpIcv(self.icv))])
class SeriesList(BaseRecordHandler):
def __parseBytes(self):
self.cser = self.readUnsignedInt(2)
self.series = []
for x in xrange(self.cser):
self.series.append(self.readUnsignedInt(2))
def parseBytes (self):
self.__parseBytes()
self.appendLine("Series count : %s" % str(self.cser))
for x in self.series:
self.appendLine("Series id : %s" % str(x))
def dumpData(self):
self.__parseBytes()
return ('series-list',
{'cser': self.cser},
map(lambda x: ('series-index',x),
self.series))
class AxisLine(BaseRecordHandler):
def __parseBytes(self):
self.id = self.readUnsignedInt(2)
def dumpData(self):
self.__parseBytes()
return ('axis-line', {'id': self.id})
class SIIndex(BaseRecordHandler):
def __parseBytes(self):
self.numIndex = self.readUnsignedInt(2)
def dumpData(self):
self.__parseBytes()
return ('si-index', {'num-index': self.numIndex})
class DefaultText(BaseRecordHandler):
__types = [
'non-percent or non-value',
'percent or value',
'non-scalable font',
'scalable font']
def __parseBytes (self):
self.id = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine(globals.getValueOrUnknown(DefaultText.__types, self.id))
def dumpData(self):
self.__parseBytes()
return ('default-text', {'id': self.id})
class Text(BaseRecordHandler):
__horAlign = { 1: 'left', 2: 'center', 3: 'right', 4: 'justify', 7: 'distributed' }
__verAlign = { 1: 'top', 2: 'center', 3: 'bottom', 4: 'justify', 7: 'distributed' }
__bkgMode = { 1: 'transparent', 2: 'opaque' }
def __parseBytes (self):
self.at = self.readUnsignedInt(1)
self.vat = self.readUnsignedInt(1)
self.bkgMode = self.readUnsignedInt(2)
self.textColor = self.readLongRGB()
self.x = self.readSignedInt(4)
self.y = self.readSignedInt(4)
self.dx = self.readSignedInt(4)
self.dy = self.readSignedInt(4)
flag = self.readUnsignedInt(2)
self.autoColor = (flag & 0x0001) != 0 # A
self.showKey = (flag & 0x0002) != 0 # B
self.showValue = (flag & 0x0004) != 0 # C
unused = (flag & 0x0008) != 0 # D (unused)
self.autoText = (flag & 0x0010) != 0 # E
self.generated = (flag & 0x0020) != 0 # F
self.deleted = (flag & 0x0040) != 0 # G
self.autoMode = (flag & 0x0080) != 0 # H
unused = (flag & 0x0700) != 0 # I (unused)
self.showLabelAndPerc = (flag & 0x0800) != 0 # J
self.showPercent = (flag & 0x1000) != 0 # K
self.showBubbleSizes = (flag & 0x2000) != 0 # L
self.showLabel = (flag & 0x4000) != 0 # M
reserved = (flag & 0x8000) != 0 # N (reserved)
self.icvTextColor = self.readICV()
flag = self.readUnsignedInt(2)
self.dlp = (flag & 0x000F)
self.readingOrder = (flag & 0xC000) / (2**14)
self.trot = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
self.appendLine("horizontal alignment: %s"%
globals.getValueOrUnknown(Text.__horAlign, self.at))
self.appendLine("vertical alignment: %s"%
globals.getValueOrUnknown(Text.__verAlign, self.vat))
self.appendLine("text background: %s"%
globals.getValueOrUnknown(Text.__bkgMode, self.bkgMode))
# TODO : handle the rest of the data.
def dumpData(self):
self.__parseBytes()
return ('text', {'at': self.at,
'vat': self.vat,
'bkg-mode': self.bkgMode,
'x': self.x,
'y': self.y,
'dx': self.dx,
'dy': self.dy,
'auto-color': self.autoColor,
'show-key': self.showKey,
'show-value': self.showValue,
'auto-text': self.autoText,
'generated': self.generated,
'deleted': self.deleted,
'show-label-and-perc': self.showLabelAndPerc,
'show-percent': self.showPercent,
'show-bubble-sizes': self.showBubbleSizes,
'show-label': self.showLabel,
'dlp': self.dlp,
'reading-order': self.readingOrder,
'trot': self.trot},
[('text-color', dumpRgb(self.textColor)),
('icv-text-color', dumpIcv(self.icvTextColor))])
class Series(BaseRecordHandler):
DATE = 0
NUMERIC = 1
SEQUENCE = 2
TEXT = 3
seriesTypes = ['date', 'numeric', 'sequence', 'text']
@staticmethod
def getSeriesType (idx):
r = 'unknown'
if idx < len(CHSeries.seriesTypes):
r = CHSeries.seriesTypes[idx]
return r
def __parseBytes (self):
self.catType = self.readUnsignedInt(2)
self.valType = self.readUnsignedInt(2) # must be 1 (ignored)
self.catCount = self.readUnsignedInt(2)
self.valCount = self.readUnsignedInt(2)
self.bubbleType = self.readUnsignedInt(2) # must be 1 (ignored)
self.bubbleCount = self.readUnsignedInt(2)
def parseBytes (self):
self.__parseBytes()
s = "unknown"
if self.catType == 1:
s = "numeric"
elif self.catType == 3:
s = "text"
self.appendLine("data type: %s"%s)
self.appendLine("category or horizontal value count: %d"%self.catCount)
self.appendLine("value or vertical value count: %d"%self.valCount)
self.appendLine("bubble size value count: %d"%self.bubbleCount)
def dumpData(self):
self.__parseBytes()
return ('series', {'cat-type': self.catType,
'val-type': self.valType,
'cat-count': self.catCount,
'val-count': self.valCount,
'bubble-type': self.bubbleType,
'bubble-count': self.bubbleCount})
class CHAxis(BaseRecordHandler):
axisTypeList = ['x-axis', 'y-axis', 'z-axis']
def __parseBytes(self):
self.axisType = self.readUnsignedInt(2)
self.x = self.readSignedInt(4)
self.y = self.readSignedInt(4)
self.w = self.readSignedInt(4)
self.h = self.readSignedInt(4)
def parseBytes (self):
self.__parseBytes()
if self.axisType < len(CHAxis.axisTypeList):
self.appendLine("axis type: %s (%d)"%(CHAxis.axisTypeList[self.axisType], self.axisType))
else:
self.appendLine("axis type: unknown")
self.appendLine("area: (x, y, w, h) = (%d, %d, %d, %d) [no longer used]"%(self.x, self.y, self.w, self.h))
def dumpData(self):
self.__parseBytes()
return ('axis', {'axis-type': self.axisType,
'x': self.x,
'y': self.y,
'w': self.w,
'h': self.h})
class CHProperties(BaseRecordHandler):
def __parseBytes(self):
flags = self.readUnsignedInt(2)
self.emptyFlags = self.readUnsignedInt(2)
self.manualSeries = (flags & 0x0001) != 0
self.showVisCells = (flags & 0x0002) != 0
self.noResize = (flags & 0x0004) != 0
self.manualPlotArea = (flags & 0x0008) != 0
def parseBytes (self):
self.__parseBytes()
self.appendLine("manual series: %s" % self.getTrueFalse(self.manualSeries))
self.appendLine("show only visible cells: %s" % self.getTrueFalse(self.showVisCells))
self.appendLine("no resize: %s"%self.getTrueFalse(self.noResize))
self.appendLine("manual plot area: %s" % self.getTrueFalse(self.manualPlotArea))
emptyValues = "skip"
if self.emptyFlags == 1:
emptyValues = "plot as zero"
elif self.emptyFlags == 2:
emptyValues = "interpolate empty values"
self.appendLine("empty value treatment: %s" % emptyValues)
def dumpData(self):
self.__parseBytes()
return ('sht-props', {'empty-flags': self.emptyFlags,
'manual-series': self.manualSeries,
'show-vis-cells': self.showVisCells,
'no-resize': self.noResize,
'manual-plot-area': self.manualPlotArea})
class CHLabelRange(BaseRecordHandler):
def __parseBytes (self):
self.axisCross = self.readUnsignedInt(2)
self.freqLabel = self.readUnsignedInt(2)
self.freqTick = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
self.betweenCateg = (flags & 0x0001) != 0
self.maxCross = (flags & 0x0002) != 0
self.reversed = (flags & 0x0004) != 0
def parseBytes (self):
self.__parseBytes()
self.appendLine("axis crossing: %d"%self.axisCross)
self.appendLine("label frequency: %d"%self.freqLabel)
self.appendLine("tick frequency: %d"%self.freqTick)
self.appendLineBoolean("axis between categories", self.betweenCateg)
self.appendLineBoolean("other axis crosses at maximum", self.maxCross)
self.appendLineBoolean("axis reversed", self.reversed)
def dumpData(self):
self.__parseBytes()
return ('cat-ser-range', {'axis-cross': self.axisCross,
'freq-label': self.freqLabel,
'freq-tick': self.freqTick,
'between-categ': self.betweenCateg,
'max-cross': self.maxCross,
'reversed': self.reversed})
class Legend(BaseRecordHandler):
dockModeMap = {0: 'bottom', 1: 'corner', 2: 'top', 3: 'right', 4: 'left', 7: 'not docked'}
spacingMap = ['close', 'medium', 'open']
def getDockModeText (self, val):
if Legend.dockModeMap.has_key(val):
return Legend.dockModeMap[val]
else:
return '(unknown)'
def getSpacingText (self, val):
if val < len(Legend.spacingMap):
return Legend.spacingMap[val]
else:
return '(unknown)'
def __parseBytes (self):
self.x = self.readSignedInt(4)
self.y = self.readSignedInt(4)
self.w = self.readSignedInt(4)
self.h = self.readSignedInt(4)
self.dockMode = self.readUnsignedInt(1) # [MS-XLS] says unused !?
self.spacing = self.readUnsignedInt(1)
flags = self.readUnsignedInt(2)
self.docked = (flags & 0x0001) != 0
self.autoSeries = (flags & 0x0002) != 0
self.autoPosX = (flags & 0x0004) != 0
self.autoPosY = (flags & 0x0008) != 0
self.stacked = (flags & 0x0010) != 0
self.dataTable = (flags & 0x0020) != 0
def parseBytes (self):
self.__parseBytes()
self.appendLine("legend position: (x, y) = (%d, %d)"%(self.x, self.y))
self.appendLine("legend size: width = %d, height = %d"%(self.w, self.h))
self.appendLine("dock mode: %s"%self.getDockModeText(self.dockMode))
self.appendLine("spacing: %s"%self.getSpacingText(self.spacing))
self.appendLineBoolean("docked", self.docked)
self.appendLineBoolean("auto series", self.autoSeries)
self.appendLineBoolean("auto position x", self.autoPosX)
self.appendLineBoolean("auto position y", self.autoPosY)
self.appendLineBoolean("stacked", self.stacked)
self.appendLineBoolean("data table", self.dataTable)
self.appendLine("")
self.appendMultiLine("NOTE: Position and size are in units of 1/4000 of chart's width or height.")
def dumpData(self):
self.__parseBytes()
return ('legend', {'x': self.x,
'y': self.y,
'w': self.w,
'h': self.h,
'dock-mode': self.dockMode,
'spacing': self.spacing,
'docked': self.docked,
'auto-series': self.autoSeries,
'auto-pos-x': self.autoPosX,
'auto-pos-y': self.autoPosY,
'stacked': self.stacked,
'data-table': self.dataTable})
class CHValueRange(BaseRecordHandler):
def __parseBytes (self):
self.minVal = globals.getDouble(self.readBytes(8))
self.maxVal = globals.getDouble(self.readBytes(8))
self.majorStep = globals.getDouble(self.readBytes(8))
self.minorStep = globals.getDouble(self.readBytes(8))
self.cross = globals.getDouble(self.readBytes(8))
flags = globals.getSignedInt(self.readBytes(2))
self.autoMin = (flags & 0x0001) != 0
self.autoMax = (flags & 0x0002) != 0
self.autoMajor = (flags & 0x0004) != 0
self.autoMinor = (flags & 0x0008) != 0
self.autoCross = (flags & 0x0010) != 0
self.logScale = (flags & 0x0020) != 0
self.reversed = (flags & 0x0040) != 0
self.maxCross = (flags & 0x0080) != 0
self.bit8 = (flags & 0x0100) != 0
def parseBytes (self):
self.__parseBytes()
self.appendLine("min: %g (auto min: %s)"%(self.minVal, self.getYesNo(self.autoMin)))
self.appendLine("max: %g (auto max: %s)"%(self.maxVal, self.getYesNo(self.autoMax)))
self.appendLine("major step: %g (auto major: %s)"%
(self.majorStep, self.getYesNo(self.autoMajor)))
self.appendLine("minor step: %g (auto minor: %s)"%
(self.minorStep, self.getYesNo(self.autoMinor)))
self.appendLine("cross: %g (auto cross: %s) (max cross: %s)"%
(self.cross, self.getYesNo(self.autoCross), self.getYesNo(self.maxCross)))
self.appendLine("biff5 or above: %s"%self.getYesNo(self.bit8))
def dumpData(self):
self.__parseBytes()
return ('value-range', {'min-val': self.minVal,
'max-val': self.maxVal,
'major-step': self.majorStep,
'minor-step': self.minorStep,
'cross': self.cross,
'auto-min': self.autoMin,
'auto-max': self.autoMax,
'auto-major': self.autoMajor,
'auto-minor': self.autoMinor,
'auto-cross': self.autoCross,
'log-scale': self.logScale,
'reversed': self.reversed,
'max-cross': self.maxCross,
'biff5bit': self.bit8})
class CHBar(BaseRecordHandler):
def __parseBytes (self):
self.overlap = globals.getSignedInt(self.readBytes(2))
self.gap = globals.getSignedInt(self.readBytes(2))
flags = globals.getUnsignedInt(self.readBytes(2))
self.horizontal = (flags & 0x0001) != 0
self.stacked = (flags & 0x0002) != 0
self.percent = (flags & 0x0004) != 0
self.shadow = (flags & 0x0008) != 0
def parseBytes (self):
self.__parseBytes()
self.appendLine("overlap width: %d"%self.overlap)
self.appendLine("gap: %d"%self.gap)
self.appendLine("horizontal: %s"%self.getYesNo(self.horizontal))
self.appendLine("stacked: %s"%self.getYesNo(self.stacked))
self.appendLine("percent: %s"%self.getYesNo(self.percent))
self.appendLine("shadow: %s"%self.getYesNo(self.shadow))
def dumpData(self):
self.__parseBytes()
return ('bar', {'overlap': self.overlap,
'gap': self.gap,
'horizontal': self.horizontal,
'stacked': self.stacked,
'shadow': self.shadow})
class CHLine(BaseRecordHandler):
def __parseBytes (self):
flags = globals.getUnsignedInt(self.readBytes(2))
self.stacked = (flags & 0x0001)
self.percent = (flags & 0x0002)
self.shadow = (flags & 0x0004)
def parseBytes (self):
self.__parseBytes()
self.appendLine("stacked: %s"%self.getYesNo(self.stacked))
self.appendLine("percent: %s"%self.getYesNo(self.percent))
self.appendLine("shadow: %s"%self.getYesNo(self.shadow))
def dumpData(self):
self.__parseBytes()
return ('line', {'stacked': self.stacked,
'percent': self.percent,
'shadow': self.shadow})
class CHRadar(BaseRecordHandler):
def __parseBytes (self):
flags = self.readUnsignedInt(2)
self.rdrAxLab = (flags & 0x0001) != 0 # A
self.hasShadow = (flags & 0x0002) != 0 # B
def parseBytes (self):
self.__parseBytes()
self.appendLine("Display category labels: %s"%self.getYesNo(self.rdrAxLab))
self.appendLine("Data markers have shadow: %s"%self.getYesNo(self.hasShadow))
def dumpData(self):
self.__parseBytes()
return ('radar', {'rdr-ax-lab': self.rdrAxLab,
'has-shadow': self.hasShadow})
class CHSurf(BaseRecordHandler):
def __parseBytes (self):
flags = self.readUnsignedInt(2)
self.fillSurface = (flags & 0x0001) != 0 # A
self.phongShade3D = (flags & 0x0002) != 0 # B
def parseBytes (self):
self.__parseBytes()
self.appendLine("Surface has a fill: %s"%self.getYesNo(self.fillSurface))
self.appendLine("3D Phong shading: %s"%self.getYesNo(self.phongShade3D))
def dumpData(self):
self.__parseBytes()
return ('surf', {'fill-surface': self.fillSurface,
'phong-shade-3d': self.phongShade3D})
class CHArea(BaseRecordHandler):
def __parseBytes (self):
flags = self.readUnsignedInt(2)
self.stacked = (flags & 0x0001) != 0 # A
self.f100 = (flags & 0x0002) != 0 # B
self.hasShadow = (flags & 0x0002) != 0 # B
def parseBytes (self):
self.__parseBytes()
self.appendLine("Is stacked: %s"%self.getYesNo(self.stacked))
self.appendLine("Data points are percentage of sum: %s"%self.getYesNo(self.f100))
self.appendLine("Has shadow: %s"%self.getYesNo(self.hasShadow))
def dumpData(self):
self.__parseBytes()
return ('surf', {'stacked': self.stacked,
'f100': self.f100,
'has-shadow': self.hasShadow})
class CHScatter(BaseRecordHandler):
def __parseBytes (self):
self.bubbleSizeRatio = self.readUnsignedInt(2)
self.bubbleSize = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
self.bubbles = (flags & 0x0001) != 0 # A
self.showNegBubbles = (flags & 0x0002) != 0 # B
self.hasShadow = (flags & 0x0004) != 0 # C
def parseBytes (self):
self.__parseBytes()
self.appendLine("Bubble size ratio: %s" % str(self.bubbleSizeRatio))
self.appendLine("Bubble size: %s" % str(self.bubbleSize))
self.appendLine("Is a bubble chart group: %s"%self.getYesNo(self.bubbles))
self.appendLine("Show negative bubbles: %s"%self.getYesNo(self.showNegBubbles))
self.appendLine("Data points have shadow: %s"%self.getYesNo(self.hasShadow))
def dumpData(self):
self.__parseBytes()
return ('pie', {'bubble-size-ratio': self.bubbleSizeRatio,
'bubble-size': self.bubbleSize,
'bubble': self.bubbles,
'show-neg-bubbles': self.showNegBubbles,
'has-shadow': self.hasShadow})
class CHPie(BaseRecordHandler):
def __parseBytes (self):
self.start = self.readUnsignedInt(2)
self.donut = self.readUnsignedInt(2)
flags = self.readUnsignedInt(2)
self.hasShadow = (flags & 0x0001) != 0 # A
self.showLdrLines = (flags & 0x0002) != 0 # B
def parseBytes (self):
self.__parseBytes()
self.appendLine("Start angle: %s"%self.getYesNo(self.start))
self.appendLine("Size of center hole: %s"%self.getYesNo(self.donut))
self.appendLine("Data points have shadow: %s"%self.getYesNo(self.hasShadow))
self.appendLine("Show leader lines: %s"%self.getYesNo(self.showLdrLines))
def dumpData(self):
self.__parseBytes()
return ('pie', {'start': self.start,
'donut': self.donut,
'has-shadow': self.hasShadow,
'show-ldr-Lines': self.showLdrLines})
class Brai(BaseRecordHandler):
destTypes = [
'series, legend entry, trendline name, or error bars name',
'values or horizontal values',
'categories or vertical values',
'bubble size values of the series']
linkTypes = [
'auto-generated category name, series name, or bubble size',
'text or value',
'range of cells']
def __parseBytes (self):
self.id = self.readUnsignedInt(1)
self.rt = self.readUnsignedInt(1)
flag = self.readUnsignedInt(2)
self.unlinkedIFmt = (flag & 0x0001) != 0
self.iFmt = self.readUnsignedInt(2)
tokenBytes = self.readUnsignedInt(2)
self.formulaBytes = self.readBytes(tokenBytes)
self.formula = None
self.formulaError = None
if len(self.formulaBytes) > 0:
parser = formula.FormulaParser(self.header, self.formulaBytes)
try:
parser.parse()
self.formula = parser.getText()
except formula.FormulaParserError as e:
self.formulaError = e.args[0]
def parseBytes (self):
self.__parseBytes()
self.appendLine("part type: %s"%globals.getValueOrUnknown(Brai.destTypes, self.id))
self.appendLine("referenced data type: %s"%globals.getValueOrUnknown(Brai.linkTypes, self.rt))
s = "number format: "
if self.unlinkedIFmt:
s += "custom format"
else:
s += "source data format"
self.appendLine(s)
self.appendLine("number format ID: %d"%self.iFmt)
self.appendLine("formula size (bytes): %d"%len(self.formulaBytes))
if not self.formula is None:
self.appendLine("formula: %s"%self.formula)
else:
self.appendLine("formula parser error: %s"%self.formulaError)
def dumpData(self):
self.__parseBytes()
return ('brai', {'id': self.id,
'rt': self.rt,
'unlinked-ifmt': self.unlinkedIFmt,
'i-fmt': self.iFmt,
'formula': self.formula}) # assuming the formula is fine
class MSODrawing(BaseRecordHandler):
"""Handler for the MSODRAWING record
This record consists of BIFF-like sub-records, with their own headers and
contents. The structure of this record is specified in [MS-ODRAW].pdf found
somewhere in the MSDN website. In case of multiple MSODRAWING records in a
single worksheet stream, they need to be treated as if they are lumped
together.
"""
def __parseBytes (self):
self.msodHdl = msodraw.MSODrawHandler(self.bytes, self)
def parseBytes (self):
self.__parseBytes()
try:
self.msodHdl.parseBytes()
except:
self.appendLine("Error while parsing MSO Drawing record!")
def fillModel (self, model):
self.__parseBytes()
self.msodHdl.fillModel(model)
class MSODrawingGroup(BaseRecordHandler):
def __parseBytes (self):
self.msodHdl = msodraw.MSODrawHandler(self.bytes, self)
def parseBytes (self):
self.__parseBytes()
self.msodHdl.parseBytes()
def fillModel (self, model):
self.__parseBytes()
self.msodHdl.fillModel(model)
class MSODrawingSelection(BaseRecordHandler):
def __parseBytes (self):
self.msodHdl = msodraw.MSODrawHandler(self.bytes, self)
def parseBytes (self):
self.__parseBytes()
self.msodHdl.parseBytes()
def fillModel (self, model):
self.__parseBytes()
self.msodHdl.fillModel(model)
class GelFrame(BaseRecordHandler):
def __parseBytes (self):
self.msodHdl = msodraw.MSODrawHandler(self.bytes, self)
def parseBytes (self):
self.__parseBytes()
# it seems there are errors in msodraw parser :(
#self.msodHdl.parseBytes()
def dumpData(self):
# we don't dump data!
return ('gel-frame', {'bytes': globals.getRawBytes(self.bytes, False, False)})
class Pls(BaseRecordHandler):
def __parseBytes (self):
# DEVMODE is quite a big structure so we don't parse it
pass
def parseBytes (self):
self.__parseBytes()
def dumpData(self):
return ('devmode', {'bytes': globals.getRawBytes(self.bytes, False, False)})
# vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab:
|