Example #1
0
        /**
         * Constructs an workbook from an existing workbook.
         * <p>
         * When a new node is created via createRow() and the total number
         * of unflushed records would exceed the specified value, then the
         * row with the lowest index value is flushed and cannot be accessed
         * via getRow() anymore.
         * </p>
         * <p>
         * A value of -1 indicates unlimited access. In this case all
         * records that have not been flushed by a call to flush() are available
         * for random access.
         * </p>
         * <p>
         * A value of 0 is not allowed because it would flush any newly created row
         * without having a chance to specify any cells.
         * </p>
         *
         * @param workbook  the template workbook
         * @param rowAccessWindowSize the number of rows that are kept in memory until flushed out, see above.
         * @param compressTmpFiles whether to use gzip compression for temporary files
         * @param useSharedStringsTable whether to use a shared strings table
         */
        /// <summary>
        /// Currently only supports writing not reading. E.g. the number of rows returned from a worksheet will be wrong etc.
        /// </summary>
        /// <param name="workbook"></param>
        /// <param name="rowAccessWindowSize"></param>
        /// <param name="compressTmpFiles"></param>
        /// <param name="useSharedStringsTable"></param>
        public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize, bool compressTmpFiles, bool useSharedStringsTable)
        {
            RandomAccessWindowSize = rowAccessWindowSize;

            _compressTmpFiles = compressTmpFiles;

            if (workbook == null)
            {
                _wb = new XSSFWorkbook();
                _sharedStringSource = useSharedStringsTable ? XssfWorkbook.GetSharedStringSource() : null;
            }
            else
            {
                _wb = workbook;
                _sharedStringSource = useSharedStringsTable ? XssfWorkbook.GetSharedStringSource() : null;
                var numberOfSheets = XssfWorkbook.NumberOfSheets;
                for (int i = 0; i < numberOfSheets; i++)
                {
                    XSSFSheet sheet = (XSSFSheet)XssfWorkbook.GetSheetAt(i);
                    CreateAndRegisterSXSSFSheet(sheet);
                }
            }
        }