Sax方式读取Excel03

@param in 输入流
@param sheetIndex Sheet索引，-1表示全部Sheet, 0表示第一个Sheet
@param rowHandler 行处理器
@return {@link Excel07SaxReader}
@since 3.2.0
556026
public static Excel03SaxReader read03BySax(InputStream in, int sheetIndex, RowHandler rowHandler) {
		try {
			return new Excel03SaxReader(rowHandler).read(in, sheetIndex);
		} catch (NoClassDefFoundError e) {
			throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
		}
	}
264094
public Object getValue(Object row, int rowIndex, int columnIndex) {
        if (valueModel instanceof NestedValueModel) {
            NestedValueModel nestedModel = (NestedValueModel) valueModel;
            nestedModel.getSourceModel().setValue(row);
        }
        return valueModel.getValue();
    }
224507
public TableRow getRow(final Table table, final TableAppender appender, final int rowIndex)
            throws FastOdsException, IOException {
        TableBuilder.checkRow(rowIndex);
        return this.getRowSecure(table, appender, rowIndex, true);
    }
367907
function (formatter) {
    this.formatter = formatter;

    /**
     * Convert 
     *
     * @param filePath input ods file path
     */
    this.convert = function (filePath) {
        log('Message resource converter');
        log('Execute convert: ' + filePath);

        var excelApp = new ActiveXObject('Excel.Application');
        excelApp.Visible = true;
        log('Start');
        var book = excelApp.Workbooks.Open(filePath);
        var sheet = book.Worksheets(1);
        this.extractResources(sheet);
        log("End");
        book.Close(false);
        excelApp.Quit();
        excelApp = null;
    };

    this.data = [];
    this.fillData = function (sheet, lastCol, lastRow) {
      WScript.StdOut.Write('                        \r');
      this.data.push(undefined);
      for (var r = 1; r <= lastRow; r++) {
        var row = [];
        row.push(undefined);
        for (var c = 1; c <= lastCol; c++) {
          row.push(sheet.Cells(r, c).Value);
        }
        this.data.push(row);
        WScript.StdOut.Write('\rLoading... ' + r + ' / ' + lastRow);
      }
      WScript.StdOut.WriteLine();
    };
    this.value = function (row, col) {
        if (row >= this.data.length) throw Error('Array index out of range error(row): ' + row + ' in ' + this.data.length);
        if (col >= this.data[row].length) throw Error('Array index out of range error(col): ' + col + ' in ' + this.data[row].length);
        return this.data[row][col];
    };
    this.getLocaleColIndex = function(locale) {
        for (var col = 1; col < 100; col++) {
            if (this.value(3, col).toLowerCase() === locale.toLowerCase()) {
                return col;
            }
        }
        throw new Error('ref locale "' + locale + '" not found');
    };
    this.getRealValue = function (row, col) {
        var v = this.value(row, col);
        if (v === '^') {
            return this.getRealValue(row, col - 1);
        } else if (v === undefined) {
            return '';
        } else if (v.length > 1 && v.charAt(0) === '^') {
            var m = v.match(/^\^([a-z]+[\-_][a-zA-Z]+)$/);
            if (m) {
                var refLocaleCol = this.getLocaleColIndex(m[1]);
                return this.getRealValue(row, refLocaleCol);
            }
        }
        return v;
    };
    this.extractResources = function (sheet) {
        var locales = [];
        var lastLocaleCol = 1;
        var startLocaleCol = 4;
        for (var col = startLocaleCol, cellValue; cellValue = sheet.Cells(3, col).Value; col++) {
            lastLocaleCol = col;
        }
        var lastKeyRow = this.getLastKeyRow(sheet, 5);
        this.fillData(sheet, lastLocaleCol, lastKeyRow);
        console.log('Writing files...');
        var locales = [];
        for (var col = startLocaleCol; col <= lastLocaleCol; col++) {
            var localeKey = this.value(3, col);
            var lines = [];
            for (var row = 4; row <= lastKeyRow; row++) {
                var key = this.value(row, 3);
                var v = this.getRealValue(row, col);
                if (key) {
                    if (key.substr(0, 1) === '#') {
                        lines.push(formatter.formatComment(key));
                    } else {
                        if (row === lastKeyRow) {
                            lines.push(formatter.formatLastLine(key, v));
                        } else {
                            lines.push(formatter.formatLine(key, v));
                        }
                    }
                } else {
                    lines.push(''); // empty line
                }
            }
            locales.push(localeKey);
            this.writeSingleResourceFile(localeKey, formatter.normalizeLines(lines));
        }
        console.log('Wrote ' + locales.length + ' files in messages/ directory.');
    };
    this.writeSingleResourceFile = function (localeKey, lines) {
        var folderName = formatter.folderName;
        if (!fso.FolderExists(folderName)) {
            fso.CreateFolder(folderName);
        }
        // const
        var adTypeBinary = 1; // Binary
        var adTypeText = 2; // Text
        var adWriteChar = 0; // no EOL
        var adSaveCreateOverWrite = 2; // create or over write

        var filename = formatter.getFilePath(folderName, localeKey);
        var sw = new ActiveXObject('ADODB.Stream');
        sw.Type = adTypeText;
        sw.charset = 'utf-8';
        sw.Open();
        var headerText = formatter.formatHeader(localeKey);
        sw.WriteText(headerText, adWriteChar);
        for (var i = 0; i < lines.length; i++) {
            sw.WriteText(lines[i], adWriteChar);
        }
        var footerText = formatter.formatFooter(localeKey);
        sw.WriteText(footerText, adWriteChar);
        // Change to binary mode
        sw.Position = 0;
        sw.Type = adTypeBinary;
        // UTF-8 BOM
        if (outputBOM) {
            // Keep UTF-8 BOM
            sw.Position = 0;
        } else {
            // Skip UTF-8 BOM
            sw.Position = 3;
        }
        var binBlock = sw.Read();
        sw.Close();

        // Write binBlock as binary
        var os = new ActiveXObject('ADODB.Stream');
        os.Type = adTypeBinary;
        os.Open();
        os.Write(binBlock);
        os.SaveToFile(filename, adSaveCreateOverWrite);
        if (formatter.requireDefaultFile && formatter.isDefaultLocale(localeKey)) {
            var filenameOriginal = formatter.getDefaultFilePath(folderName);
            os.SaveToFile(filenameOriginal, adSaveCreateOverWrite);
        }
        os.Close();
    };

    // True if there are 
    this.getLastKeyRow = function (sheet, startRow) {
        var isBlank10rows = function (row) {
            for (var i = 0; i < 10; i++) {
                if (sheet.Cells(row + i, 3).Value) {
                    return false;
                }
            }
            return true;
        };
        for (var j = startRow; j < 5000; j++) { 
            if (isBlank10rows(j)) {
                return j - 1;
            }
        }
        return startRow;
    };
    return this;
}
1216942
public function getRow($rowIndex)
    {
        //check whether worksheet name is set or not
        if ($this->worksheetName == '')
            throw new Exception('Worksheet name not specified');
        $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() .
            '/worksheets/' . $this->worksheetName . '/cells/rows/' . $rowIndex;
        $signedURI = Utils::sign($strURI);
        $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
        $json = json_decode($responseStream);
        return $json->Row;

    }
