Example usage for org.apache.poi.hssf.record RowRecord getFirstCol

List of usage examples for org.apache.poi.hssf.record RowRecord getFirstCol

Introduction

In this page you can find the example usage for org.apache.poi.hssf.record RowRecord getFirstCol.

Prototype

public int getFirstCol() 

Source Link

Document

get the logical col number for the first cell this row (0 based index)

Usage

From source file:ambit.test.io.POIExample.java

License:Open Source License

public void processRecord(Record record) {
    switch (record.getSid()) {
    // the BOFRecord can represent either the beginning of a sheet or the workbook
    case BOFRecord.sid:
        BOFRecord bof = (BOFRecord) record;
        if (bof.getType() == bof.TYPE_WORKBOOK) {
            System.out.println("Encountered workbook");
            // assigned to the class level member
        } else if (bof.getType() == bof.TYPE_WORKSHEET) {
            System.out.println("Encountered sheet reference");
        }/*from www  . j a v  a  2  s . co  m*/
        break;
    case BoundSheetRecord.sid:
        BoundSheetRecord bsr = (BoundSheetRecord) record;
        System.out.println("New sheet named: " + bsr.getSheetname());
        break;
    case RowRecord.sid:
        RowRecord rowrec = (RowRecord) record;
        System.out.println("Row found, first column at " + rowrec.getFirstCol() + " last column at "
                + rowrec.getLastCol());
        break;
    case NumberRecord.sid:
        NumberRecord numrec = (NumberRecord) record;
        System.out.println("Cell found with value " + numrec.getValue() + " at row " + numrec.getRow()
                + " and column " + numrec.getColumn());
        break;
    // SSTRecords store a array of unique strings used in Excel.
    case SSTRecord.sid:
        sstrec = (SSTRecord) record;
        for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) {
            System.out.println("String table value " + k + " = " + sstrec.getString(k));
        }
        break;
    case LabelSSTRecord.sid:
        LabelSSTRecord lrec = (LabelSSTRecord) record;
        System.out.println("String cell found with value " + sstrec.getString(lrec.getSSTIndex()));
        break;
    }
}

From source file:com.netxforge.netxstudio.screens.f4.support.XLSService.java

License:Open Source License

/**
 * This method listens for incoming records and handles them as required.
 * /*w ww .  j  ava  2  s  . c o  m*/
 * @param record
 *            The record that was found while reading.
 */
