You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SXSSFWorkbook.java 43KB

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