848724
public function copyRows($sourceRowIndex = 1, $destRowIndex = 1, $rowNumber = 1)
    {
        //check whether worksheet name is set or not
        if ($this->worksheetName == '')
            throw new Exception('Worksheet name not specified');
        $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() .
            '/worksheets/' . $this->worksheetName . '/cells/rows/copy?sourceRowIndex=' . $sourceRowIndex . '&destinationRowIndex=' . $destRowIndex . '&rowNumber=' . $rowNumber;
        $signedURI = Utils::sign($strURI);
        $responseStream = Utils::processCommand($signedURI, 'POST', '', '');
        $json = json_decode($responseStream);
        if ($json->Code == 200)
            return true;
        else
            return false;

    }
1180602
protected T getRowObject(int rowIndex) {
		int pageIndex = rowIndex - dataOffset;
		if (pageIndex >= 0 && pageIndex < data.size()) {
			return data.get(pageIndex);
		}
		return null;
	}
452477
protected String[] readLine(HSSFSheet sheet, int rowIndex) {
    HSSFRow row = sheet.getRow(rowIndex);
    logger.debug("values count:{}", row.getLastCellNum());
    List<String> attrList = CollectUtils.newArrayList();
    for (int i = 0; i < row.getLastCellNum(); i++) {
      HSSFCell cell = row.getCell(i);
      if (null != cell) {
        String attr = cell.getRichStringCellValue().getString();
        if (Strings.isEmpty(attr)) {
          break;
        } else {
          attrList.add(attr.trim());
        }
      } else {
        break;
      }
    }
    String[] attrs = new String[attrList.size()];
    attrList.toArray(attrs);
    logger.debug("has attrs {}", attrs);
    return attrs;
  }
753262
public static void parse (DefaultHandler handler, InputStream in)
        throws IOException, ParserConfigurationException, SAXException
    {
        XMLReader xr = _pfactory.newSAXParser().getXMLReader();

        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);

        xr.parse(new InputSource(in));
    }
