Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SXSSFWorkbook.java 44KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xssf.streaming;
  16. import java.io.File;
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. import java.io.InputStreamReader;
  21. import java.io.OutputStream;
  22. import java.io.OutputStreamWriter;
  23. import java.io.Reader;
  24. import java.io.Writer;
  25. import java.nio.charset.StandardCharsets;
  26. import java.util.Enumeration;
  27. import java.util.HashMap;
  28. import java.util.Iterator;
  29. import java.util.List;
  30. import java.util.Map;
  31. import java.util.NoSuchElementException;
  32. import java.util.Spliterator;
  33. import org.apache.commons.compress.archivers.ArchiveOutputStream;
  34. import org.apache.commons.compress.archivers.zip.Zip64Mode;
  35. import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
  36. import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
  37. import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
  38. import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
  39. import org.apache.logging.log4j.LogManager;
  40. import org.apache.logging.log4j.Logger;
  41. import org.apache.poi.openxml4j.opc.OPCPackage;
  42. import org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream;
  43. import org.apache.poi.openxml4j.util.ZipEntrySource;
  44. import org.apache.poi.openxml4j.util.ZipFileZipEntrySource;
  45. import org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource;
  46. import org.apache.poi.openxml4j.util.ZipSecureFile;
  47. import org.apache.poi.ss.SpreadsheetVersion;
  48. import org.apache.poi.ss.formula.EvaluationWorkbook;
  49. import org.apache.poi.ss.formula.udf.UDFFinder;
  50. import org.apache.poi.ss.usermodel.CellReferenceType;
  51. import org.apache.poi.ss.usermodel.CellStyle;
  52. import org.apache.poi.ss.usermodel.CreationHelper;
  53. import org.apache.poi.ss.usermodel.DataFormat;
  54. import org.apache.poi.ss.usermodel.Font;
  55. import org.apache.poi.ss.usermodel.Name;
  56. import org.apache.poi.ss.usermodel.PictureData;
  57. import org.apache.poi.ss.usermodel.Row;
  58. import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
  59. import org.apache.poi.ss.usermodel.Sheet;
  60. import org.apache.poi.ss.usermodel.SheetVisibility;
  61. import org.apache.poi.ss.usermodel.Workbook;
  62. import org.apache.poi.util.Beta;
  63. import org.apache.poi.util.IOUtils;
  64. import org.apache.poi.util.Internal;
  65. import org.apache.poi.util.NotImplemented;
  66. import org.apache.poi.util.Removal;
  67. import org.apache.poi.util.TempFile;
  68. import org.apache.poi.xssf.model.SharedStringsTable;
  69. import org.apache.poi.xssf.usermodel.XSSFChartSheet;
  70. import org.apache.poi.xssf.usermodel.XSSFSheet;
  71. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  72. /**
  73. * Streaming version of XSSFWorkbook implementing the "BigGridDemo" strategy.
  74. *
  75. * This allows to write very large files without running out of memory as only
  76. * a configurable portion of the rows are kept in memory at any one time.
  77. *
  78. * You can provide a template workbook which is used as basis for the written
  79. * data.
  80. *
  81. * See https://poi.apache.org/spreadsheet/how-to.html#sxssf for details.
  82. *
  83. * Please note that there are still things that still may consume a large
  84. * amount of memory based on which features you are using, e.g. merged regions,
  85. * comments, ... are still only stored in memory and thus may require a lot of
  86. * memory if used extensively.
  87. *
  88. * SXSSFWorkbook defaults to using inline strings instead of a shared strings
  89. * table. This is very efficient, since no document content needs to be kept in
  90. * memory, but is also known to produce documents that are incompatible with
  91. * some clients. With shared strings enabled all unique strings in the document
  92. * has to be kept in memory. Depending on your document content this could use
  93. * a lot more resources than with shared strings disabled.
  94. *
  95. * Carefully review your memory budget and compatibility needs before deciding
  96. * whether to enable shared strings or not.
  97. */
  98. public class SXSSFWorkbook implements Workbook {
  99. /**
  100. * Specifies how many rows can be accessed at most via {@link SXSSFSheet#getRow}.
  101. * When a new node is created via {@link SXSSFSheet#createRow} and the total number
  102. * of unflushed records would exceed the specified value, then the
  103. * row with the lowest index value is flushed and cannot be accessed
  104. * via {@link SXSSFSheet#getRow} anymore.
  105. */
  106. public static final int DEFAULT_WINDOW_SIZE = 100;
  107. private static final Logger LOG = LogManager.getLogger(SXSSFWorkbook.class);
  108. protected final XSSFWorkbook _wb;
  109. private final Map<SXSSFSheet,XSSFSheet> _sxFromXHash = new HashMap<>();
  110. private final Map<XSSFSheet,SXSSFSheet> _xFromSxHash = new HashMap<>();
  111. private int _randomAccessWindowSize = DEFAULT_WINDOW_SIZE;
  112. protected interface ISheetInjector {
  113. void writeSheetData(OutputStream out) throws IOException;
  114. }
  115. /**
  116. * whether temp files should be compressed.
  117. */
  118. private boolean _compressTmpFiles;
  119. /**
  120. * shared string table - a cache of strings in this workbook
  121. */
  122. protected final SharedStringsTable _sharedStringSource;
  123. /**
  124. * controls whether Zip64 mode is used - Always became the default in POI 5.0.0
  125. */
  126. protected Zip64Mode zip64Mode = Zip64Mode.Always;
  127. private boolean shouldCalculateSheetDimensions = true;
  128. /**
  129. * Construct a new workbook with default row window size
  130. */
  131. public SXSSFWorkbook()
  132. {
  133. this(null /*workbook*/);
  134. }
  135. /**
  136. * <p>Construct a workbook from a template.</p>
  137. *
  138. * There are three use-cases to use SXSSFWorkbook(XSSFWorkbook) :
  139. * <ol>
  140. * <li>
  141. * Append new sheets to existing workbooks. You can open existing
  142. * workbook from a file or create on the fly with XSSF.
  143. * </li>
  144. * <li>
  145. * Append rows to existing sheets. The row number MUST be greater
  146. * than {@code max(rownum)} in the template sheet.
  147. * </li>
  148. * <li>
  149. * Use existing workbook as a template and re-use global objects such
  150. * as cell styles, formats, images, etc.
  151. * </li>
  152. * </ol>
  153. * All three use cases can work in a combination.
  154. *
  155. * What is not supported:
  156. * <ul>
  157. * <li>
  158. * Access initial cells and rows in the template. After constructing
  159. * all internal windows are empty and {@link SXSSFSheet#getRow} and
  160. * {@link SXSSFRow#getCell} return <code>null</code>.
  161. * </li>
  162. * <li>
  163. * Override existing cells and rows. The API silently allows that but
  164. * the output file is invalid and Excel cannot read it.
  165. * </li>
  166. * </ul>
  167. *
  168. * @param workbook the template workbook
  169. */
  170. public SXSSFWorkbook(XSSFWorkbook workbook) {
  171. this(workbook, DEFAULT_WINDOW_SIZE);
  172. }
  173. /**
  174. * Constructs an workbook from an existing workbook.
  175. * <p>
  176. * When a new node is created via {@link SXSSFSheet#createRow} and the total number
  177. * of unflushed records would exceed the specified value, then the
  178. * row with the lowest index value is flushed and cannot be accessed
  179. * via {@link SXSSFSheet#getRow} anymore.
  180. * </p>
  181. * <p>
  182. * A value of <code>-1</code> indicates unlimited access. In this case all
  183. * records that have not been flushed by a call to <code>flush()</code> are available
  184. * for random access.
  185. * </p>
  186. * <p>
  187. * A value of <code>0</code> is not allowed because it would flush any newly created row
  188. * without having a chance to specify any cells.
  189. * </p>
  190. *
  191. * @param rowAccessWindowSize the number of rows that are kept in memory until flushed out, see above.
  192. */
  193. public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize) {
  194. this(workbook, rowAccessWindowSize, false);
  195. }
  196. /**
  197. * Constructs an workbook from an existing workbook.
  198. * <p>
  199. * When a new node is created via {@link SXSSFSheet#createRow} and the total number
  200. * of unflushed records would exceed the specified value, then the
  201. * row with the lowest index value is flushed and cannot be accessed
  202. * via {@link SXSSFSheet#getRow} anymore.
  203. * </p>
  204. * <p>
  205. * A value of <code>-1</code> indicates unlimited access. In this case all
  206. * records that have not been flushed by a call to <code>flush()</code> are available
  207. * for random access.
  208. * </p>
  209. * <p>
  210. * A value of <code>0</code> is not allowed because it would flush any newly created row
  211. * without having a chance to specify any cells.
  212. * </p>
  213. *
  214. * @param rowAccessWindowSize the number of rows that are kept in memory until flushed out, see above.
  215. * @param compressTmpFiles whether to use gzip compression for temporary files
  216. */
  217. public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize, boolean compressTmpFiles) {
  218. this(workbook, rowAccessWindowSize, compressTmpFiles, false);
  219. }
  220. /**
  221. * Constructs an workbook from an existing workbook.
  222. * <p>
  223. * When a new node is created via {@link SXSSFSheet#createRow} and the total number
  224. * of unflushed records would exceed the specified value, then the
  225. * row with the lowest index value is flushed and cannot be accessed
  226. * via {@link SXSSFSheet#getRow} anymore.
  227. * </p>
  228. * <p>
  229. * A value of <code>-1</code> indicates unlimited access. In this case all
  230. * records that have not been flushed by a call to <code>flush()</code> are available
  231. * for random access.
  232. * </p>
  233. * <p>
  234. * A value of <code>0</code> is not allowed because it would flush any newly created row
  235. * without having a chance to specify any cells.
  236. * </p>
  237. *
  238. * @param workbook the template workbook
  239. * @param rowAccessWindowSize the number of rows that are kept in memory until flushed out, see above.
  240. * @param compressTmpFiles whether to use gzip compression for temporary files
  241. * @param useSharedStringsTable whether to use a shared strings table
  242. */
  243. public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize, boolean compressTmpFiles, boolean useSharedStringsTable) {
  244. setRandomAccessWindowSize(rowAccessWindowSize);
  245. setCompressTempFiles(compressTmpFiles);
  246. if (workbook == null) {
  247. _wb = new XSSFWorkbook();
  248. _sharedStringSource = useSharedStringsTable ? _wb.getSharedStringSource() : null;
  249. } else {
  250. _wb=workbook;
  251. _sharedStringSource = useSharedStringsTable ? _wb.getSharedStringSource() : null;
  252. for ( Sheet sheet : _wb ) {
  253. createAndRegisterSXSSFSheet( (XSSFSheet)sheet );
  254. }
  255. }
  256. }
  257. /**
  258. * Construct an empty workbook and specify the window for row access.
  259. * <p>
  260. * When a new node is created via {@link SXSSFSheet#createRow} and the total number
  261. * of unflushed records would exceed the specified value, then the
  262. * row with the lowest index value is flushed and cannot be accessed
  263. * via {@link SXSSFSheet#getRow} anymore.
  264. * </p>
  265. * <p>
  266. * A value of <code>-1</code> indicates unlimited access. In this case all
  267. * records that have not been flushed by a call to <code>flush()</code> are available
  268. * for random access.
  269. * </p>
  270. * <p>
  271. * A value of <code>0</code> is not allowed because it would flush any newly created row
  272. * without having a chance to specify any cells.
  273. * </p>
  274. *
  275. * @param rowAccessWindowSize the number of rows that are kept in memory until flushed out, see above.
  276. */
  277. public SXSSFWorkbook(int rowAccessWindowSize) {
  278. this(null /*workbook*/, rowAccessWindowSize);
  279. }
  280. /**
  281. * See the constructors for a more detailed description of the sliding window of rows.
  282. *
  283. * @return The number of rows that are kept in memory at once before flushing them out.
  284. */
  285. public int getRandomAccessWindowSize() {
  286. return _randomAccessWindowSize;
  287. }
  288. protected void setRandomAccessWindowSize(int rowAccessWindowSize) {
  289. if(rowAccessWindowSize == 0 || rowAccessWindowSize < -1) {
  290. throw new IllegalArgumentException("rowAccessWindowSize must be greater than 0 or -1");
  291. }
  292. _randomAccessWindowSize = rowAccessWindowSize;
  293. }
  294. /**
  295. * Sets the <a href="https://commons.apache.org/proper/commons-compress/apidocs/org/apache/commons/compress/archivers/zip/Zip64Mode.html">Zip64 Mode</a>
  296. * @param zip64Mode {@link Zip64Mode}
  297. *
  298. * @since 4.1.0
  299. */
  300. @Beta
  301. public void setZip64Mode(Zip64Mode zip64Mode) {
  302. this.zip64Mode = zip64Mode;
  303. }
  304. /**
  305. * Get whether temp files should be compressed.
  306. *
  307. * @return whether to compress temp files
  308. */
  309. public boolean isCompressTempFiles() {
  310. return _compressTmpFiles;
  311. }
  312. /**
  313. * Set whether temp files should be compressed.
  314. * <p>
  315. * SXSSF writes sheet data in temporary files (a temp file per-sheet)
  316. * and the size of these temp files can grow to to a very large size,
  317. * e.g. for a 20 MB csv data the size of the temp xml file become few GB large.
  318. * If the "compress" flag is set to <code>true</code> then the temporary XML is gzipped.
  319. * </p>
  320. * <p>
  321. * Please note the "compress" option may cause performance penalty.
  322. * </p>
  323. * <p>
  324. * Setting this option only affects compression for subsequent <code>createSheet()</code>
  325. * calls.
  326. * </p>
  327. * @param compress whether to compress temp files
  328. */
  329. public void setCompressTempFiles(boolean compress) {
  330. _compressTmpFiles = compress;
  331. }
  332. /**
  333. * @param shouldCalculateSheetDimensions defaults to <code>true</code>, set to <code>false</code> if
  334. * the calculated dimensions are causing trouble
  335. * @since POI 5.2.3
  336. */
  337. public void setShouldCalculateSheetDimensions(boolean shouldCalculateSheetDimensions) {
  338. this.shouldCalculateSheetDimensions = shouldCalculateSheetDimensions;
  339. }
  340. /**
  341. * @return shouldCalculateSheetDimensions defaults to <code>true</code>, set to <code>false</code> if
  342. * the calculated dimensions are causing trouble
  343. * @since POI 5.2.3
  344. */
  345. public boolean shouldCalculateSheetDimensions() {
  346. return shouldCalculateSheetDimensions;
  347. }
  348. @Internal
  349. protected SharedStringsTable getSharedStringSource() {
  350. return _sharedStringSource;
  351. }
  352. protected SheetDataWriter createSheetDataWriter() throws IOException {
  353. if(_compressTmpFiles) {
  354. return new GZIPSheetDataWriter(_sharedStringSource);
  355. }
  356. return new SheetDataWriter(_sharedStringSource);
  357. }
  358. XSSFSheet getXSSFSheet(SXSSFSheet sheet) {
  359. return _sxFromXHash.get(sheet);
  360. }
  361. SXSSFSheet getSXSSFSheet(XSSFSheet sheet) {
  362. return _xFromSxHash.get(sheet);
  363. }
  364. void registerSheetMapping(SXSSFSheet sxSheet,XSSFSheet xSheet) {
  365. _sxFromXHash.put(sxSheet,xSheet);
  366. _xFromSxHash.put(xSheet,sxSheet);
  367. }
  368. void deregisterSheetMapping(XSSFSheet xSheet) {
  369. SXSSFSheet sxSheet = getSXSSFSheet(xSheet);
  370. if (sxSheet != null) {
  371. // ensure that the writer is closed in all cases to not have lingering writers
  372. IOUtils.closeQuietly(sxSheet.getSheetDataWriter());
  373. _sxFromXHash.remove(sxSheet);
  374. _xFromSxHash.remove(xSheet);
  375. }
  376. }
  377. protected XSSFSheet getSheetFromZipEntryName(String sheetRef) {
  378. for(XSSFSheet sheet : _sxFromXHash.values()) {
  379. if(sheetRef.equals(sheet.getPackagePart().getPartName().getName().substring(1))) {
  380. return sheet;
  381. }
  382. }
  383. return null;
  384. }
  385. protected void injectData(ZipEntrySource zipEntrySource, OutputStream out) throws IOException {
  386. ArchiveOutputStream zos = createArchiveOutputStream(out);
  387. try {
  388. Enumeration<? extends ZipArchiveEntry> en = zipEntrySource.getEntries();
  389. while (en.hasMoreElements()) {
  390. ZipArchiveEntry ze = en.nextElement();
  391. ZipArchiveEntry zeOut = new ZipArchiveEntry(ze.getName());
  392. if (ze.getSize() >= 0) zeOut.setSize(ze.getSize());
  393. if (ze.getTime() >= 0) zeOut.setTime(ze.getTime());
  394. zos.putArchiveEntry(zeOut);
  395. try (final InputStream is = zipEntrySource.getInputStream(ze)) {
  396. if (is instanceof ZipArchiveThresholdInputStream) {
  397. // #59743 - disable Threshold handling for SXSSF copy
  398. // as users tend to put too much repetitive data in when using SXSSF :)
  399. ((ZipArchiveThresholdInputStream)is).setGuardState(false);
  400. }
  401. XSSFSheet xSheet = getSheetFromZipEntryName(ze.getName());
  402. // See bug 56557, we should not inject data into the special ChartSheets
  403. if (xSheet != null && !(xSheet instanceof XSSFChartSheet)) {
  404. SXSSFSheet sxSheet = getSXSSFSheet(xSheet);
  405. copyStreamAndInjectWorksheet(is, zos, createSheetInjector(sxSheet));
  406. } else {
  407. IOUtils.copy(is, zos);
  408. }
  409. } finally {
  410. zos.closeArchiveEntry();
  411. }
  412. }
  413. } finally {
  414. zos.finish();
  415. zipEntrySource.close();
  416. }
  417. }
  418. protected ZipArchiveOutputStream createArchiveOutputStream(OutputStream out) {
  419. if (Zip64Mode.Always.equals(zip64Mode)) {
  420. return new OpcZipArchiveOutputStream(out);
  421. } else {
  422. ZipArchiveOutputStream zos = new ZipArchiveOutputStream(out);
  423. zos.setUseZip64(zip64Mode);
  424. return zos;
  425. }
  426. }
  427. protected ISheetInjector createSheetInjector(SXSSFSheet sxSheet) throws IOException {
  428. return (output) -> {
  429. try (InputStream xis = sxSheet.getWorksheetXMLInputStream()) {
  430. // Copy the worksheet data to "output".
  431. IOUtils.copy(xis, output);
  432. }
  433. };
  434. }
  435. // private static void copyStreamAndInjectWorksheet(InputStream in, OutputStream out, InputStream worksheetData) throws IOException {
  436. private static void copyStreamAndInjectWorksheet(InputStream in, OutputStream out, ISheetInjector sheetInjector) throws IOException {
  437. Reader inReader = new InputStreamReader(in, StandardCharsets.UTF_8);
  438. Writer outWriter = new OutputStreamWriter(out, StandardCharsets.UTF_8);
  439. boolean needsStartTag = true;
  440. int c;
  441. int pos=0;
  442. String s="<sheetData";
  443. int n=s.length();
  444. //Copy from "in" to "out" up to the string "<sheetData/>" or "</sheetData>" (excluding).
  445. while(((c=inReader.read())!=-1)) {
  446. if(c==s.charAt(pos)) {
  447. pos++;
  448. if(pos==n) {
  449. if ("<sheetData".equals(s)) {
  450. c = inReader.read();
  451. if (c == -1) {
  452. outWriter.write(s);
  453. break;
  454. }
  455. if (c == '>') {
  456. // Found <sheetData>
  457. outWriter.write(s);
  458. outWriter.write(c);
  459. s = "</sheetData>";
  460. n = s.length();
  461. pos = 0;
  462. needsStartTag = false;
  463. continue;
  464. }
  465. if (c == '/') {
  466. // Found <sheetData/
  467. c = inReader.read();
  468. if (c == -1) {
  469. outWriter.write(s);
  470. break;
  471. }
  472. if (c == '>') {
  473. // Found <sheetData/>
  474. break;
  475. }
  476. outWriter.write(s);
  477. outWriter.write('/');
  478. outWriter.write(c);
  479. pos = 0;
  480. continue;
  481. }
  482. outWriter.write(s);
  483. outWriter.write('/');
  484. outWriter.write(c);
  485. pos = 0;
  486. continue;
  487. } else {
  488. // Found </sheetData>
  489. break;
  490. }
  491. }
  492. } else {
  493. if(pos>0) {
  494. outWriter.write(s,0,pos);
  495. }
  496. if(c==s.charAt(0)) {
  497. pos=1;
  498. } else {
  499. outWriter.write(c);
  500. pos=0;
  501. }
  502. }
  503. }
  504. outWriter.flush();
  505. if (needsStartTag) {
  506. outWriter.write("<sheetData>\n");
  507. outWriter.flush();
  508. }
  509. sheetInjector.writeSheetData(out);
  510. outWriter.write("</sheetData>");
  511. outWriter.flush();
  512. //Copy the rest of "in" to "out".
  513. while(((c=inReader.read())!=-1)) {
  514. outWriter.write(c);
  515. }
  516. outWriter.flush();
  517. }
  518. public XSSFWorkbook getXSSFWorkbook() {
  519. return _wb;
  520. }
  521. //start of interface implementation
  522. /**
  523. * Convenience method to get the active sheet. The active sheet is is the sheet
  524. * which is currently displayed when the workbook is viewed in Excel.
  525. * 'Selected' sheet(s) is a distinct concept.
  526. *
  527. * @return the index of the active sheet (0-based)
  528. */
  529. @Override
  530. public int getActiveSheetIndex() {
  531. return _wb.getActiveSheetIndex();
  532. }
  533. /**
  534. * Convenience method to set the active sheet. The active sheet is is the sheet
  535. * which is currently displayed when the workbook is viewed in Excel.
  536. * 'Selected' sheet(s) is a distinct concept.
  537. *
  538. * @param sheetIndex index of the active sheet (0-based)
  539. */
  540. @Override
  541. public void setActiveSheet(int sheetIndex) {
  542. _wb.setActiveSheet(sheetIndex);
  543. }
  544. /**
  545. * Gets the first tab that is displayed in the list of tabs in excel.
  546. *
  547. * @return the first tab that to display in the list of tabs (0-based).
  548. */
  549. @Override
  550. public int getFirstVisibleTab() {
  551. return _wb.getFirstVisibleTab();
  552. }
  553. /**
  554. * Sets the first tab that is displayed in the list of tabs in excel.
  555. *
  556. * @param sheetIndex the first tab that to display in the list of tabs (0-based)
  557. */
  558. @Override
  559. public void setFirstVisibleTab(int sheetIndex) {
  560. _wb.setFirstVisibleTab(sheetIndex);
  561. }
  562. /**
  563. * Sets the order of appearance for a given sheet.
  564. *
  565. * @param sheetname the name of the sheet to reorder
  566. * @param pos the position that we want to insert the sheet into (0 based)
  567. */
  568. @Override
  569. public void setSheetOrder(String sheetname, int pos) {
  570. _wb.setSheetOrder(sheetname,pos);
  571. }
  572. /**
  573. * Sets the tab whose data is actually seen when the sheet is opened.
  574. * This may be different from the "selected sheet" since excel seems to
  575. * allow you to show the data of one sheet when another is seen "selected"
  576. * in the tabs (at the bottom).
  577. *
  578. * @see Sheet#setSelected(boolean)
  579. * @param index the index of the sheet to select (0 based)
  580. */
  581. @Override
  582. public void setSelectedTab(int index) {
  583. _wb.setSelectedTab(index);
  584. }
  585. /**
  586. * Set the sheet name.
  587. *
  588. * @param sheet number (0 based)
  589. * @throws IllegalArgumentException if the name is greater than 31 chars or contains <code>/\?*[]</code>
  590. */
  591. @Override
  592. public void setSheetName(int sheet, String name) {
  593. _wb.setSheetName(sheet,name);
  594. }
  595. /**
  596. * Set the sheet name
  597. *
  598. * @param sheet sheet number (0 based)
  599. * @return Sheet name
  600. */
  601. @Override
  602. public String getSheetName(int sheet) {
  603. return _wb.getSheetName(sheet);
  604. }
  605. /**
  606. * Returns the index of the sheet by his name
  607. *
  608. * @param name the sheet name
  609. * @return index of the sheet (0 based)
  610. */
  611. @Override
  612. public int getSheetIndex(String name) {
  613. return _wb.getSheetIndex(name);
  614. }
  615. /**
  616. * Returns the index of the given sheet
  617. *
  618. * @param sheet the sheet to look up
  619. * @return index of the sheet (0 based)
  620. */
  621. @Override
  622. public int getSheetIndex(Sheet sheet) {
  623. return _wb.getSheetIndex(getXSSFSheet((SXSSFSheet)sheet));
  624. }
  625. /**
  626. * Create a Sheet for this Workbook, adds it to the sheets and returns
  627. * the high level representation. Use this to create new sheets.
  628. *
  629. * @return Sheet representing the new sheet.
  630. */
  631. @Override
  632. public SXSSFSheet createSheet() {
  633. return createAndRegisterSXSSFSheet(_wb.createSheet());
  634. }
  635. SXSSFSheet createAndRegisterSXSSFSheet(XSSFSheet xSheet) {
  636. final SXSSFSheet sxSheet;
  637. try {
  638. sxSheet = new SXSSFSheet(this,xSheet);
  639. } catch (IOException ioe) {
  640. throw new IllegalStateException(ioe);
  641. }
  642. registerSheetMapping(sxSheet,xSheet);
  643. return sxSheet;
  644. }
  645. /**
  646. * Create a Sheet for this Workbook, adds it to the sheets and returns
  647. * the high level representation. Use this to create new sheets.
  648. *
  649. * @param sheetname sheetname to set for the sheet.
  650. * @return Sheet representing the new sheet.
  651. * @throws IllegalArgumentException if the name is greater than 31 chars or contains <code>/\?*[]</code>
  652. */
  653. @Override
  654. public SXSSFSheet createSheet(String sheetname) {
  655. return createAndRegisterSXSSFSheet(_wb.createSheet(sheetname));
  656. }
  657. /**
  658. * <i>Not implemented for SXSSFWorkbook</i>
  659. *
  660. * Create a Sheet from an existing sheet in the Workbook.
  661. *
  662. * @return Sheet representing the cloned sheet.
  663. */
  664. @Override
  665. @NotImplemented
  666. public Sheet cloneSheet(int sheetNum) {
  667. throw new IllegalStateException("Not Implemented");
  668. }
  669. /**
  670. * Get the number of spreadsheets in the workbook
  671. *
  672. * @return the number of sheets
  673. */
  674. @Override
  675. public int getNumberOfSheets() {
  676. return _wb.getNumberOfSheets();
  677. }
  678. /**
  679. * Returns an iterator of the sheets in the workbook
  680. * in sheet order. Includes hidden and very hidden sheets.
  681. *
  682. * @return an iterator of the sheets.
  683. */
  684. @Override
  685. public Iterator<Sheet> sheetIterator() {
  686. return new SheetIterator<>();
  687. }
  688. /**
  689. * Returns a spliterator of the sheets in the workbook
  690. * in sheet order. Includes hidden and very hidden sheets.
  691. *
  692. * @return a spliterator of the sheets.
  693. *
  694. * @since POI 5.2.0
  695. */
  696. @Override
  697. public Spliterator<Sheet> spliterator() {
  698. return _wb.spliterator();
  699. }
  700. protected final class SheetIterator<T extends Sheet> implements Iterator<T> {
  701. final private Iterator<XSSFSheet> it;
  702. @SuppressWarnings("unchecked")
  703. public SheetIterator() {
  704. it = (Iterator<XSSFSheet>)(Iterator<? extends Sheet>) _wb.iterator();
  705. }
  706. @Override
  707. public boolean hasNext() {
  708. return it.hasNext();
  709. }
  710. @Override
  711. @SuppressWarnings("unchecked")
  712. public T next() throws NoSuchElementException {
  713. final XSSFSheet xssfSheet = it.next();
  714. return (T) getSXSSFSheet(xssfSheet);
  715. }
  716. /**
  717. * Unexpected behavior may occur if sheets are reordered after iterator
  718. * has been created. Support for the remove method may be added in the future
  719. * if someone can figure out a reliable implementation.
  720. */
  721. @Override
  722. public void remove() throws IllegalStateException {
  723. throw new UnsupportedOperationException("remove method not supported on XSSFWorkbook.iterator(). "+
  724. "Use Sheet.removeSheetAt(int) instead.");
  725. }
  726. }
  727. /**
  728. * Get the Sheet object at the given index.
  729. *
  730. * @param index of the sheet number (0-based physical and logical)
  731. * @return Sheet at the provided index
  732. */
  733. @Override
  734. public SXSSFSheet getSheetAt(int index) {
  735. return getSXSSFSheet(_wb.getSheetAt(index));
  736. }
  737. /**
  738. * Get sheet with the given name
  739. *
  740. * @param name of the sheet
  741. * @return Sheet with the name provided or <code>null</code> if it does not exist
  742. */
  743. @Override
  744. public SXSSFSheet getSheet(String name) {
  745. return getSXSSFSheet(_wb.getSheet(name));
  746. }
  747. /**
  748. * Removes sheet at the given index
  749. *
  750. * @param index of the sheet to remove (0-based)
  751. */
  752. @Override
  753. public void removeSheetAt(int index) {
  754. // Get the sheet to be removed
  755. XSSFSheet xSheet = _wb.getSheetAt(index);
  756. SXSSFSheet sxSheet = getSXSSFSheet(xSheet);
  757. // De-register it
  758. _wb.removeSheetAt(index);
  759. deregisterSheetMapping(xSheet);
  760. // Clean up temporary resources
  761. try {
  762. sxSheet.dispose();
  763. } catch (IOException e) {
  764. LOG.atWarn().withThrowable(e).log("Failed to dispose old sheet");
  765. }
  766. }
  767. /**
  768. * Create a new Font and add it to the workbook's font table
  769. *
  770. * @return new font object
  771. */
  772. @Override
  773. public Font createFont() {
  774. return _wb.createFont();
  775. }
  776. /**
  777. * Finds a font that matches the one with the supplied attributes
  778. *
  779. * @return the font with the matched attributes or <code>null</code>
  780. */
  781. @Override
  782. public Font findFont(boolean bold, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
  783. return _wb.findFont(bold, color, fontHeight, name, italic, strikeout, typeOffset, underline);
  784. }
  785. @Override
  786. public int getNumberOfFonts() {
  787. return _wb.getNumberOfFonts();
  788. }
  789. @Override
  790. @Deprecated
  791. @Removal(version = "6.0.0")
  792. public int getNumberOfFontsAsInt() {
  793. return getNumberOfFonts();
  794. }
  795. @Override
  796. public Font getFontAt(int idx) {
  797. return _wb.getFontAt(idx);
  798. }
  799. /**
  800. * Create a new Cell style and add it to the workbook's style table
  801. *
  802. * @return the new Cell Style object
  803. */
  804. @Override
  805. public CellStyle createCellStyle() {
  806. return _wb.createCellStyle();
  807. }
  808. /**
  809. * Get the number of styles the workbook contains
  810. *
  811. * @return count of cell styles
  812. */
  813. @Override
  814. public int getNumCellStyles() {
  815. return _wb.getNumCellStyles();
  816. }
  817. /**
  818. * Get the cell style object at the given index
  819. *
  820. * @param idx index within the set of styles (0-based)
  821. * @return CellStyle object at the index
  822. */
  823. @Override
  824. public CellStyle getCellStyleAt(int idx) {
  825. return _wb.getCellStyleAt(idx);
  826. }
  827. /**
  828. * Closes the underlying {@link XSSFWorkbook} and {@link OPCPackage}
  829. * on which this Workbook is based, if any.
  830. *
  831. * <p>Once this has been called, no further
  832. * operations, updates or reads should be performed on the
  833. * Workbook.
  834. */
  835. @Override
  836. public void close() throws IOException {
  837. // ensure that any lingering writer is closed
  838. for (SXSSFSheet sheet : _xFromSxHash.values()) {
  839. try {
  840. SheetDataWriter _writer = sheet.getSheetDataWriter();
  841. if (_writer != null) _writer.close();
  842. } catch (IOException e) {
  843. LOG.atWarn().withThrowable(e).log("An exception occurred while closing sheet data writer for sheet {}.", sheet.getSheetName());
  844. }
  845. }
  846. // Tell the base workbook to close, does nothing if
  847. // it's a newly created one
  848. _wb.close();
  849. }
  850. /**
  851. * Write out this workbook to an OutputStream.
  852. *
  853. * @param stream - the java OutputStream you wish to write to
  854. * @throws IOException if anything can't be written.
  855. */
  856. @Override
  857. public void write(OutputStream stream) throws IOException {
  858. flushSheets();
  859. //Save the template
  860. File tmplFile = TempFile.createTempFile("poi-sxssf-template", ".xlsx");
  861. boolean deleted;
  862. try {
  863. try (FileOutputStream os = new FileOutputStream(tmplFile)) {
  864. _wb.write(os);
  865. }
  866. //Substitute the template entries with the generated sheet data files
  867. try (
  868. ZipSecureFile zf = new ZipSecureFile(tmplFile);
  869. ZipFileZipEntrySource source = new ZipFileZipEntrySource(zf)
  870. ) {
  871. injectData(source, stream);
  872. }
  873. } finally {
  874. deleted = tmplFile.delete();
  875. }
  876. if (!deleted) {
  877. throw new IOException("Could not delete temporary file after processing: " + tmplFile);
  878. }
  879. }
  880. /**
  881. * Write out this workbook to an OutputStream. This (experimental) method avoids the temp file that
  882. * {@link #write} creates but will use more memory as a result. Other SXSSF code can create temp files,
  883. * so using this does not guarantee that there will be no temp file usage.
  884. *
  885. * @param stream - the java OutputStream you wish to write to
  886. * @throws IOException if anything can't be written.
  887. * @since POI 5.1.0 (experimental and still liable to change or be removed)
  888. */
  889. @Beta
  890. public void writeAvoidingTempFiles(OutputStream stream) throws IOException {
  891. flushSheets();
  892. //Save the template
  893. try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
  894. _wb.write(bos);
  895. //Substitute the template entries with the generated sheet data files
  896. try (
  897. InputStream is = bos.toInputStream();
  898. ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
  899. ZipInputStreamZipEntrySource source = new ZipInputStreamZipEntrySource(
  900. new ZipArchiveThresholdInputStream(zis))
  901. ) {
  902. injectData(source, stream);
  903. }
  904. }
  905. }
  906. protected void flushSheets() throws IOException {
  907. for (SXSSFSheet sheet : _xFromSxHash.values()) {
  908. sheet.deriveDimension();
  909. sheet.flushRows();
  910. }
  911. }
  912. /**
  913. * Dispose of temporary files backing this workbook on disk.
  914. * Calling this method will render the workbook unusable.
  915. * @return true if all temporary files were deleted successfully.
  916. */
  917. public boolean dispose() {
  918. boolean success = true;
  919. for (SXSSFSheet sheet : _sxFromXHash.keySet()) {
  920. try {
  921. success = sheet.dispose() && success;
  922. } catch (IOException e) {
  923. LOG.atWarn().withThrowable(e).log("Failed to dispose sheet");
  924. success = false;
  925. }
  926. }
  927. return success;
  928. }
  929. /**
  930. * @return the total number of defined names in this workbook
  931. */
  932. @Override
  933. public int getNumberOfNames() {
  934. return _wb.getNumberOfNames();
  935. }
  936. /**
  937. * @param name the name of the defined name
  938. * @return the defined name with the specified name. <code>null</code> if not found.
  939. */
  940. @Override
  941. public Name getName(String name) {
  942. return _wb.getName(name);
  943. }
  944. /**
  945. * Returns all defined names with the given name.
  946. *
  947. * @param name the name of the defined name
  948. * @return a list of the defined names with the specified name. An empty list is returned if none is found.
  949. */
  950. @Override
  951. public List<? extends Name> getNames(String name) {
  952. return _wb.getNames(name);
  953. }
  954. /**
  955. * Returns all defined names
  956. *
  957. * @return all defined names
  958. */
  959. @Override
  960. public List<? extends Name> getAllNames() {
  961. return _wb.getAllNames();
  962. }
  963. /**
  964. * Creates a new (uninitialised) defined name in this workbook
  965. *
  966. * @return new defined name object
  967. */
  968. @Override
  969. public Name createName() {
  970. return _wb.createName();
  971. }
  972. /**
  973. * Remove the given defined name
  974. *
  975. * @param name the name to remove
  976. */
  977. @Override
  978. public void removeName(Name name) {
  979. _wb.removeName(name);
  980. }
  981. /**
  982. * Sets the printarea for the sheet provided
  983. * <p>
  984. * i.e. Reference = $A$1:$B$2
  985. * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
  986. * @param reference Valid name Reference for the Print Area
  987. */
  988. @Override
  989. public void setPrintArea(int sheetIndex, String reference) {
  990. _wb.setPrintArea(sheetIndex,reference);
  991. }
  992. /**
  993. * For the Convenience of Java Programmers maintaining pointers.
  994. * @see #setPrintArea(int, String)
  995. * @param sheetIndex Zero-based sheet index (0 = First Sheet)
  996. * @param startColumn Column to begin printarea
  997. * @param endColumn Column to end the printarea
  998. * @param startRow Row to begin the printarea
  999. * @param endRow Row to end the printarea
  1000. */
  1001. @Override
  1002. public void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) {
  1003. _wb.setPrintArea(sheetIndex, startColumn, endColumn, startRow, endRow);
  1004. }
  1005. /**
  1006. * Retrieves the reference for the printarea of the specified sheet,
  1007. * the sheet name is appended to the reference even if it was not specified.
  1008. *
  1009. * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
  1010. * @return String Null if no print area has been defined
  1011. */
  1012. @Override
  1013. public String getPrintArea(int sheetIndex) {
  1014. return _wb.getPrintArea(sheetIndex);
  1015. }
  1016. /**
  1017. * Delete the printarea for the sheet specified
  1018. *
  1019. * @param sheetIndex Zero-based sheet index (0 = First Sheet)
  1020. */
  1021. @Override
  1022. public void removePrintArea(int sheetIndex) {
  1023. _wb.removePrintArea(sheetIndex);
  1024. }
  1025. /**
  1026. * Retrieves the current policy on what to do when
  1027. * getting missing or blank cells from a row.
  1028. * <p>
  1029. * The default is to return blank and null cells.
  1030. * {@link MissingCellPolicy}
  1031. * </p>
  1032. */
  1033. @Override
  1034. public MissingCellPolicy getMissingCellPolicy() {
  1035. return _wb.getMissingCellPolicy();
  1036. }
  1037. /**
  1038. * Sets the policy on what to do when
  1039. * getting missing or blank cells from a row.
  1040. *
  1041. * This will then apply to all calls to
  1042. * {@link Row#getCell(int)}. See
  1043. * {@link MissingCellPolicy}
  1044. */
  1045. @Override
  1046. public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
  1047. _wb.setMissingCellPolicy(missingCellPolicy);
  1048. }
  1049. /**
  1050. * Returns the instance of DataFormat for this workbook.
  1051. *
  1052. * @return the DataFormat object
  1053. */
  1054. @Override
  1055. public DataFormat createDataFormat() {
  1056. return _wb.createDataFormat();
  1057. }
  1058. /**
  1059. * Adds a picture to the workbook.
  1060. *
  1061. * @param pictureData The bytes of the picture
  1062. * @param format The format of the picture.
  1063. *
  1064. * @return the index to this picture (1 based).
  1065. * @see #PICTURE_TYPE_EMF
  1066. * @see #PICTURE_TYPE_WMF
  1067. * @see #PICTURE_TYPE_PICT
  1068. * @see #PICTURE_TYPE_JPEG
  1069. * @see #PICTURE_TYPE_PNG
  1070. * @see #PICTURE_TYPE_DIB
  1071. */
  1072. @Override
  1073. public int addPicture(byte[] pictureData, int format) {
  1074. return _wb.addPicture(pictureData,format);
  1075. }
  1076. /**
  1077. * Gets all pictures from the Workbook.
  1078. *
  1079. * @return the list of pictures (a list of {@link PictureData} objects.)
  1080. */
  1081. @Override
  1082. public List<? extends PictureData> getAllPictures() {
  1083. return _wb.getAllPictures();
  1084. }
  1085. /**
  1086. * Returns an object that handles instantiating concrete
  1087. * classes of the various instances one needs for HSSF, XSSF
  1088. * and SXSSF.
  1089. */
  1090. @Override
  1091. public CreationHelper getCreationHelper() {
  1092. return new SXSSFCreationHelper(this);
  1093. }
  1094. protected boolean isDate1904() {
  1095. return _wb.isDate1904();
  1096. }
  1097. @Override
  1098. @NotImplemented("XSSFWorkbook#isHidden is not implemented")
  1099. public boolean isHidden() {
  1100. return _wb.isHidden();
  1101. }
  1102. @Override
  1103. @NotImplemented("XSSFWorkbook#setHidden is not implemented")
  1104. public void setHidden(boolean hiddenFlag) {
  1105. _wb.setHidden(hiddenFlag);
  1106. }
  1107. @Override
  1108. public boolean isSheetHidden(int sheetIx) {
  1109. return _wb.isSheetHidden(sheetIx);
  1110. }
  1111. @Override
  1112. public boolean isSheetVeryHidden(int sheetIx) {
  1113. return _wb.isSheetVeryHidden(sheetIx);
  1114. }
  1115. @Override
  1116. public SheetVisibility getSheetVisibility(int sheetIx) {
  1117. return _wb.getSheetVisibility(sheetIx);
  1118. }
  1119. @Override
  1120. public void setSheetHidden(int sheetIx, boolean hidden) {
  1121. _wb.setSheetHidden(sheetIx,hidden);
  1122. }
  1123. @Override
  1124. public void setSheetVisibility(int sheetIx, SheetVisibility visibility) {
  1125. _wb.setSheetVisibility(sheetIx, visibility);
  1126. }
  1127. /**
  1128. * <i>Not implemented for SXSSFWorkbook</i>
  1129. *
  1130. * Adds the LinkTable records required to allow formulas referencing
  1131. * the specified external workbook to be added to this one. Allows
  1132. * formulas such as "[MyOtherWorkbook]Sheet3!$A$5" to be added to the
  1133. * file, for workbooks not already referenced.
  1134. *
  1135. * Note: this is not implemented and thus currently throws an Exception stating this.
  1136. *
  1137. * @param name The name the workbook will be referenced as in formulas
  1138. * @param workbook The open workbook to fetch the link required information from
  1139. *
  1140. * @throws IllegalStateException stating that this method is not implemented yet.
  1141. */
  1142. @Override
  1143. @NotImplemented
  1144. public int linkExternalWorkbook(String name, Workbook workbook) {
  1145. throw new IllegalStateException("Not Implemented");
  1146. }
  1147. /**
  1148. * Register a new toolpack in this workbook.
  1149. *
  1150. * @param toolpack the toolpack to register
  1151. */
  1152. @Override
  1153. public void addToolPack(UDFFinder toolpack) {
  1154. _wb.addToolPack(toolpack);
  1155. }
  1156. /**
  1157. * Whether the application shall perform a full recalculation when the workbook is opened.
  1158. * <p>
  1159. * Typically you want to force formula recalculation when you modify cell formulas or values
  1160. * of a workbook previously created by Excel. When set to 0, this flag will tell Excel
  1161. * that it needs to recalculate all formulas in the workbook the next time the file is opened.
  1162. * </p>
  1163. *
  1164. * @param value true if the application will perform a full recalculation of
  1165. * workbook values when the workbook is opened
  1166. * @since 3.8
  1167. */
  1168. @Override
  1169. public void setForceFormulaRecalculation(boolean value) {
  1170. _wb.setForceFormulaRecalculation(value);
  1171. }
  1172. /**
  1173. * Whether Excel will be asked to recalculate all formulas when the workbook is opened.
  1174. */
  1175. @Override
  1176. public boolean getForceFormulaRecalculation() {
  1177. return _wb.getForceFormulaRecalculation();
  1178. }
  1179. /**
  1180. * Returns the spreadsheet version (EXCEL2007) of this workbook
  1181. *
  1182. * @return EXCEL2007 SpreadsheetVersion enum
  1183. * @since 3.14 beta 2
  1184. */
  1185. @Override
  1186. public SpreadsheetVersion getSpreadsheetVersion() {
  1187. return SpreadsheetVersion.EXCEL2007;
  1188. }
  1189. @Override
  1190. public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException {
  1191. return _wb.addOlePackage(oleData, label, fileName, command);
  1192. }
  1193. @Override
  1194. public EvaluationWorkbook createEvaluationWorkbook() {
  1195. return SXSSFEvaluationWorkbook.create(this);
  1196. }
  1197. @Override
  1198. public CellReferenceType getCellReferenceType() {
  1199. return getXSSFWorkbook().getCellReferenceType();
  1200. }
  1201. @Override
  1202. public void setCellReferenceType(CellReferenceType cellReferenceType) {
  1203. getXSSFWorkbook().setCellReferenceType(cellReferenceType);
  1204. }
  1205. }