private int processRecordInternal(Record record) {

    if (currentMonitor.isCanceled()) {
        // we should interrupt the process here.
        return ABORTED;
    }

    // Produce a multiple kvp for the .xls

    switch (record.getSid()) {
    // the BOFRecord can represent either the beginning of a sheet or the
    // workbook
    case BOFRecord.sid:
        BOFRecord bof = (BOFRecord) record;
        if (bof.getType() == BOFRecord.TYPE_WORKBOOK) {
            System.out.println("Encountered workbook");
            // assigned to the class level member
        } else if (bof.getType() == BOFRecord.TYPE_WORKSHEET) {

            currentRecordMap = Lists.newArrayListWithExpectedSize(32);
            // fill the list with at least x map entries.
            for (int i = 0; i < MAX_VISIBLE_ROWS; i++) {
                Map<Integer, Tuple> map = Maps.newHashMap();
                currentRecordMap.add(map);
            }

            sheets.add(currentRecordMap);
            System.out.println("Encountered sheet reference, changing sheet...");
        }
        break;
    case BoundSheetRecord.sid:
        BoundSheetRecord bsr = (BoundSheetRecord) record;
        System.out.println("New sheet named: " + bsr.getSheetname());

        break;

    // Row records come in batch (32) before the actual cell records.

    case RowRecord.sid:

        RowRecord rowrec = (RowRecord) record;
        // Look for our header row, when found we have to interpret the
        // values.

        System.out.println("Row found" + rowrec.getRowNumber() + ", first column at " + rowrec.getFirstCol()
                + " last column at " + rowrec.getLastCol());
        break;

    // SSTRecords store a array of unique strings used in Excel.
    case SSTRecord.sid:
        currentSStrec = (SSTRecord) record;
        // for (int k = 0; k < currentSStrec.getNumUniqueStrings(); k++) {
        // System.out.println("String table value " + k + " = "
        // + currentSStrec.getString(k));
        // }
        break;
    case DateWindow1904Record.sid: {
        System.out.println("Hitting Date record. ");

    }
        break;
    case NumberRecord.sid:
    case LabelSSTRecord.sid:

        int column = -1;
        int row = -1;
        Object value = null;

        if (record.getSid() == NumberRecord.sid) {
            NumberRecord numrec = (NumberRecord) record;

            double numValue = numrec.getValue();
            column = numrec.getColumn();
            row = numrec.getRow();

            value = this.formatNumberDateCell(numrec, numValue);

            // DEBUG
            System.out.println("Number:Cell found with value " + value + " at: [" + row + "," + column + "]");

        }
        if (record.getSid() == LabelSSTRecord.sid) {
            LabelSSTRecord lrec = (LabelSSTRecord) record;
            value = currentSStrec.getString(lrec.getSSTIndex()).toString();
            column = lrec.getColumn();
            row = lrec.getRow();

            // DEBUG
            System.out.println("String:Cell found with value " + value + " at: [" + row + "," + column + "]");
        }

        if (value != null && row != -1 && column != -1) {
            Tuple t = new Tuple(column, value);

            if (currentRecordMap.size() < row) {
                Map<Integer, Tuple> map = Maps.newHashMap();
                currentRecordMap.add(map);
            }
            currentRecordMap.get(row).put(column, t);

        } else {
            System.err.println("Incomplete cell encountered" + "v=" + value + " r=" + row + " c=" + column);
        }
        // TODO, do a more gracefull check with a switch break to proceed,
        // or other strategy if this fails.
        // assert row > 0 && column > 0 && value != null;

        if (column == 0) {
            currentMonitor.worked(1);
            currentRowProgress = true; // reset for the next row.
            processedRows++; // Update the number of processed rows.

        } else {
            // Did we have a failure on a previous column, if so skip this
            // column until the next row.
            if (!currentRowProgress) {
                break;
            }
            // We have an undefined column.
            this.currentRowProgress = false;

        }

        break;
    }
    return OK;
}

From source file:poi.hssf.usermodel.examples.EventExample.java

License:Apache License

/**
 * This method listens for incoming records and handles them as required.
 * @param record    The record that was found while reading.
 */// w  w  w . ja va  2s .co  m
public void processRecord(Record record) {
    switch (record.getSid()) {
    // the BOFRecord can represent either the beginning of a sheet or the workbook
    case BOFRecord.sid:
        BOFRecord bof = (BOFRecord) record;
        if (bof.getType() == bof.TYPE_WORKBOOK) {
            System.out.println("Encountered workbook");
            // assigned to the class level member
        } else if (bof.getType() == bof.TYPE_WORKSHEET) {
            System.out.println("Encountered sheet reference");
        }
        break;
    case BoundSheetRecord.sid:
        BoundSheetRecord bsr = (BoundSheetRecord) record;
        System.out.println("New sheet named: " + bsr.getSheetname());
        break;
    case RowRecord.sid:
        RowRecord rowrec = (RowRecord) record;
        System.out.println("Row found, first column at " + rowrec.getFirstCol() + " last column at "
                + rowrec.getLastCol());
        break;
    case NumberRecord.sid:
        NumberRecord numrec = (NumberRecord) record;
        System.out.println("Cell found with value " + numrec.getValue() + " at row " + numrec.getRow()
                + " and column " + numrec.getColumn());
        break;
    // SSTRecords store a array of unique strings used in Excel.
    case SSTRecord.sid:
        sstrec = (SSTRecord) record;
        for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) {
            System.out.println("String table value " + k + " = " + sstrec.getString(k));
        }
        break;
    case LabelSSTRecord.sid:
        LabelSSTRecord lrec = (LabelSSTRecord) record;
        System.out.println("String cell found with value " + sstrec.getString(lrec.getSSTIndex()));
        break;
    }
}