328590
private void readCompressedIntegerRowByNumber( ByteBuffer rowdata, int rn, long[] adrows, RandomAccessFile thefile )
            throws IOException, DataFormatException {
        int offset = (int) (adrows[rn + 1] - adrows[rn]);

        thefile.seek(adrows[rn]);
        /*
         * Read how many bytes the values are ex 1 => if encoded: 1 byte for the value and one byte
         * for the count = 2 2 => if encoded: 2 bytes for the value and one byte for the count = 3
         * etc... etc
         */
        int bytespervalue = (thefile.read() & 0xff);
        ByteBuffer cell = ByteBuffer.allocate(bytespervalue);
        int cellValue = 0;

        /* Create the buffer in which read the compressed row */
        byte[] tmp = new byte[offset - 1];
        thefile.read(tmp);
        ByteBuffer tmpBuffer = ByteBuffer.wrap(tmp);
        tmpBuffer.order(ByteOrder.nativeOrder());

        /*
         * Create the buffer in which read the decompressed row. The final decompressed row will
         * always contain 4-byte integer values
         */
        if ((offset - 1) == (bytespervalue * fileWindow.getCols())) {
            /* There is no compression in this row */
            for( int i = 0; i < offset - 1; i = i + bytespervalue ) {
                /* Read the value */
                tmpBuffer.get(cell.array());

                /*
                 * Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we
                 * need to pad them with 0's. The order of the padding is determined by the
                 * ByteOrder of the buffer.
                 */
                if (bytespervalue == 1) {
                    cellValue = (cell.get(0) & 0xff);
                } else if (bytespervalue == 2) {
                    cellValue = cell.getShort(0);
                } else if (bytespervalue == 4) {
                    cellValue = cell.getInt(0);
                }
                // if (logger.isDebugEnabled()) logger.debug("tmpint=" + tmpint
                // );
                rowdata.putInt(cellValue);
            }
        } else {
            /*
             * If the row is compressed, then the values appear in pairs (like couples a party). The
             * couple is composed of the count and the value value (WARNING: this can be more than
             * one byte). Therefore, knowing the length of the compressed row we can calculate the
             * number of couples.
             */
            int couples = (offset - 1) / (1 + bytespervalue);

            for( int i = 0; i < couples; i++ ) {
                /* Read the count of values */
                int count = (tmpBuffer.get() & 0xff);

                /* Read the value */
                tmpBuffer.get(cell.array());

                /*
                 * Integers can be of 1, 2, or 4 bytes. As rasterBuffer expects 4 byte integers we
                 * need to pad them with 0's. The order of the padding is determined by the
                 * ByteOrder of the buffer.
                 */
                if (bytespervalue == 1) {
                    cellValue = (cell.get(0) & 0xff);
                } else if (bytespervalue == 2) {
                    cellValue = cell.getShort(0);
                } else if (bytespervalue == 4) {
                    cellValue = cell.getInt(0);
                }
                /*
                 * Now write the cell value the required number of times to the raster row data
                 * buffer.
                 */
                for( int j = 0; j < count; j++ ) {
                    // // if (logger.isDebugEnabled()) logger.debug(" " +
                    // tmpint);
                    rowdata.putInt(cellValue);
                }
            }
        }
    }
245802
public synchronized V getCell(int columnIndex, int rowIndex) {
        if(rowIndex < 0 || columnIndex < 0) {
            throw new IndexOutOfBoundsException("Invalid row or column index: " + rowIndex + " " + columnIndex);
        }
        else if (rowIndex >= getRowCount()) {
            throw new IndexOutOfBoundsException("TableModel has " + getRowCount() + " rows, invalid access at rowIndex " + rowIndex);
        }
        if(columnIndex >= getColumnCount()) {
            throw new IndexOutOfBoundsException("TableModel has " + columnIndex + " columns, invalid access at columnIndex " + columnIndex);
        }
        return rows.get(rowIndex).get(columnIndex);
    }
687869
public static Excel07SaxReader read07BySax(File file, int sheetIndex, RowHandler rowHandler) {
		try {
			return new Excel07SaxReader(rowHandler).read(file, sheetIndex);
		} catch (NoClassDefFoundError e) {
			throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
		}
	}
