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
|
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.streaming;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import org.apache.logging.log4j.Logger;
import org.apache.poi.logging.PoiLogManager;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.PaneInformation;
import org.apache.poi.ss.util.SheetUtil;
import org.apache.poi.util.Internal;
import org.apache.poi.util.NotImplemented;
import org.apache.poi.util.Removal;
import org.apache.poi.xssf.usermodel.*;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
/**
* Streaming version of XSSFSheet implementing the "BigGridDemo" strategy.
*/
public class SXSSFSheet implements Sheet, OoxmlSheetExtensions {
private static final Logger LOG = PoiLogManager.getLogger(SXSSFSheet.class);
/*package*/ final XSSFSheet _sh;
protected final SXSSFWorkbook _workbook;
private final TreeMap<Integer,SXSSFRow> _rows = new TreeMap<>();
protected SheetDataWriter _writer;
private int _randomAccessWindowSize = SXSSFWorkbook.DEFAULT_WINDOW_SIZE;
protected AutoSizeColumnTracker _autoSizeColumnTracker;
private int lastFlushedRowNumber = -1;
private boolean allFlushed;
private int leftMostColumn = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
private int rightMostColumn;
protected SXSSFSheet(SXSSFWorkbook workbook, XSSFSheet xSheet, int randomAccessWindowSize) {
_workbook = workbook;
_sh = xSheet;
calculateLeftAndRightMostColumns(xSheet);
setRandomAccessWindowSize(randomAccessWindowSize);
try {
_autoSizeColumnTracker = new AutoSizeColumnTracker(this);
} catch (UnsatisfiedLinkError | NoClassDefFoundError | InternalError |
// thrown when no fonts are available in the workbook
IndexOutOfBoundsException e) {
// only handle special NoClassDefFound
if (!e.getMessage().contains("X11FontManager")) {
throw e;
}
LOG.atWarn()
.withThrowable(e)
.log("Failed to create AutoSizeColumnTracker, possibly due to fonts not being installed in your OS");
}
}
private void calculateLeftAndRightMostColumns(XSSFSheet xssfSheet) {
if (_workbook.shouldCalculateSheetDimensions()) {
int rowCount = 0;
int leftMostColumn = Integer.MAX_VALUE;
int rightMostColumn = 0;
for (Row row : xssfSheet) {
rowCount++;
if (row.getFirstCellNum() < leftMostColumn) {
final int first = row.getFirstCellNum();
final int last = row.getLastCellNum() - 1;
leftMostColumn = Math.min(first, leftMostColumn);
rightMostColumn = Math.max(last, rightMostColumn);
}
}
if (rowCount > 0) {
this.leftMostColumn = leftMostColumn;
this.rightMostColumn = rightMostColumn;
}
}
}
public SXSSFSheet(SXSSFWorkbook workbook, XSSFSheet xSheet) throws IOException {
_workbook = workbook;
_sh = xSheet;
_writer = workbook.createSheetDataWriter();
setRandomAccessWindowSize(_workbook.getRandomAccessWindowSize());
try {
_autoSizeColumnTracker = new AutoSizeColumnTracker(this);
} catch (UnsatisfiedLinkError | NoClassDefFoundError | InternalError |
// thrown when no fonts are available in the workbook
IndexOutOfBoundsException e) {
// only handle special NoClassDefFound
if (!e.getMessage().contains("X11FontManager")) {
// close temporary resources when throwing exception in the constructor
_writer.close();
throw e;
}
LOG.atWarn()
.withThrowable(e)
.log("Failed to create AutoSizeColumnTracker, possibly due to fonts not being installed in your OS");
} catch (Throwable e) {
// close temporary resources when throwing exception in the constructor
_writer.close();
throw e;
}
}
/**
* for testing purposes only
*/
@Internal
SheetDataWriter getSheetDataWriter(){
return _writer;
}
/* Gets "<sheetData>" document fragment*/
public InputStream getWorksheetXMLInputStream() throws IOException {
// flush all remaining data and close the temp file writer
flushRows(0);
_writer.close();
return _writer.getWorksheetXMLInputStream();
}
//start of interface implementation
/**
* Create a new row within the sheet and return the high level representation
*
* @param rownum row number
* @return high level Row object representing a row in the sheet
* @throws IllegalArgumentException If the max. number of rows is exceeded or
* a rownum is provided where the row is already flushed to disk.
* @see #removeRow(Row)
*/
@Override
public SXSSFRow createRow(int rownum) {
int maxrow = SpreadsheetVersion.EXCEL2007.getLastRowIndex();
if (rownum < 0 || rownum > maxrow) {
throw new IllegalArgumentException("Invalid row number (" + rownum
+ ") outside allowable range (0.." + maxrow + ")");
}
// attempt to overwrite a row that is already flushed to disk
if(_writer != null && rownum <= _writer.getLastFlushedRow() ) {
throw new IllegalArgumentException(
"Attempting to write a row["+rownum+"] " +
"in the range [0," + _writer.getLastFlushedRow() + "] that is already written to disk.");
}
// attempt to overwrite an existing row in the input template
if(_sh.getPhysicalNumberOfRows() > 0 && rownum <= _sh.getLastRowNum() ) {
throw new IllegalArgumentException(
"Attempting to write a row["+rownum+"] " +
"in the range [0," + _sh.getLastRowNum() + "] that is already written to disk.");
}
SXSSFRow newRow = new SXSSFRow(this);
newRow.setRowNumWithoutUpdatingSheet(rownum);
_rows.put(rownum, newRow);
allFlushed = false;
if(_randomAccessWindowSize >= 0 && _rows.size() > _randomAccessWindowSize) {
try {
flushRows(_randomAccessWindowSize);
} catch (IOException ioe) {
throw new IllegalStateException(ioe);
}
}
return newRow;
}
/**
* Remove a row from this sheet. All cells contained in the row are removed as well
*
* @param row representing a row to remove.
*/
@Override
public void removeRow(Row row) {
if (row.getSheet() != this) {
throw new IllegalArgumentException("Specified row does not belong to this sheet");
}
for(Iterator<Map.Entry<Integer, SXSSFRow>> iter = _rows.entrySet().iterator(); iter.hasNext();) {
Map.Entry<Integer, SXSSFRow> entry = iter.next();
if(entry.getValue() == row) {
iter.remove();
return;
}
}
}
/**
* Returns the logical row (not physical) 0-based. If you ask for a row that is not
* defined you get a null. This is to say row 4 represents the fifth row on a sheet.
*
* @param rownum row to get (0-based)
* @return Row representing the rownumber or null if its not defined on the sheet
*/
@Override
public SXSSFRow getRow(int rownum) {
return _rows.get(rownum);
}
/**
* Returns the number of physically defined rows (NOT the number of rows in the sheet)
*
* @return the number of physically defined rows in this sheet
*/
@Override
public int getPhysicalNumberOfRows() {
return _rows.size() + _writer.getNumberOfFlushedRows();
}
/**
* Gets the first row on the sheet
*
* @return the number of the first logical row on the sheet (0-based)
*/
@Override
public int getFirstRowNum() {
if(_writer.getNumberOfFlushedRows() > 0) {
return _writer.getLowestIndexOfFlushedRows();
}
return _rows.isEmpty() ? -1 : _rows.firstKey();
}
/**
* Gets the last row on the sheet
*
* @return last row contained n this sheet (0-based)
*/
@Override
public int getLastRowNum() {
return _rows.isEmpty() ? -1 : _rows.lastKey();
}
/**
* Set the visibility state for a given column
*
* @param columnIndex - the column to get (0-based)
* @param hidden - the visibility state of the column
*/
@Override
public void setColumnHidden(int columnIndex, boolean hidden) {
_sh.setColumnHidden(columnIndex,hidden);
}
/**
* Get the hidden state for a given column
*
* @param columnIndex - the column to set (0-based)
* @return hidden - <code>false</code> if the column is visible
*/
@Override
public boolean isColumnHidden(int columnIndex) {
return _sh.isColumnHidden(columnIndex);
}
/**
* Set the width (in units of 1/256th of a character width)
* <p>
* The maximum column width for an individual cell is 255 characters.
* This value represents the number of characters that can be displayed
* in a cell that is formatted with the standard font.
* </p>
*
* @param columnIndex - the column to set (0-based)
* @param width - the width in units of 1/256th of a character width
*/
@Override
public void setColumnWidth(int columnIndex, int width) {
_sh.setColumnWidth(columnIndex,width);
}
/**
* get the width (in units of 1/256th of a character width )
* @param columnIndex - the column to set (0-based)
* @return width - the width in units of 1/256th of a character width
*/
@Override
public int getColumnWidth(int columnIndex) {
return _sh.getColumnWidth(columnIndex);
}
/**
* Get the actual column width in pixels
*
* <p>
* Please note, that this method works correctly only for workbooks
* with the default font size (Calibri 11pt for .xlsx).
* </p>
*/
@Override
public float getColumnWidthInPixels(int columnIndex) {
return _sh.getColumnWidthInPixels(columnIndex);
}
/**
* Set the default column width for the sheet (if the columns do not define their own width)
* in characters
*
* @param width default column width measured in characters
*/
@Override
public void setDefaultColumnWidth(int width) {
_sh.setDefaultColumnWidth(width);
}
/**
* Get the default column width for the sheet (if the columns do not define their own width)
* in characters
*
* @return default column width measured in characters
*/
@Override
public int getDefaultColumnWidth() {
return _sh.getDefaultColumnWidth();
}
/**
* Get the default row height for the sheet (if the rows do not define their own height) in
* twips (1/20 of a point)
*
* @return default row height measured in twips (1/20 of a point)
*/
@Override
public short getDefaultRowHeight() {
return _sh.getDefaultRowHeight();
}
/**
* Get the default row height for the sheet (if the rows do not define their own height) in
* points.
*
* @return default row height in points
*/
@Override
public float getDefaultRowHeightInPoints() {
return _sh.getDefaultRowHeightInPoints();
}
/**
* Set the default row height for the sheet (if the rows do not define their own height) in
* twips (1/20 of a point)
*
* @param height default row height measured in twips (1/20 of a point)
*/
@Override
public void setDefaultRowHeight(short height) {
_sh.setDefaultRowHeight(height);
}
/**
* Set the default row height for the sheet (if the rows do not define their own height) in
* points
* @param height default row height
*/
@Override
public void setDefaultRowHeightInPoints(float height) {
_sh.setDefaultRowHeightInPoints(height);
}
/**
* Get VML drawing for this sheet (aka 'legacy' drawing).
*
* @param autoCreate if true, then a new VML drawing part is created
*
* @return the VML drawing of {@code null} if the drawing was not found and autoCreate=false
* @since POI 5.2.0
*/
public XSSFVMLDrawing getVMLDrawing(boolean autoCreate) {
XSSFSheet xssfSheet = getWorkbook().getXSSFSheet(this);
return xssfSheet == null ? null : xssfSheet.getVMLDrawing(autoCreate);
}
/**
* Returns the CellStyle that applies to the given
* (0 based) column, or null if no style has been
* set for that column
*/
@Override
public CellStyle getColumnStyle(int column) {
return _sh.getColumnStyle(column);
}
/*
* Sets the CellStyle that applies to the given
* (0 based) column.
*/
// public CellStyle setColumnStyle(int column, CellStyle style);
/**
* Adds a merged region of cells (hence those cells form one)
*
* @param region (rowfrom/colfrom-rowto/colto) to merge
* @return index of this region
*/
@Override
public int addMergedRegion(CellRangeAddress region) {
return _sh.addMergedRegion(region);
}
/**
* Adds a merged region of cells (hence those cells form one)
*
* @param region (rowfrom/colfrom-rowto/colto) to merge
* @return index of this region
*/
@Override
public int addMergedRegionUnsafe(CellRangeAddress region) {
return _sh.addMergedRegionUnsafe(region);
}
/**
* Verify that merged regions do not intersect multi-cell array formulas and
* no merged regions intersect another merged region in this sheet.
*
* @throws IllegalStateException if region intersects with a multi-cell array formula
* @throws IllegalStateException if at least one region intersects with another merged region in this sheet
*/
@Override
public void validateMergedRegions() {
_sh.validateMergedRegions();
}
/**
* Determines whether the output is vertically centered on the page.
*
* @param value true to vertically center, false otherwise.
*/
@Override
public void setVerticallyCenter(boolean value) {
_sh.setVerticallyCenter(value);
}
/**
* Determines whether the output is horizontally centered on the page.
*
* @param value true to horizontally center, false otherwise.
*/
@Override
public void setHorizontallyCenter(boolean value) {
_sh.setHorizontallyCenter(value);
}
/**
* Determine whether printed output for this sheet will be horizontally centered.
*/
@Override
public boolean getHorizontallyCenter() {
return _sh.getHorizontallyCenter();
}
/**
* Determine whether printed output for this sheet will be vertically centered.
*/
@Override
public boolean getVerticallyCenter() {
return _sh.getVerticallyCenter();
}
/**
* Removes a merged region of cells (hence letting them free)
*
* @param index of the region to unmerge
*/
@Override
public void removeMergedRegion(int index) {
_sh.removeMergedRegion(index);
}
/**
* Removes a merged region of cells (hence letting them free)
*
* @param indices of the regions to unmerge
*/
@Override
public void removeMergedRegions(Collection<Integer> indices) {
_sh.removeMergedRegions(indices);
}
/**
* Returns the number of merged regions
*
* @return number of merged regions
*/
@Override
public int getNumMergedRegions() {
return _sh.getNumMergedRegions();
}
/**
* Returns the merged region at the specified index. If you want multiple
* regions, it is faster to call {@link #getMergedRegions()} than to call
* this each time.
*
* @return the merged region at the specified index
*/
@Override
public CellRangeAddress getMergedRegion(int index) {
return _sh.getMergedRegion(index);
}
/**
* Returns the list of merged regions. If you want multiple regions, this is
* faster than calling {@link #getMergedRegion(int)} each time.
*
* @return the list of merged regions
*/
@Override
public List<CellRangeAddress> getMergedRegions() {
return _sh.getMergedRegions();
}
/**
* Returns an iterator of the physical rows
*
* @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not
* be the third row if say for instance the second row is undefined.
*/
@Override
public Iterator<Row> rowIterator() {
@SuppressWarnings("unchecked")
Iterator<Row> result = (Iterator<Row>)(Iterator<? extends Row>)_rows.values().iterator();
return result;
}
/**
* Returns a spliterator of the physical rows
*
* @return a spliterator of the PHYSICAL rows. Meaning the 3rd element may not
* be the third row if say for instance the second row is undefined.
*
* @since POI 5.2.0
*/
@Override
@SuppressWarnings("unchecked")
public Spliterator<Row> spliterator() {
return (Spliterator<Row>)(Spliterator<? extends Row>) _rows.values().spliterator();
}
/**
* Flag indicating whether the sheet displays Automatic Page Breaks.
*
* @param value <code>true</code> if the sheet displays Automatic Page Breaks.
*/
@Override
public void setAutobreaks(boolean value) {
_sh.setAutobreaks(value);
}
/**
* Set whether to display the guts or not
*
* @param value - guts or no guts
*/
@Override
public void setDisplayGuts(boolean value) {
_sh.setDisplayGuts(value);
}
/**
* Set whether the window should show 0 (zero) in cells containing zero value.
* When false, cells with zero value appear blank instead of showing the number zero.
*
* @param value whether to display or hide all zero values on the worksheet
*/
@Override
public void setDisplayZeros(boolean value) {
_sh.setDisplayZeros(value);
}
/**
* Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value.
* When false, cells with zero value appear blank instead of showing the number zero.
*
* @return whether all zero values on the worksheet are displayed
*/
@Override
public boolean isDisplayZeros() {
return _sh.isDisplayZeros();
}
/**
* Sets whether the worksheet is displayed from right to left instead of from left to right.
*
* @param value true for right to left, false otherwise.
*/
@Override
public void setRightToLeft(boolean value) {
_sh.setRightToLeft(value);
}
/**
* Whether the text is displayed in right-to-left mode in the window
*
* @return whether the text is displayed in right-to-left mode in the window
*/
@Override
public boolean isRightToLeft() {
return _sh.isRightToLeft();
}
/**
* Flag indicating whether the Fit to Page print option is enabled.
*
* @param value <code>true</code> if the Fit to Page print option is enabled.
*/
@Override
public void setFitToPage(boolean value) {
_sh.setFitToPage(value);
}
/**
* Flag indicating whether summary rows appear below detail in an outline, when applying an outline.
*
* <p>
* When true a summary row is inserted below the detailed data being summarized and a
* new outline level is established on that row.
* </p>
* <p>
* When false a summary row is inserted above the detailed data being summarized and a new outline level
* is established on that row.
* </p>
* @param value <code>true</code> if row summaries appear below detail in the outline
*/
@Override
public void setRowSumsBelow(boolean value) {
_sh.setRowSumsBelow(value);
}
/**
* Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.
*
* <p>
* When true a summary column is inserted to the right of the detailed data being summarized
* and a new outline level is established on that column.
* </p>
* <p>
* When false a summary column is inserted to the left of the detailed data being
* summarized and a new outline level is established on that column.
* </p>
* @param value <code>true</code> if col summaries appear right of the detail in the outline
*/
@Override
public void setRowSumsRight(boolean value) {
_sh.setRowSumsRight(value);
}
/**
* Flag indicating whether the sheet displays Automatic Page Breaks.
*
* @return <code>true</code> if the sheet displays Automatic Page Breaks.
*/
@Override
public boolean getAutobreaks() {
return _sh.getAutobreaks();
}
/**
* Get whether to display the guts or not,
* default value is true
*
* @return boolean - guts or no guts
*/
@Override
public boolean getDisplayGuts() {
return _sh.getDisplayGuts();
}
/**
* Flag indicating whether the Fit to Page print option is enabled.
*
* @return <code>true</code> if the Fit to Page print option is enabled.
*/
@Override
public boolean getFitToPage() {
return _sh.getFitToPage();
}
/**
* Flag indicating whether summary rows appear below detail in an outline, when applying an outline.
*
* <p>
* When true a summary row is inserted below the detailed data being summarized and a
* new outline level is established on that row.
* </p>
* <p>
* When false a summary row is inserted above the detailed data being summarized and a new outline level
* is established on that row.
* </p>
* @return <code>true</code> if row summaries appear below detail in the outline
*/
@Override
public boolean getRowSumsBelow() {
return _sh.getRowSumsBelow();
}
/**
* Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.
*
* <p>
* When true a summary column is inserted to the right of the detailed data being summarized
* and a new outline level is established on that column.
* </p>
* <p>
* When false a summary column is inserted to the left of the detailed data being
* summarized and a new outline level is established on that column.
* </p>
* @return <code>true</code> if col summaries appear right of the detail in the outline
*/
@Override
public boolean getRowSumsRight() {
return _sh.getRowSumsRight();
}
/**
* Returns whether gridlines are printed.
*
* @return whether gridlines are printed
*/
@Override
public boolean isPrintGridlines() {
return _sh.isPrintGridlines();
}
/**
* Turns on or off the printing of gridlines.
*
* @param show boolean to turn on or off the printing of gridlines
*/
@Override
public void setPrintGridlines(boolean show) {
_sh.setPrintGridlines(show);
}
/**
* Returns whether row and column headings are printed.
*
* @return whether row and column headings are printed
*/
@Override
public boolean isPrintRowAndColumnHeadings() {
return _sh.isPrintRowAndColumnHeadings();
}
/**
* Turns on or off the printing of row and column headings.
*
* @param show boolean to turn on or off the printing of row and column headings
*/
@Override
public void setPrintRowAndColumnHeadings(boolean show) {
_sh.setPrintRowAndColumnHeadings(show);
}
/**
* Gets the print setup object.
*
* @return The user model for the print setup object.
*/
@Override
public PrintSetup getPrintSetup() {
return _sh.getPrintSetup();
}
/**
* Gets the user model for the default document header.
* <p>
* Note that XSSF offers more kinds of document headers than HSSF does
* </p>
* @return the document header. Never <code>null</code>
*/
@Override
public Header getHeader() {
return _sh.getHeader();
}
/**
* Gets the user model for the default document footer.
* <p>
* Note that XSSF offers more kinds of document footers than HSSF does.
* </p>
* @return the document footer. Never <code>null</code>
*/
@Override
public Footer getFooter() {
return _sh.getFooter();
}
/**
* Sets a flag indicating whether this sheet is selected.
* <p>
* Note: multiple sheets can be selected, but only one sheet can be active at one time.
* </p>
* @param value <code>true</code> if this sheet is selected
* @see Workbook#setActiveSheet(int)
*/
@Override
public void setSelected(boolean value) {
_sh.setSelected(value);
}
/**
* Gets the size of the margin in inches.
*
* @param margin which margin to get
* @return the size of the margin
* @deprecated use {@link #getMargin(PageMargin)}
*/
@Override
@Deprecated
@Removal(version = "7.0.0")
public double getMargin(short margin) {
return _sh.getMargin(margin);
}
/**
* Gets the size of the margin in inches.
*
* @param margin which margin to get
* @return the size of the margin
* @since POI 5.2.3
*/
@Override
public double getMargin(PageMargin margin) {
return _sh.getMargin(margin);
}
/**
* Sets the size of the margin in inches.
*
* @param margin which margin to set
* @param size the size of the margin
* @see Sheet#LeftMargin
* @see Sheet#RightMargin
* @see Sheet#TopMargin
* @see Sheet#BottomMargin
* @see Sheet#HeaderMargin
* @see Sheet#FooterMargin
* @deprecated use {@link #setMargin(PageMargin, double)} instead
*/
@Override
@Deprecated
@Removal(version = "7.0.0")
public void setMargin(short margin, double size) {
_sh.setMargin(margin, size);
}
/**
* Sets the size of the margin in inches.
*
* @param margin which margin to set
* @param size the size of the margin
* @since POI 5.2.3
*/
@Override
public void setMargin(PageMargin margin, double size) {
_sh.setMargin(margin, size);
}
/**
* Answer whether protection is enabled or disabled
*
* @return true means protection enabled; false means protection disabled
*/
@Override
public boolean getProtect() {
return _sh.getProtect();
}
/**
* Sets the protection enabled as well as the password
* @param password to set for protection. Pass <code>null</code> to remove protection
*/
@Override
public void protectSheet(String password) {
_sh.protectSheet(password);
}
/**
* Answer whether scenario protection is enabled or disabled
*
* @return true means protection enabled; false means protection disabled
*/
@Override
public boolean getScenarioProtect() {
return _sh.getScenarioProtect();
}
/**
* Window zoom magnification for current view representing percent values.
* Valid values range from 10 to 400. Horizontal and Vertical scale together.
*
* For example:
* <pre>
* 10 - 10%
* 20 - 20%
* ...
* 100 - 100%
* ...
* 400 - 400%
* </pre>
*
* Current view can be Normal, Page Layout, or Page Break Preview.
*
* @param scale window zoom magnification
* @throws IllegalArgumentException if scale is invalid
*/
@Override
public void setZoom(int scale) {
_sh.setZoom(scale);
}
/**
* The top row in the visible view when the sheet is
* first viewed after opening it in a viewer
*
* @return short indicating the rownum (0 based) of the top row
*/
@Override
public short getTopRow() {
return _sh.getTopRow();
}
/**
* The left col in the visible view when the sheet is
* first viewed after opening it in a viewer
*
* @return short indicating the rownum (0 based) of the top row
*/
@Override
public short getLeftCol() {
return _sh.getLeftCol();
}
/**
* Sets desktop window pane display area, when the
* file is first opened in a viewer.
*
* @param topRow the top row to show in desktop window pane
* @param leftCol the left column to show in desktop window pane
*/
@Override
public void showInPane(int topRow, int leftCol) {
_sh.showInPane(topRow, leftCol);
}
/**
* Control if Excel should be asked to recalculate all formulas when the
* workbook is opened, via the "sheetCalcPr fullCalcOnLoad" option.
* Calculating the formula values with {@link org.apache.poi.ss.usermodel.FormulaEvaluator} is the
* recommended solution, but this may be used for certain cases where
* evaluation in POI is not possible.
*/
@Override
public void setForceFormulaRecalculation(boolean value) {
_sh.setForceFormulaRecalculation(value);
}
/**
* Whether Excel will be asked to recalculate all formulas when the
* workbook is opened.
*/
@Override
public boolean getForceFormulaRecalculation() {
return _sh.getForceFormulaRecalculation();
}
/**
* <i>Not implemented for SXSSFSheets</i>
*
* Shifts rows between startRow and endRow n number of rows.
* If you use a negative number, it will shift rows up.
* Code ensures that rows don't wrap around.
*
* Calls shiftRows(startRow, endRow, n, false, false);
*
* <p>
* Additionally shifts merged regions that are completely defined in these
* rows (ie. merged 2 cells on a row to be shifted).
* @param startRow the row to start shifting
* @param endRow the row to end shifting
* @param n the number of rows to shift
*/
@NotImplemented
@Override
public void shiftRows(int startRow, int endRow, int n) {
throw new IllegalStateException("Not Implemented");
}
/**
* <i>Not implemented for SXSSFSheets</i>
*
* Shifts rows between startRow and endRow n number of rows.
* If you use a negative number, it will shift rows up.
* Code ensures that rows don't wrap around
*
* <p>
* Additionally shifts merged regions that are completely defined in these
* rows (ie. merged 2 cells on a row to be shifted). All merged regions that are
* completely overlaid by shifting will be deleted.
*
* @param startRow the row to start shifting
* @param endRow the row to end shifting
* @param n the number of rows to shift
* @param copyRowHeight whether to copy the row height during the shift
* @param resetOriginalRowHeight whether to set the original row's height to the default
*/
@NotImplemented
@Override
public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) {
throw new IllegalStateException("Not Implemented");
}
/**
* Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
* @param colSplit Horizontal position of split.
* @param rowSplit Vertical position of split.
* @param leftmostColumn Left column visible in right pane.
* @param topRow Top row visible in bottom pane
*/
@Override
public void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow) {
_sh.createFreezePane(colSplit, rowSplit, leftmostColumn, topRow);
}
/**
* Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
* @param colSplit Horizontal position of split.
* @param rowSplit Vertical position of split.
*/
@Override
public void createFreezePane(int colSplit, int rowSplit) {
_sh.createFreezePane(colSplit, rowSplit);
}
/**
* Creates a split pane. Any existing freezepane or split pane is overwritten.
* @param xSplitPos Horizontal position of split (in 1/20th of a point).
* @param ySplitPos Vertical position of split (in 1/20th of a point).
* @param topRow Top row visible in bottom pane
* @param leftmostColumn Left column visible in right pane.
* @param activePane Active pane. One of: PANE_LOWER_RIGHT,
* PANE_UPPER_RIGHT, PANE_LOWER_LEFT, PANE_UPPER_LEFT (but there is a
* <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=66173">bug</a>, so add 1)
* @see #PANE_LOWER_LEFT
* @see #PANE_LOWER_RIGHT
* @see #PANE_UPPER_LEFT
* @see #PANE_UPPER_RIGHT
* @deprecated use {@link #createSplitPane(int, int, int, int, PaneType)}
*/
@Override
@Deprecated
@Removal(version = "7.0.0")
public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane) {
_sh.createSplitPane(xSplitPos, ySplitPos, leftmostColumn, topRow, activePane);
}
/**
* Creates a split pane. Any existing freezepane or split pane is overwritten.
* @param xSplitPos Horizontal position of split (in 1/20th of a point).
* @param ySplitPos Vertical position of split (in 1/20th of a point).
* @param topRow Top row visible in bottom pane
* @param leftmostColumn Left column visible in right pane.
* @param activePane Active pane.
* @see PaneType
* @since POI 5.2.3
*/
@Override
public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, PaneType activePane) {
_sh.createSplitPane(xSplitPos, ySplitPos, leftmostColumn, topRow, activePane);
}
/**
* Returns the information regarding the currently configured pane (split or freeze)
*
* @return null if no pane configured, or the pane information.
*/
@Override
public PaneInformation getPaneInformation() {
return _sh.getPaneInformation();
}
/**
* Sets whether the gridlines are shown in a viewer
*
* @param show whether to show gridlines or not
*/
@Override
public void setDisplayGridlines(boolean show) {
_sh.setDisplayGridlines(show);
}
/**
* Returns if gridlines are displayed
*
* @return whether gridlines are displayed
*/
@Override
public boolean isDisplayGridlines() {
return _sh.isDisplayGridlines();
}
/**
* Sets whether the formulas are shown in a viewer
*
* @param show whether to show formulas or not
*/
@Override
public void setDisplayFormulas(boolean show) {
_sh.setDisplayFormulas(show);
}
/**
* Returns if formulas are displayed
*
* @return whether formulas are displayed
*/
@Override
public boolean isDisplayFormulas() {
return _sh.isDisplayFormulas();
}
/**
* Sets whether the RowColHeadings are shown in a viewer
*
* @param show whether to show RowColHeadings or not
*/
@Override
public void setDisplayRowColHeadings(boolean show) {
_sh.setDisplayRowColHeadings(show);
}
/**
* Returns if RowColHeadings are displayed.
* @return whether RowColHeadings are displayed
*/
@Override
public boolean isDisplayRowColHeadings() {
return _sh.isDisplayRowColHeadings();
}
/**
* Sets a page break at the indicated row
* Breaks occur above the specified row and left of the specified column inclusive.
*
* For example, {@code sheet.setColumnBreak(2);} breaks the sheet into two parts
* with columns A,B,C in the first and D,E,... in the second. Similar, {@code sheet.setRowBreak(2);}
* breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
* and rows starting with rownum=4 in the second.
*
* @param row the row to break, inclusive
*/
@Override
public void setRowBreak(int row) {
_sh.setRowBreak(row);
}
/**
* Determines if there is a page break at the indicated row
* @param row The row to check
* @return true if there is a page-break at the given row, false otherwise
*/
@Override
public boolean isRowBroken(int row) {
return _sh.isRowBroken(row);
}
/**
* Removes the page break at the indicated row
* @param row The row to remove page breaks from
*/
@Override
public void removeRowBreak(int row) {
_sh.removeRowBreak(row);
}
/**
* Retrieves all the horizontal page breaks
* @return all the horizontal page breaks, or null if there are no row page breaks
*/
@Override
public int[] getRowBreaks() {
return _sh.getRowBreaks();
}
/**
* Retrieves all the vertical page breaks
* @return all the vertical page breaks, or null if there are no column page breaks
*/
@Override
public int[] getColumnBreaks() {
return _sh.getColumnBreaks();
}
/**
* Sets a page break at the indicated column
* @param column The column to work on
*/
@Override
public void setColumnBreak(int column) {
_sh.setColumnBreak(column);
}
/**
* Determines if there is a page break at the indicated column
* @param column The column to check for page breaks
* @return true if there is a page break at the given column, false otherwise
*/
@Override
public boolean isColumnBroken(int column) {
return _sh.isColumnBroken(column);
}
/**
* Removes a page break at the indicated column
* @param column The column to remove a page break from
*/
@Override
public void removeColumnBreak(int column) {
_sh.removeColumnBreak(column);
}
/**
* Expands or collapses a column group.
*
* @param columnNumber One of the columns in the group.
* @param collapsed true = collapse group, false = expand group.
*/
@Override
public void setColumnGroupCollapsed(int columnNumber, boolean collapsed) {
_sh.setColumnGroupCollapsed(columnNumber, collapsed);
}
/**
* Create an outline for the provided column range.
*
* @param fromColumn beginning of the column range.
* @param toColumn end of the column range.
*/
@Override
public void groupColumn(int fromColumn, int toColumn) {
_sh.groupColumn(fromColumn, toColumn);
}
/**
* Ungroup a range of columns that were previously grouped
*
* @param fromColumn start column (0-based)
* @param toColumn end column (0-based)
*/
@Override
public void ungroupColumn(int fromColumn, int toColumn) {
_sh.ungroupColumn(fromColumn, toColumn);
}
/**
* Tie a range of rows together so that they can be collapsed or expanded
*
* <p>
* Please note the rows being grouped <em>must</em> be in the current window,
* if the rows are already flushed then groupRow has no effect.
* </p>
*
* Correct code:
* <pre><code>
* Workbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory
* Sheet sh = wb.createSheet();
* for (int rownum = 0; rownum < 1000; rownum++) {
* Row row = sh.createRow(rownum);
* if(rownum == 200) {
* sh.groupRow(100, 200);
* }
* }
*
* </code></pre>
*
*
* Incorrect code:
* <pre><code>
* Workbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory
* Sheet sh = wb.createSheet();
* for (int rownum = 0; rownum < 1000; rownum++) {
* Row row = sh.createRow(rownum);
* }
* sh.groupRow(100, 200); // the rows in the range [100, 200] are already flushed and groupRows has no effect
*
* </code></pre>
*
*
* @param fromRow start row (0-based)
* @param toRow end row (0-based)
*/
@Override
public void groupRow(int fromRow, int toRow) {
int maxLevelRow = -1;
for(SXSSFRow row : _rows.subMap(fromRow, toRow + 1).values()){
final int level = row.getOutlineLevel() + 1;
row.setOutlineLevel(level);
maxLevelRow = Math.max(maxLevelRow, level);
}
setWorksheetOutlineLevelRowIfNecessary((short) Math.min(Short.MAX_VALUE, maxLevelRow));
}
/**
* Set row groupings (like groupRow) in a stream-friendly manner
*
* <p>
* groupRows requires all rows in the group to be in the current window.
* This is not always practical. Instead use setRowOutlineLevel to
* explicitly set the group level. Level 1 is the top level group,
* followed by 2, etc. It is up to the user to ensure that level 2
* groups are correctly nested under level 1, etc.
* </p>
*
* @param rownum index of row to update (0-based)
* @param level outline level (greater than 0)
*/
public void setRowOutlineLevel(int rownum, int level) {
SXSSFRow row = _rows.get(rownum);
row.setOutlineLevel(level);
setWorksheetOutlineLevelRowIfNecessary((short) Math.min(Short.MAX_VALUE, level));
}
private void setWorksheetOutlineLevelRowIfNecessary(final short levelRow) {
CTWorksheet ct = _sh.getCTWorksheet();
CTSheetFormatPr pr = ct.isSetSheetFormatPr() ?
ct.getSheetFormatPr() :
ct.addNewSheetFormatPr();
if(levelRow > _sh.getSheetFormatPrOutlineLevelRow()) {
pr.setOutlineLevelRow(levelRow);
}
}
/**
* Ungroup a range of rows that were previously grouped
*
* @param fromRow start row (0-based)
* @param toRow end row (0-based)
*/
@Override
public void ungroupRow(int fromRow, int toRow) {
_sh.ungroupRow(fromRow, toRow);
}
/**
* Set view state of a grouped range of rows.
*
* <i>Not implemented for expanding (i.e. collapse == false)</i>
*
* @param row start row of a grouped range of rows (0-based)
* @param collapse whether to expand/collapse the detail rows
* @throws IllegalStateException if collapse is false as this is not implemented for SXSSF.
*/
@Override
public void setRowGroupCollapsed(int row, boolean collapse) {
if (collapse) {
collapseRow(row);
} else {
//expandRow(rowIndex);
throw new IllegalStateException("Unable to expand row: Not Implemented");
}
}
/**
* @param rowIndex the zero based row index to collapse
*/
private void collapseRow(int rowIndex) {
SXSSFRow row = getRow(rowIndex);
if(row == null) {
throw new IllegalArgumentException("Invalid row number("+ rowIndex + "). Row does not exist.");
} else {
int startRow = findStartOfRowOutlineGroup(rowIndex);
// Hide all the columns until the end of the group
int lastRow = writeHidden(row, startRow);
SXSSFRow lastRowObj = getRow(lastRow);
if (lastRowObj != null) {
lastRowObj.setCollapsed(true);
} else {
SXSSFRow newRow = createRow(lastRow);
newRow.setCollapsed(true);
}
}
}
/**
* @param rowIndex the zero based row index to find from
*/
private int findStartOfRowOutlineGroup(int rowIndex) {
// Find the start of the group.
Row row = getRow(rowIndex);
int level = row.getOutlineLevel();
if(level == 0) {
throw new IllegalArgumentException("Outline level is zero for the row (" + rowIndex + ").");
}
int currentRow = rowIndex;
while (getRow(currentRow) != null) {
if (getRow(currentRow).getOutlineLevel() < level) {
return currentRow + 1;
}
currentRow--;
}
return currentRow + 1;
}
private int writeHidden(SXSSFRow xRow, int rowIndex) {
int level = xRow.getOutlineLevel();
SXSSFRow currRow = getRow(rowIndex);
while (currRow != null && currRow.getOutlineLevel() >= level) {
currRow.setHidden(true);
rowIndex++;
currRow = getRow(rowIndex);
}
return rowIndex;
}
/**
* Sets the default column style for a given column. POI will only apply this style to new cells added to the sheet.
*
* @param column the column index
* @param style the style to set
*/
@Override
public void setDefaultColumnStyle(int column, CellStyle style) {
_sh.setDefaultColumnStyle(column, style);
}
/**
* Set the extra width added to the best-fit column width (default 0.0).
*
* @param arbitraryExtraWidth the extra width added to the best-fit column width
* @throws IllegalStateException if autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)
* @since 5.4.0
*/
public void setArbitraryExtraWidth(final double arbitraryExtraWidth) {
if (_autoSizeColumnTracker == null) {
throw new IllegalStateException("Cannot trackColumnForAutoSizing because autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)");
}
_autoSizeColumnTracker.setArbitraryExtraWidth(arbitraryExtraWidth);
}
/**
* Get the extra width added to the best-fit column width.
*
* @return the extra width added to the best-fit column width
* @throws IllegalStateException if autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)
* @since 5.4.0
*/
public double getArbitraryExtraWidth() {
if (_autoSizeColumnTracker == null) {
throw new IllegalStateException("Cannot trackColumnForAutoSizing because autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)");
}
return _autoSizeColumnTracker.getArbitraryExtraWidth();
}
/**
* Track a column in the sheet for auto-sizing.
* Note this has undefined behavior if a column is tracked after one or more rows are written to the sheet.
* If <code>column</code> is already tracked, this call does nothing.
*
* @param column the column to track for auto-sizing
* @throws IllegalStateException if autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)
* @since 3.14beta1
* @see #trackColumnsForAutoSizing(Collection)
* @see #trackAllColumnsForAutoSizing()
*/
public void trackColumnForAutoSizing(int column) {
if (_autoSizeColumnTracker == null) {
throw new IllegalStateException("Cannot trackColumnForAutoSizing because autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)");
}
_autoSizeColumnTracker.trackColumn(column);
}
/**
* Track several columns in the sheet for auto-sizing.
* Note this has undefined behavior if columns are tracked after one or more rows are written to the sheet.
* Any column in <code>columns</code> that are already tracked are ignored by this call.
*
* @param columns the columns to track for auto-sizing
* @throws IllegalStateException if autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)
* @since 3.14beta1
*/
public void trackColumnsForAutoSizing(Collection<Integer> columns) {
if (_autoSizeColumnTracker == null) {
throw new IllegalStateException("Cannot trackColumnForAutoSizing because autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)");
}
_autoSizeColumnTracker.trackColumns(columns);
}
/**
* Tracks all columns in the sheet for auto-sizing. If this is called, individual columns do not need to be tracked.
* Because determining the best-fit width for a cell is expensive, this may affect the performance.
* @throws IllegalStateException if autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)
* @since 3.14beta1
*/
public void trackAllColumnsForAutoSizing() {
if (_autoSizeColumnTracker == null) {
throw new IllegalStateException("Cannot trackColumnForAutoSizing because autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)");
}
_autoSizeColumnTracker.trackAllColumns();
}
/**
* Removes a column that was previously marked for inclusion in auto-size column tracking.
* When a column is untracked, the best-fit width is forgotten.
* If <code>column</code> is not tracked, it will be ignored by this call.
*
* @param column the index of the column to track for auto-sizing
* @return true if column was tracked prior to this call, false if no action was taken
* @since 3.14beta1
* @see #untrackColumnsForAutoSizing(Collection)
* @see #untrackAllColumnsForAutoSizing()
*/
public boolean untrackColumnForAutoSizing(int column) {
return _autoSizeColumnTracker != null && _autoSizeColumnTracker.untrackColumn(column);
}
/**
* Untracks several columns in the sheet for auto-sizing.
* When a column is untracked, the best-fit width is forgotten.
* Any column in <code>columns</code> that is not tracked will be ignored by this call.
*
* @param columns the indices of the columns to track for auto-sizing
* @return true if one or more columns were untracked as a result of this call
* @since 3.14beta1
*/
public boolean untrackColumnsForAutoSizing(Collection<Integer> columns) {
return _autoSizeColumnTracker != null && _autoSizeColumnTracker.untrackColumns(columns);
}
/**
* Untracks all columns in the sheet for auto-sizing. Best-fit column widths are forgotten.
* If this is called, individual columns do not need to be untracked.
* @since 3.14beta1
*/
public void untrackAllColumnsForAutoSizing() {
if (_autoSizeColumnTracker != null) {
_autoSizeColumnTracker.untrackAllColumns();
}
}
/**
* Returns true if column is currently tracked for auto-sizing.
*
* @param column the index of the column to check
* @return true if column is tracked
* @since 3.14beta1
*/
public boolean isColumnTrackedForAutoSizing(int column) {
return _autoSizeColumnTracker != null && _autoSizeColumnTracker.isColumnTracked(column);
}
/**
* Get the currently tracked columns for auto-sizing.
* Note if all columns are tracked, this will only return the columns that have been explicitly or implicitly tracked,
* which is probably only columns containing 1 or more non-blank values
*
* @return a set of the indices of all tracked columns
* @since 3.14beta1
*/
public Set<Integer> getTrackedColumnsForAutoSizing() {
return _autoSizeColumnTracker == null ? Collections.emptySet() : _autoSizeColumnTracker.getTrackedColumns();
}
/**
* Adjusts the column width to fit the contents.
*
* <p>
* This process can be relatively slow on large sheets, so this should
* normally only be called once per column, at the end of your
* processing.
* </p>
* You can specify whether the content of merged cells should be considered or ignored.
* Default is to ignore merged cells.
*
* <p>
* Special note about SXSSF implementation: You must register the columns you wish to track with
* the SXSSFSheet using {@link #trackColumnForAutoSizing(int)} or {@link #trackAllColumnsForAutoSizing()}.
* This is needed because the rows needed to compute the column width may have fallen outside the
* random access window and been flushed to disk.
* Tracking columns is required even if all rows are in the random access window.
* </p>
* <p><i>New in POI 3.14 beta 1: auto-sizes columns using cells from current and flushed rows.</i></p>
*
* @param column the column index to auto-size
*/
@Override
public void autoSizeColumn(int column) {
autoSizeColumn(column, false);
}
/**
* Adjusts the column width to fit the contents.
* <p>
* This process can be relatively slow on large sheets, so this should
* normally only be called once per column, at the end of your
* processing.
* </p>
* You can specify whether the content of merged cells should be considered or ignored.
* Default is to ignore merged cells.
*
* <p>
* Special note about SXSSF implementation: You must register the columns you wish to track with
* the SXSSFSheet using {@link #trackColumnForAutoSizing(int)} or {@link #trackAllColumnsForAutoSizing()}.
* This is needed because the rows needed to compute the column width may have fallen outside the
* random access window and been flushed to disk.
* Tracking columns is required even if all rows are in the random access window.
* </p>
* <p><i>New in POI 3.14 beta 1: auto-sizes columns using cells from current and flushed rows.</i></p>
*
* @param column the column index to auto-size
* @param useMergedCells whether to use the contents of merged cells when calculating the width of the column
* @throws IllegalStateException if autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)
*/
@Override
public void autoSizeColumn(int column, boolean useMergedCells) {
if (_autoSizeColumnTracker == null) {
throw new IllegalStateException("Cannot trackColumnForAutoSizing because autoSizeColumnTracker failed to initialize (possibly due to fonts not being installed in your OS)");
}
// Multiple calls to autoSizeColumn need to look up the best-fit width
// of rows already flushed to disk plus re-calculate the best-fit width
// of rows in the current window. It isn't safe to update the column
// widths before flushing to disk because columns in the random access
// window rows may change in best-fit width. The best-fit width of a cell
// is only fixed when it becomes inaccessible for modification.
// Changes to the shared strings table, styles table, or formulas might
// be able to invalidate the auto-size width without the opportunity
// to recalculate the best-fit width for the flushed rows. This is an
// inherent limitation of SXSSF. If having correct auto-sizing is
// critical, the flushed rows would need to be re-read by the read-only
// XSSF eventmodel (SAX) or the memory-heavy XSSF usermodel (DOM).
final int flushedWidth;
try {
// get the best fit width of rows already flushed to disk
flushedWidth = _autoSizeColumnTracker.getBestFitColumnWidth(column, useMergedCells);
}
catch (final IllegalStateException e) {
throw new IllegalStateException("Could not auto-size column. Make sure the column was tracked prior to auto-sizing the column.", e);
}
// get the best-fit width of rows currently in the random access window
final double w1 = SheetUtil.getColumnWidth(this, column, useMergedCells);
final int activeWidth = (int) ((256 * w1) + getArbitraryExtraWidth());
// the best-fit width for both flushed rows and random access window rows
// flushedWidth or activeWidth may be negative if column contains only blank cells
final int bestFitWidth = Math.max(flushedWidth, activeWidth);
if (bestFitWidth > 0) {
final int maxColumnWidth = 255*256; // The maximum column width for an individual cell is 255 characters
final int width = Math.min(bestFitWidth, maxColumnWidth);
setColumnWidth(column, width);
}
}
/**
* Returns cell comment for the specified row and column
*
* @return cell comment or <code>null</code> if not found
*/
@Override
public XSSFComment getCellComment(CellAddress ref) {
return _sh.getCellComment(ref);
}
/**
* Returns all cell comments on this sheet.
* @return A map of each Comment in the sheet, keyed on the cell address where
* the comment is located.
*/
@Override
public Map<CellAddress, XSSFComment> getCellComments() {
return _sh.getCellComments();
}
/**
* Get a Hyperlink in this sheet anchored at row, column
*
* @param row The 0-base row number
* @param column The 0-based column number
* @return hyperlink if there is a hyperlink anchored at row, column; otherwise returns null
*/
@Override
public XSSFHyperlink getHyperlink(int row, int column) {
return _sh.getHyperlink(row, column);
}
/**
* Get a Hyperlink in this sheet located in a cell specified by {code addr}
*
* @param addr The address of the cell containing the hyperlink
* @return hyperlink if there is a hyperlink anchored at {@code addr}; otherwise returns {@code null}
* @since POI 3.15 beta 3
*/
@Override
public XSSFHyperlink getHyperlink(CellAddress addr) {
return _sh.getHyperlink(addr);
}
/**
* Register a hyperlink in the collection of hyperlinks on this sheet.
* Use {@link SXSSFCell#setHyperlink(Hyperlink)} if the hyperlink is just for that one cell.
* Use this method if you want to add a Hyperlink that covers a range of sells. If you use
* this method, you will need to call {@link XSSFHyperlink#setCellReference(String)} to
* explicitly cell the value, eg B2 or B2:C3 (the 4 cells with B2 at top left and C3 at bottom right)
*
* @param hyperlink the link to add
* @since POI 5.2.3
*/
public void addHyperlink(XSSFHyperlink hyperlink) {
_sh.addHyperlink(hyperlink);
}
/**
* Get a list of Hyperlinks in this sheet
*
* @return Hyperlinks for the sheet
*/
@Override
public List<XSSFHyperlink> getHyperlinkList() {
return _sh.getHyperlinkList();
}
/**
* {@inheritDoc}
*/
@Override
public XSSFDrawing getDrawingPatriarch() {
return _sh.getDrawingPatriarch();
}
/**
* Creates the top-level drawing patriarch.
*
* @return The new drawing patriarch.
*/
@Override
public SXSSFDrawing createDrawingPatriarch() {
return new SXSSFDrawing(getWorkbook(), _sh.createDrawingPatriarch());
}
/**
* Return the parent workbook
*
* @return the parent workbook
*/
@Override
public SXSSFWorkbook getWorkbook() {
return _workbook;
}
/**
* Returns the name of this sheet
*
* @return the name of this sheet
*/
@Override
public String getSheetName() {
return _sh.getSheetName();
}
/**
* Note - this is not the same as whether the sheet is focused (isActive)
* @return <code>true</code> if this sheet is currently selected
*/
@Override
public boolean isSelected() {
return _sh.isSelected();
}
/**
* Sets array formula to specified region for result.
*
* @param formula text representation of the formula
* @param range Region of array formula for result.
* @return the {@link CellRange} of cells affected by this change
*/
@Override
public CellRange<? extends Cell> setArrayFormula(String formula, CellRangeAddress range) {
// the simple approach via _sh does not work as it creates rows in the XSSFSheet and thus causes
// corrupted .xlsx files as rows appear multiple times in the resulting sheetX.xml files
// return _sh.setArrayFormula(formula, range);
throw new IllegalStateException("Not Implemented");
}
/**
* Remove an Array Formula from this sheet. All cells contained in the Array Formula range are removed as well
*
* @param cell any cell within Array Formula range
* @return the {@link CellRange} of cells affected by this change
*/
@Override
public CellRange<? extends Cell> removeArrayFormula(Cell cell) {
// the simple approach via _sh does not work as it creates rows in the XSSFSheet and thus causes
// corrupted .xlsx files as rows appear multiple times in the resulting sheetX.xml files
// return _sh.removeArrayFormula(cell);
throw new IllegalStateException("Not Implemented");
}
@Override
public DataValidationHelper getDataValidationHelper() {
return _sh.getDataValidationHelper();
}
@Override
public List<XSSFDataValidation> getDataValidations() {
return _sh.getDataValidations();
}
/**
* Creates a data validation object
* @param dataValidation The Data validation object settings
*/
@Override
public void addValidationData(DataValidation dataValidation) {
_sh.addValidationData(dataValidation);
}
/**
* Enable filtering for a range of cells
*
* @param range the range of cells to filter
*/
@Override
public AutoFilter setAutoFilter(CellRangeAddress range) {
return _sh.setAutoFilter(range);
}
@Override
public SheetConditionalFormatting getSheetConditionalFormatting(){
return _sh.getSheetConditionalFormatting();
}
@Override
public CellRangeAddress getRepeatingRows() {
return _sh.getRepeatingRows();
}
@Override
public CellRangeAddress getRepeatingColumns() {
return _sh.getRepeatingColumns();
}
@Override
public void setRepeatingRows(CellRangeAddress rowRangeRef) {
_sh.setRepeatingRows(rowRangeRef);
}
@Override
public void setRepeatingColumns(CellRangeAddress columnRangeRef) {
_sh.setRepeatingColumns(columnRangeRef);
}
//end of interface implementation
/**
* Specifies how many rows can be accessed at most via getRow().
* When a new node is created via createRow() and the total number
* of unflushed records would exceed the specified value, then the
* row with the lowest index value is flushed and cannot be accessed
* via getRow() anymore.
* A value of -1 indicates unlimited access. In this case all
* records that have not been flushed by a call to flush() are available
* for random access.
* A value of 0 is not allowed because it would flush any newly created row
* without having a chance to specify any cells.
*/
public void setRandomAccessWindowSize(int value) {
if(value == 0 || value < -1) {
throw new IllegalArgumentException("RandomAccessWindowSize must be either -1 or a positive integer");
}
_randomAccessWindowSize = value;
}
/**
* Are all rows flushed to disk?
*/
public boolean areAllRowsFlushed() {
return allFlushed;
}
/**
* @return Last row number to be flushed to disk, or -1 if none flushed yet
*/
public int getLastFlushedRowNum() {
return lastFlushedRowNumber;
}
/**
* Specifies how many rows can be accessed at most via getRow().
* The excess rows (if any) are flushed to the disk while rows
* with lower index values are flushed first.
*/
public void flushRows(int remaining) throws IOException {
while(_rows.size() > remaining) {
flushOneRow();
}
if (remaining == 0) {
allFlushed = true;
}
}
/**
* Flush all rows to disk. After this call no rows can be accessed via getRow()
*
* @throws IOException If an I/O error occurs
*/
public void flushRows() throws IOException {
this.flushRows(0);
}
/**
* Flush all the data in the buffered stream to the temp file.
*
* @throws IOException If an I/O error occurs
*/
public void flushBufferedData() throws IOException {
this._writer.flush();
}
private void flushOneRow() throws IOException {
Integer firstRowNum = _rows.firstKey();
if (firstRowNum!=null) {
int rowIndex = firstRowNum;
SXSSFRow row = _rows.get(firstRowNum);
if (_autoSizeColumnTracker != null) {
// Update the best fit column widths for auto-sizing just before the rows are flushed
_autoSizeColumnTracker.updateColumnWidths(row);
}
if (_writer != null) {
_writer.writeRow(rowIndex, row);
}
_rows.remove(firstRowNum);
lastFlushedRowNumber = rowIndex;
}
}
public void changeRowNum(SXSSFRow row, int newRowNum) {
removeRow(row);
row.setRowNumWithoutUpdatingSheet(newRowNum);
_rows.put(newRowNum, row);
}
public int getRowNum(SXSSFRow row) {
return row.getRowNum();
}
/**
* Deletes the temporary file that backed this sheet on disk.
* @return true if the file was deleted, false if it wasn't.
*/
boolean dispose() throws IOException {
boolean ret;
try {
if (!allFlushed) {
flushRows();
}
} finally {
ret = _writer == null || _writer.dispose();
}
return ret;
}
@Override
public int getColumnOutlineLevel(int columnIndex) {
return _sh.getColumnOutlineLevel(columnIndex);
}
/**
* {@inheritDoc}
*/
@Override
public CellAddress getActiveCell() {
return _sh.getActiveCell();
}
/**
* {@inheritDoc}
*/
@Override
public void setActiveCell(CellAddress address) {
_sh.setActiveCell(address);
}
public XSSFColor getTabColor() {
return _sh.getTabColor();
}
public void setTabColor(XSSFColor color) {
_sh.setTabColor(color);
}
/**
* Enable sheet protection
*/
public void enableLocking() {
safeGetProtectionField().setSheet(true);
}
/**
* Disable sheet protection
*/
public void disableLocking() {
safeGetProtectionField().setSheet(false);
}
/**
* Enable or disable Autofilters locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockAutoFilter(boolean enabled) {
safeGetProtectionField().setAutoFilter(enabled);
}
/**
* Enable or disable Deleting columns locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockDeleteColumns(boolean enabled) {
safeGetProtectionField().setDeleteColumns(enabled);
}
/**
* Enable or disable Deleting rows locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockDeleteRows(boolean enabled) {
safeGetProtectionField().setDeleteRows(enabled);
}
/**
* Enable or disable Formatting cells locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockFormatCells(boolean enabled) {
safeGetProtectionField().setFormatCells(enabled);
}
/**
* Enable or disable Formatting columns locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockFormatColumns(boolean enabled) {
safeGetProtectionField().setFormatColumns(enabled);
}
/**
* Enable or disable Formatting rows locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockFormatRows(boolean enabled) {
safeGetProtectionField().setFormatRows(enabled);
}
/**
* Enable or disable Inserting columns locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockInsertColumns(boolean enabled) {
safeGetProtectionField().setInsertColumns(enabled);
}
/**
* Enable or disable Inserting hyperlinks locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockInsertHyperlinks(boolean enabled) {
safeGetProtectionField().setInsertHyperlinks(enabled);
}
/**
* Enable or disable Inserting rows locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockInsertRows(boolean enabled) {
safeGetProtectionField().setInsertRows(enabled);
}
/**
* Enable or disable Pivot Tables locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockPivotTables(boolean enabled) {
safeGetProtectionField().setPivotTables(enabled);
}
/**
* Enable or disable Sort locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockSort(boolean enabled) {
safeGetProtectionField().setSort(enabled);
}
/**
* Enable or disable Objects locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockObjects(boolean enabled) {
safeGetProtectionField().setObjects(enabled);
}
/**
* Enable or disable Scenarios locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockScenarios(boolean enabled) {
safeGetProtectionField().setScenarios(enabled);
}
/**
* Enable or disable Selection of locked cells locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockSelectLockedCells(boolean enabled) {
safeGetProtectionField().setSelectLockedCells(enabled);
}
/**
* Enable or disable Selection of unlocked cells locking.
* This does not modify sheet protection status.
* To enforce this un-/locking, call {@link #disableLocking()} or {@link #enableLocking()}
*/
public void lockSelectUnlockedCells(boolean enabled) {
safeGetProtectionField().setSelectUnlockedCells(enabled);
}
private CTSheetProtection safeGetProtectionField() {
CTWorksheet ct = _sh.getCTWorksheet();
if (!isSheetProtectionEnabled()) {
return ct.addNewSheetProtection();
}
return ct.getSheetProtection();
}
/* package */ boolean isSheetProtectionEnabled() {
CTWorksheet ct = _sh.getCTWorksheet();
return (ct.isSetSheetProtection());
}
/**
* Set background color of the sheet tab
*
* @param colorIndex the indexed color to set, must be a constant from {@link IndexedColors}
*/
public void setTabColor(int colorIndex){
CTWorksheet ct = _sh.getCTWorksheet();
CTSheetPr pr = ct.getSheetPr();
if(pr == null) pr = ct.addNewSheetPr();
CTColor color = CTColor.Factory.newInstance();
color.setIndexed(colorIndex);
pr.setTabColor(color);
}
/**
* This method is not yet supported.
*
* @throws UnsupportedOperationException this method is not yet supported
*/
@NotImplemented
@Override
public void shiftColumns(int startColumn, int endColumn, int n){
throw new UnsupportedOperationException("Not Implemented");
}
void trackNewCell(SXSSFCell cell) {
leftMostColumn = Math.min(cell.getColumnIndex(), leftMostColumn);
rightMostColumn = Math.max(cell.getColumnIndex(), rightMostColumn);
}
void deriveDimension() {
if (_workbook.shouldCalculateSheetDimensions()) {
try {
CellRangeAddress cellRangeAddress = new CellRangeAddress(
getFirstRowNum(), getLastRowNum(), leftMostColumn, rightMostColumn);
_sh.setDimensionOverride(cellRangeAddress);
} catch (Exception e) {
LOG.atDebug().log("Failed to set dimension details on sheet", e);
}
}
}
}
|