From source file:util.XLSReader.java

License:Open Source License

/**
 * This method listens for incoming records and handles them as required.
 * //from   w w w.j  a v  a 2  s .  com
 * @param record
 */
public void processRecord(final Record record) {
    switch (record.getSid()) {

    // the BOFRecord can represent either the beginning of a sheet or the workbook
    case BOFRecord.sid:
        final BOFRecord bof = (BOFRecord) record;
        if (bof.getType() == BOFRecord.TYPE_WORKBOOK) {
            LOG.debug("Encountered workbook");
            // assigned to the class level member
        } else if (bof.getType() == BOFRecord.TYPE_WORKSHEET) {
            LOG.debug("Encountered sheet reference");
        }
        break;
    case BoundSheetRecord.sid:
        final BoundSheetRecord bsr = (BoundSheetRecord) record;
        LOG.debug("New sheet named: " + bsr.getSheetname());
        break;
    case RowRecord.sid:
        final RowRecord rowrec = (RowRecord) record;
        // counts for all rows
        LOG.debug("Row at " + rowrec.getRowNumber() + " found, first column at " + rowrec.getFirstCol()
                + " last column at " + rowrec.getLastCol() + ". Total number of columns: "
                + rowrec.getRecordSize());
        break;
    case NumberRecord.sid:
        // cells with numbers
        final NumberRecord numrec = (NumberRecord) record;
        if (getLastrow() < numrec.getRow()) { // start of a new record / row
            if (numrec.getRow() > 0) { // put the old record / row into result
                // make a copy, because the reference will be reused
                final ArrayList<String> copy = new ArrayList<String>();
                setLastcol(-1); // reset column count
                copy.addAll(rowcontent);
                result.add(copy);
            }
            rowcontent = new ArrayList<String>();
        }

        // set current row number
        setLastrow(numrec.getRow());

        // add empty cell contents for the missing cells
        addEmptyCells(numrec.getColumn() - getLastcol());

        // set current column number
        setLastcol(numrec.getColumn());

        // add cell content into rowcontent...
        if (numrec.getColumn() == 3 || numrec.getColumn() == 4) {
            //... with possible float point numbers for Location Name (3) and Shelfmark (4)...
            rowcontent.add(String.valueOf(numrec.getValue()));
        } else {
            //.. and without float point numbers for all other cells...
            rowcontent.add(String.valueOf(new Double(numrec.getValue()).longValue()));
        }

        break;
    // SSTRecords store a array of unique strings used in Excel.
    case SSTRecord.sid:
        sstrec = (SSTRecord) record;
        for (int k = 0; k < sstrec.getNumUniqueStrings(); k++) {
            LOG.debug("String table value " + k + " = " + sstrec.getString(k));
        }
        break;
    case LabelSSTRecord.sid:
        // cells with strings
        final LabelSSTRecord lrec = (LabelSSTRecord) record;
        if (getLastrow() < lrec.getRow()) { // start of a new record / row
            if (lrec.getRow() > 0) { // put the old record / row into result
                // make a copy, because the reference will be reused
                final ArrayList<String> copy = new ArrayList<String>();
                setLastcol(-1); // reset column count
                copy.addAll(rowcontent);
                result.add(copy);
            }
            rowcontent = new ArrayList<String>();
        }

        // set current row number
        setLastrow(lrec.getRow());

        // add empty cell contents for the missing cells
        addEmptyCells(lrec.getColumn() - getLastcol());

        // set current column number
        setLastcol(lrec.getColumn());

        // add cell content into rowcontent
        rowcontent.add(sstrec.getString(lrec.getSSTIndex()).toString());

        break;
    }
}