231687
public void setupCellPositoin(final int rowIndex, final int columnIndex) {
        
        if(topLeftPoisitoin == null) {
            this.topLeftPoisitoin = new Point(columnIndex, rowIndex);
        }
        
        if(bottomRightPosition == null) {
            this.bottomRightPosition = new Point(columnIndex, rowIndex);
        }
        
        // 左上のセルの位置の設定
        if(topLeftPoisitoin.x > columnIndex) {
            this.topLeftPoisitoin.x = columnIndex;
        }
        
        if(topLeftPoisitoin.y > rowIndex) {
            this.topLeftPoisitoin.y = rowIndex;
        }
        
        // 右下のセルの位置の設定
        if(bottomRightPosition.x < columnIndex) {
            this.bottomRightPosition.x = columnIndex;
        }
        
        if(bottomRightPosition.y < rowIndex) {
            this.bottomRightPosition.y = rowIndex;
        }
    }
1230042
public void updateRowId(int columnIndex, RowId x) throws SQLException {
        try {
            rsetImpl.updateRowId(columnIndex, x);
        } catch (SQLException sqlX) {
            FFDCFilter.processException(
                                        sqlX, getClass().getName() + ".updateRowId", "5064", this);
            throw WSJdbcUtil.mapException(this, sqlX);
        } catch (NullPointerException nullX) {
            // No FFDC code needed; we might be closed.
            throw runtimeXIfNotClosed(nullX);
        } catch (AbstractMethodError methError) {
            // No FFDC code needed; wrong JDBC level.
            throw AdapterUtil.notSupportedX("ResultSet.updateRowId", methError);
        } catch (RuntimeException runX) {
            FFDCFilter.processException(
                                        runX, getClass().getName() + ".updateRowId", "5080", this);
            if (tc.isDebugEnabled())
                Tr.debug(this, tc, "updateRowId", runX);
            throw runX;
        } catch (Error err) {
            FFDCFilter.processException(
                                        err, getClass().getName() + ".updateRowId", "5087", this);
            if (tc.isDebugEnabled())
                Tr.debug(this, tc, "updateRowId", err);
            throw err;
        }
    }
788207
@Override
    public TableCellRenderer getCellRenderer(int row, int column) {
        PropertySheetTableModel.Item item = getSheetModel()
                .getPropertySheetElement(row);

        switch (column) {
            case PropertySheetTableModel.NAME_COLUMN:
                // name column gets a custom renderer
                return nameRenderer;

            case PropertySheetTableModel.VALUE_COLUMN:
                if (!item.isProperty()) {
                    return nameRenderer;
                }

                // property value column gets the renderer from the factory
                Property property = item.getProperty();
                TableCellRenderer renderer = getRendererFactory().createTableCellRenderer(property);
                if (renderer == null) {
                    renderer = getCellRenderer(property.getType());
                }
                return renderer;
            default:
                // when will this happen, given the above?
                return super.getCellRenderer(row, column);
        }
    }
1112329
public com.google.privacy.dlp.v2.Table.RowOrBuilder getRowsOrBuilder(int index) {
    return rows_.get(index);
  }
681848
function(chunk)
  {
    // get all the rows in the current chunk that overlap with the requested
    // window
    var chunkStart = chunk.getStartIndex();
    var chunkEnd   = chunk.getEndIndex();
    var rows       = chunk.getRows().slice(
        Math.max(chunkStart, start) - chunkStart,
        Math.min(chunkEnd, end) + 1 - chunkStart);

    var rowIndex = 0;
    var rowsLength = rows.length;

    // create a function that can be called to batch-process rows
    var processRows = function()
    {
      // get the start position and start time
      var startIndex = rowIndex;
      var startTime  = Date.now();

      var each = options.each;
      while (rowIndex < rowsLength)
      {
        // invoke the each() callback on the current row
        var ret = each(rows[rowIndex++]);

        context.numRowsProcessed++;

        // if the callback returned false, stop processing rows
        if (ret === false)
        {
          var stoppedProcessingRows = true;
          break;
        }

        // use the current position and current time to check if we've been
        // processing rows for too long; if so, leave the rest for the next
        // tick of the event loop
        if ((rowIndex - startIndex) >= context.rowBatchSize &&
            (Date.now() - startTime) > context.rowBatchDuration)
        {
          process.nextTick(processRows);
          break;
        }
      }

      // if there are no more rows for us to process in this chunk
      if (!(rowIndex < rowsLength) || stoppedProcessingRows)
      {
        // if we exhausted all the rows in this chunk and we haven't yet
        // processed all the rows we want to process, ask the result stream to
        // do another read
        if (!(rowIndex < rowsLength) &&
            context.numRowsProcessed !== context.maxNumRowsToProcess)
        {
          resultStream.read();
        }
        else
        {
          // we've either processed all the rows we wanted to process or we
          // were told to stop processing rows by the each() callback; either
          // way, close the result stream to complete the operation
          resultStream.asyncClose();
        }
      }
    };

    // start processing rows
    processRows();
  }