Example usage for org.apache.poi.hssf.record BOFRecord getType

List of usage examples for org.apache.poi.hssf.record BOFRecord getType

Introduction

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

Prototype

public int getType() 

Source Link

Document

type of object this marks

Usage

From source file:XLS2CSV.java

License:Apache License

/**
 * Main HSSFListener method, processes events, and outputs the CSV as the
 * file is processed./* w  w  w.  j a v  a  2s  . co m*/
 */
@SuppressWarnings("unchecked")
public void processRecord(Record record) {
    int thisRow = -1;
    int thisColumn = -1;
    String thisStr = null;

    switch (record.getSid()) {
    case BoundSheetRecord.sid:
        boundSheetRecords.add(record);
        break;
    case BOFRecord.sid:
        BOFRecord br = (BOFRecord) record;
        if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
            // Create sub workbook if required
            if (workbookBuildingListener != null && stubWorkbook == null) {
                stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
            }

            // Output the worksheet name
            // Works by ordering the BSRs by the location of
            // their BOFRecords, and then knowing that we
            // process BOFRecords in byte offset order
            sheetIndex++;
            if (orderedBSRs == null) {
                orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords);
            }
            output.println();
            output.println(orderedBSRs[sheetIndex].getSheetname() + " [" + (sheetIndex + 1) + "]:");
        }
        break;

    case SSTRecord.sid:
        sstRecord = (SSTRecord) record;
        break;

    case BlankRecord.sid:
        BlankRecord brec = (BlankRecord) record;

        thisRow = brec.getRow();
        thisColumn = brec.getColumn();
        thisStr = "";
        break;
    case BoolErrRecord.sid:
        BoolErrRecord berec = (BoolErrRecord) record;

        thisRow = berec.getRow();
        thisColumn = berec.getColumn();
        thisStr = "";
        break;

    case FormulaRecord.sid:
        FormulaRecord frec = (FormulaRecord) record;

        thisRow = frec.getRow();
        thisColumn = frec.getColumn();

        if (outputFormulaValues) {
            if (Double.isNaN(frec.getValue())) {
                // Formula result is a string
                // This is stored in the next record
                outputNextStringRecord = true;
                nextRow = frec.getRow();
                nextColumn = frec.getColumn();
            } else {
                thisStr = formatListener.formatNumberDateCell(frec);
            }
        } else {
            thisStr = '"' + HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()) + '"';
        }
        break;
    case StringRecord.sid:
        if (outputNextStringRecord) {
            // String for formula
            StringRecord srec = (StringRecord) record;
            thisStr = srec.getString();
            thisRow = nextRow;
            thisColumn = nextColumn;
            outputNextStringRecord = false;
        }
        break;

    case LabelRecord.sid:
        LabelRecord lrec = (LabelRecord) record;

        thisRow = lrec.getRow();
        thisColumn = lrec.getColumn();
        thisStr = '"' + lrec.getValue() + '"';
        break;
    case LabelSSTRecord.sid:
        LabelSSTRecord lsrec = (LabelSSTRecord) record;

        thisRow = lsrec.getRow();
        thisColumn = lsrec.getColumn();
        if (sstRecord == null) {
            thisStr = '"' + "(No SST Record, can't identify string)" + '"';
        } else {
            thisStr = '"' + sstRecord.getString(lsrec.getSSTIndex()).toString() + '"';
        }
        break;
    case NoteRecord.sid:
        NoteRecord nrec = (NoteRecord) record;

        thisRow = nrec.getRow();
        thisColumn = nrec.getColumn();
        // TODO: Find object to match nrec.getShapeId()
        thisStr = '"' + "(TODO)" + '"';
        break;
    case NumberRecord.sid:
        NumberRecord numrec = (NumberRecord) record;

        thisRow = numrec.getRow();
        thisColumn = numrec.getColumn();

        // Format
        thisStr = formatListener.formatNumberDateCell(numrec);
        break;
    case RKRecord.sid:
        RKRecord rkrec = (RKRecord) record;

        thisRow = rkrec.getRow();
        thisColumn = rkrec.getColumn();
        thisStr = '"' + "(TODO)" + '"';
        break;
    default:
        break;
    }

    // Handle new row
    if (thisRow != -1 && thisRow != lastRowNumber) {
        lastColumnNumber = -1;
    }

    // Handle missing column
    if (record instanceof MissingCellDummyRecord) {
        MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
        thisRow = mc.getRow();
        thisColumn = mc.getColumn();
        thisStr = "";
    }

    // If we got something to print out, do so
    if (thisStr != null) {
        if (thisColumn > 0) {
            output.print(',');
        }
        output.print(thisStr);
    }

    // Update column and row count
    if (thisRow > -1)
        lastRowNumber = thisRow;
    if (thisColumn > -1)
        lastColumnNumber = thisColumn;

    // Handle end of row
    if (record instanceof LastCellOfRowDummyRecord) {
        // Print out any missing commas if needed
        if (minColumns > 0) {
            // Columns are 0 based
            if (lastColumnNumber == -1) {
                lastColumnNumber = 0;
            }
            for (int i = lastColumnNumber; i < (minColumns); i++) {
                output.print(',');
            }
        }

        // We're onto a new row
        lastColumnNumber = -1;

        // End the row
        output.println();
    }
}

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");
        }/*  w w  w.  ja v  a2 s .c om*/
        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:ambit2.core.test.io.POItest.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() == BOFRecord.TYPE_WORKBOOK) {
            //System.out.println("Encountered workbook");
            // assigned to the class level member
        } else if (bof.getType() == BOFRecord.TYPE_WORKSHEET) {
            //System.out.println("Encountered sheet reference");
        }/*from   w  w w .j a  v a2  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:cn.sinobest.jzpt.minidemo.poidemo.example.XLS2CSVmra.java

License:Apache License

/**
 * Main HSSFListener method, processes events, and outputs the
 *  CSV as the file is processed.//from  ww  w.  j a v  a  2s. c o  m
 */
public void processRecord(Record record) {
    int thisRow = -1;
    int thisColumn = -1;
    String thisStr = null;

    switch (record.getSid()) {
    case BoundSheetRecord.sid:
        boundSheetRecords.add(record);
        break;
    case BOFRecord.sid:
        BOFRecord br = (BOFRecord) record;
        if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
            // Create sub workbook if required
            if (workbookBuildingListener != null && stubWorkbook == null) {
                stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
            }

            // Output the worksheet name
            // Works by ordering the BSRs by the location of
            //  their BOFRecords, and then knowing that we
            //  process BOFRecords in byte offset order
            sheetIndex++;
            if (orderedBSRs == null) {
                orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords);
            }
            output.println();
            output.println(orderedBSRs[sheetIndex].getSheetname() + " [" + (sheetIndex + 1) + "]:");
        }
        break;

    case SSTRecord.sid:
        sstRecord = (SSTRecord) record;
        break;

    case BlankRecord.sid:
        BlankRecord brec = (BlankRecord) record;

        thisRow = brec.getRow();
        thisColumn = brec.getColumn();
        thisStr = "";
        break;
    case BoolErrRecord.sid:
        BoolErrRecord berec = (BoolErrRecord) record;

        thisRow = berec.getRow();
        thisColumn = berec.getColumn();
        thisStr = "";
        break;

    case FormulaRecord.sid:
        FormulaRecord frec = (FormulaRecord) record;

        thisRow = frec.getRow();
        thisColumn = frec.getColumn();

        if (outputFormulaValues) {
            if (Double.isNaN(frec.getValue())) {
                // Formula result is a string
                // This is stored in the next record
                outputNextStringRecord = true;
                nextRow = frec.getRow();
                nextColumn = frec.getColumn();
            } else {
                thisStr = formatListener.formatNumberDateCell(frec);
            }
        } else {
            thisStr = '"' + HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()) + '"';
        }
        break;
    case StringRecord.sid:
        if (outputNextStringRecord) {
            // String for formula
            StringRecord srec = (StringRecord) record;
            thisStr = srec.getString();
            thisRow = nextRow;
            thisColumn = nextColumn;
            outputNextStringRecord = false;
        }
        break;

    case LabelRecord.sid:
        LabelRecord lrec = (LabelRecord) record;

        thisRow = lrec.getRow();
        thisColumn = lrec.getColumn();
        thisStr = '"' + lrec.getValue() + '"';
        break;
    case LabelSSTRecord.sid:
        LabelSSTRecord lsrec = (LabelSSTRecord) record;

        thisRow = lsrec.getRow();
        thisColumn = lsrec.getColumn();
        if (sstRecord == null) {
            thisStr = '"' + "(No SST Record, can't identify string)" + '"';
        } else {
            thisStr = '"' + sstRecord.getString(lsrec.getSSTIndex()).toString() + '"';
        }
        break;
    case NoteRecord.sid:
        NoteRecord nrec = (NoteRecord) record;

        thisRow = nrec.getRow();
        thisColumn = nrec.getColumn();
        // TODO: Find object to match nrec.getShapeId()
        thisStr = '"' + "(TODO)" + '"';
        break;
    case NumberRecord.sid:
        NumberRecord numrec = (NumberRecord) record;
        System.out.println(numrec.getSid());

        thisRow = numrec.getRow();
        thisColumn = numrec.getColumn();

        // Format
        thisStr = formatListener.formatNumberDateCell(numrec);
        //            if(HSSFDateUtil.isValidExcelDate(numrec.getValue())){
        System.out.println(HSSFDateUtil.isValidExcelDate(numrec.getValue()));

        //            }
        //            System.out.println("formatListener--------"+formatListener.getFormatString(1));
        //            System.out.println("thisStr----------"+thisStr);
        break;
    case RKRecord.sid:
        RKRecord rkrec = (RKRecord) record;

        thisRow = rkrec.getRow();
        thisColumn = rkrec.getColumn();
        thisStr = '"' + "(TODO)" + '"';
        break;
    default:
        break;
    }

    // Handle new row
    if (thisRow != -1 && thisRow != lastRowNumber) {
        lastColumnNumber = -1;
    }

    // Handle missing column
    if (record instanceof MissingCellDummyRecord) {
        MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
        thisRow = mc.getRow();
        thisColumn = mc.getColumn();
        thisStr = "";
    }

    // If we got something to print out, do so
    if (thisStr != null) {
        if (thisColumn > 0) {
            output.print(',');
        }
        output.print(thisStr);
    }

    // Update column and row count
    if (thisRow > -1)
        lastRowNumber = thisRow;
    if (thisColumn > -1)
        lastColumnNumber = thisColumn;

    // Handle end of row
    if (record instanceof LastCellOfRowDummyRecord) {
        // Print out any missing commas if needed
        if (minColumns > 0) {
            // Columns are 0 based
            if (lastColumnNumber == -1) {
                lastColumnNumber = 0;
            }
            for (int i = lastColumnNumber; i < (minColumns); i++) {
                output.print(',');
            }
        }

        // We're onto a new row
        lastColumnNumber = -1;

        // End the row
        output.println();
    }
}

From source file:com.bayareasoftware.chartengine.ds.util.XLS2Data.java

License:Apache License

/**
 * Main HSSFListener method, processes events, and outputs the CSV as the
 * file is processed./*w w w  .ja v a2s.c  o m*/
 */
public void processRecord(Record record) {
    int thisRow = -1;
    int thisColumn = -1;
    String thisStr = null;

    //p("looking at " + record.getClass().getName() + " sid=0x" + Integer.toHexString(record.getSid()));
    if ((record.getSid() != BoundSheetRecord.sid && record.getSid() != BOFRecord.sid)
            && currentSheetName != null && this.requiredSheetName != null
            && !this.requiredSheetName.equals(currentSheetName)) {
        return;
    }
    switch (record.getSid()) {
    case BoundSheetRecord.sid:
        boundSheetRecords.add(record);
        break;
    case BOFRecord.sid:
        BOFRecord br = (BOFRecord) record;
        if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
            // Create sub workbook if required
            if (workbookBuildingListener != null && stubWorkbook == null) {
                stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
            }

            // Output the worksheet name
            // Works by ordering the BSRs by the location of
            // their BOFRecords, and then knowing that we
            // process BOFRecords in byte offset order
            sheetIndex++;
            if (orderedBSRs == null) {
                orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords);
            }
            //output.println();
            startNewSheet();
            currentSheetName = orderedBSRs[sheetIndex].getSheetname();
            //System.err.println("got sheet name '" + currentSheetName + "' required='"
            //      + this.requiredSheetName + "'");
            /*if (requiredSheetName == null) {
            startNewRow();
            //output.println(orderedBSRs[sheetIndex].getSheetname() + " ["
            //+ (sheetIndex + 1) + "]:");
            appendCell(currentSheetName + " ["
                    + (sheetIndex + 1) + "]:");
            startNewRow();
            }
            */
        } else if (br.getType() == BOFRecord.TYPE_CHART) {
            //p("got chart");
        }
        break;

    case SSTRecord.sid:
        sstRecord = (SSTRecord) record;
        break;

    case BlankRecord.sid:
        BlankRecord brec = (BlankRecord) record;

        thisRow = brec.getRow();
        thisColumn = brec.getColumn();
        thisStr = "";
        break;
    case BoolErrRecord.sid:
        BoolErrRecord berec = (BoolErrRecord) record;

        thisRow = berec.getRow();
        thisColumn = berec.getColumn();
        thisStr = "";
        break;

    case FormulaRecord.sid:
        FormulaRecord frec = (FormulaRecord) record;

        thisRow = frec.getRow();
        thisColumn = frec.getColumn();

        if (outputFormulaValues) {
            if (Double.isNaN(frec.getValue())) {
                // Formula result is a string
                // This is stored in the next record
                outputNextStringRecord = true;
                nextRow = frec.getRow();
                nextColumn = frec.getColumn();
            } else {
                thisStr = "" + frec.getValue();
                //thisStr = formatListener.formatNumberDateCell(frec);
            }
        } else {
            thisStr = '"' + HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()) + '"';
        }
        break;
    case StringRecord.sid:
        if (outputNextStringRecord) {
            // String for formula
            StringRecord srec = (StringRecord) record;
            thisStr = srec.getString();
            thisRow = nextRow;
            thisColumn = nextColumn;
            outputNextStringRecord = false;
        }
        break;

    case LabelRecord.sid:
        LabelRecord lrec = (LabelRecord) record;

        thisRow = lrec.getRow();
        thisColumn = lrec.getColumn();
        //thisStr = '"' + lrec.getValue() + '"';
        thisStr = lrec.getValue();
        break;
    case LabelSSTRecord.sid:
        LabelSSTRecord lsrec = (LabelSSTRecord) record;

        thisRow = lsrec.getRow();
        thisColumn = lsrec.getColumn();
        if (sstRecord == null) {
            thisStr = '"' + "(No SST Record, can't identify string)" + '"';
        } else {
            //thisStr = '"' + sstRecord.getString(lsrec.getSSTIndex())
            //      .toString() + '"';
            thisStr = sstRecord.getString(lsrec.getSSTIndex()).toString();
        }
        break;
    case NoteRecord.sid:
        NoteRecord nrec = (NoteRecord) record;

        thisRow = nrec.getRow();
        thisColumn = nrec.getColumn();
        // TODO: Find object to match nrec.getShapeId()
        thisStr = '"' + "(TODO - NoteRecord (" + thisRow + "," + thisColumn + "))" + '"';
        break;
    case NumberRecord.sid:
        NumberRecord numrec = (NumberRecord) record;

        thisRow = numrec.getRow();
        thisColumn = numrec.getColumn();

        // Format
        thisStr = formatListener.formatNumberDateCell(numrec);
        break;
    case RKRecord.sid:
        RKRecord rkrec = (RKRecord) record;

        thisRow = rkrec.getRow();
        thisColumn = rkrec.getColumn();
        thisStr = '"' + "(TODO - RKRecord (" + thisRow + "," + thisColumn + "))" + '"';
        break;
    default:
        break;
    }

    // Handle new row
    if (thisRow != -1 && thisRow != lastRowNumber) {
        lastColumnNumber = -1;
    }

    // Handle missing column
    if (record instanceof MissingCellDummyRecord) {
        MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
        thisRow = mc.getRow();
        thisColumn = mc.getColumn();
        thisStr = "";
    }

    // If we got something to print out, do so
    if (thisStr != null) {
        appendCell(thisStr);
    }

    // Update column and row count
    if (thisRow > -1)
        lastRowNumber = thisRow;
    if (thisColumn > -1)
        lastColumnNumber = thisColumn;

    // Handle end of row
    if (record instanceof LastCellOfRowDummyRecord) {
        // We're onto a new row
        lastColumnNumber = -1;

        // End the row
        //output.println();
        startNewRow();
    }
}

From source file:com.bstek.dorado.importer.policy.impl.XLS2CSV.java

License:Apache License

/**
 * Main HSSFListener method, processes events, and outputs the CSV as the
 * file is processed.//from w  w  w . j ava2  s  .c  o  m
 */
public void processRecord(Record record) {
    int thisRow = -1;
    int thisColumn = -1;
    String thisStr = null;

    switch (record.getSid()) {
    case BoundSheetRecord.sid:
        boundSheetRecords.add(record);
        break;
    case BOFRecord.sid:
        BOFRecord br = (BOFRecord) record;
        if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
            // Create sub workbook if required
            if (workbookBuildingListener != null && stubWorkbook == null) {
                stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
            }

            // Output the worksheet name
            // Works by ordering the BSRs by the location of
            // their BOFRecords, and then knowing that we
            // process BOFRecords in byte offset order
            sheetIndex++;
            if (orderedBSRs == null) {
                orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords);
            }
            output.println();
            output.println(orderedBSRs[sheetIndex].getSheetname() + " [" + (sheetIndex + 1) + "]:");
        }
        break;

    case SSTRecord.sid:
        sstRecord = (SSTRecord) record;
        break;

    case BlankRecord.sid:
        BlankRecord brec = (BlankRecord) record;

        thisRow = brec.getRow();
        thisColumn = brec.getColumn();
        thisStr = "";
        break;
    case BoolErrRecord.sid:
        BoolErrRecord berec = (BoolErrRecord) record;

        thisRow = berec.getRow();
        thisColumn = berec.getColumn();
        thisStr = "";
        break;

    case FormulaRecord.sid:
        FormulaRecord frec = (FormulaRecord) record;

        thisRow = frec.getRow();
        thisColumn = frec.getColumn();

        if (outputFormulaValues) {
            if (Double.isNaN(frec.getValue())) {
                // Formula result is a string
                // This is stored in the next record
                outputNextStringRecord = true;
                nextRow = frec.getRow();
                nextColumn = frec.getColumn();
            } else {
                thisStr = formatListener.formatNumberDateCell(frec);
            }
        } else {
            thisStr = '"' + HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()) + '"';
        }
        break;
    case StringRecord.sid:
        if (outputNextStringRecord) {
            // String for formula
            StringRecord srec = (StringRecord) record;
            thisStr = srec.getString();
            thisRow = nextRow;
            thisColumn = nextColumn;
            outputNextStringRecord = false;
        }
        break;

    case LabelRecord.sid:
        LabelRecord lrec = (LabelRecord) record;

        thisRow = lrec.getRow();
        thisColumn = lrec.getColumn();
        thisStr = '"' + lrec.getValue() + '"';
        break;
    case LabelSSTRecord.sid:
        LabelSSTRecord lsrec = (LabelSSTRecord) record;

        thisRow = lsrec.getRow();
        thisColumn = lsrec.getColumn();
        if (sstRecord == null) {
            thisStr = '"' + "(No SST Record, can't identify string)" + '"';
        } else {
            thisStr = '"' + sstRecord.getString(lsrec.getSSTIndex()).toString() + '"';
        }
        break;
    case NoteRecord.sid:
        NoteRecord nrec = (NoteRecord) record;

        thisRow = nrec.getRow();
        thisColumn = nrec.getColumn();
        // TODO: Find object to match nrec.getShapeId()
        thisStr = '"' + "(TODO)" + '"';
        break;
    case NumberRecord.sid:
        NumberRecord numrec = (NumberRecord) record;

        thisRow = numrec.getRow();
        thisColumn = numrec.getColumn();

        // Format
        thisStr = formatListener.formatNumberDateCell(numrec);
        break;
    case RKRecord.sid:
        RKRecord rkrec = (RKRecord) record;

        thisRow = rkrec.getRow();
        thisColumn = rkrec.getColumn();
        thisStr = '"' + "(TODO)" + '"';
        break;
    default:
        break;
    }

    // Handle new row
    if (thisRow != -1 && thisRow != lastRowNumber) {
        lastColumnNumber = -1;
    }

    // Handle missing column
    if (record instanceof MissingCellDummyRecord) {
        MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
        thisRow = mc.getRow();
        thisColumn = mc.getColumn();
        thisStr = "";
    }

    // If we got something to print out, do so
    if (thisStr != null) {
        if (thisColumn > 0) {
            output.print(',');
        }
        output.print(thisStr);
    }

    // Update column and row count
    if (thisRow > -1)
        lastRowNumber = thisRow;
    if (thisColumn > -1)
        lastColumnNumber = thisColumn;

    // Handle end of row
    if (record instanceof LastCellOfRowDummyRecord) {
        // Print out any missing commas if needed
        if (minColumns > 0) {
            // Columns are 0 based
            if (lastColumnNumber == -1) {
                lastColumnNumber = 0;
            }
            for (int i = lastColumnNumber; i < (minColumns); i++) {
                output.print(',');
            }
        }

        // We're onto a new row
        lastColumnNumber = -1;

        // End the row
        output.println();
    }
}

From source file:com.daphne.es.showcase.excel.service.Excel2003ImportListener.java

License:Apache License

@Override
public void processRecord(final Record record) {
    switch (record.getSid()) {
    case BOFRecord.sid:
        //?workboot sheet 
        BOFRecord bof = (BOFRecord) record;
        if (bof.getType() == bof.TYPE_WORKBOOK) {
            //workbook
        } else if (bof.getType() == bof.TYPE_WORKSHEET) {
            //sheet
        }/*  w w  w . j ava  2s  .  com*/
        break;
    case BoundSheetRecord.sid:
        //?BundleSheet
        BoundSheetRecord bsr = (BoundSheetRecord) record;
        //bsr.getSheetname() sheet name
        break;
    case RowRecord.sid:
        //?
        RowRecord rowrec = (RowRecord) record;
        break;
    case SSTRecord.sid:
        // SSTRecordsExcelString
        sstrec = (SSTRecord) record;
        break;
    case NumberRecord.sid:
    case LabelSSTRecord.sid:
        if (record instanceof NumberRecord) {
            //?Number?
            NumberRecord numrec = (NumberRecord) record;
            //numrec.getRow()  numrec.getColumn()   numrec.getValue()

            if (numrec.getRow() == 0) {
                // 
                break;
            } else if (numrec.getColumn() == 0) { //
                current = new ExcelData();
                current.setId(Double.valueOf(numrec.getValue()).longValue());
            } else if (numrec.getColumn() == 1) {//
                current.setContent(String.valueOf(Double.valueOf(numrec.getValue()).longValue()));
                add(current);
            }
            break;

        } else if (record instanceof LabelSSTRecord) {
            //?String?SSTRecord
            LabelSSTRecord lrec = (LabelSSTRecord) record;

            if (lrec.getRow() == 0) {
                // 
                break;
            } else if (lrec.getColumn() == 0) { //
                current = new ExcelData();
                String value = sstrec.getString(lrec.getSSTIndex()).getString();
                current.setId(Double.valueOf(value).longValue());
            } else if (lrec.getColumn() == 1) {//
                String value = sstrec.getString(lrec.getSSTIndex()).getString();
                current.setContent(value);
                add(current);
            }
            break;
        }
        break;
    }

}

From source file:com.epac.java.converter.ms2text.XLS2CSVmra.java

License:Apache License

/**
 * Main HSSFListener method, processes events, and outputs the
 *  CSV as the file is processed.//from   www .  ja  v a 2  s.  co  m
 */
public void processRecord(Record record) {
    int thisRow = -1;
    int thisColumn = -1;
    String thisStr = null;

    switch (record.getSid()) {
    case BoundSheetRecord.sid:
        boundSheetRecords.add(record);
        break;
    case BOFRecord.sid:
        BOFRecord br = (BOFRecord) record;
        if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
            // Create sub workbook if required
            if (workbookBuildingListener != null && stubWorkbook == null) {
                stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
            }

            // Output the worksheet name
            // Works by ordering the BSRs by the location of
            //  their BOFRecords, and then knowing that we
            //  process BOFRecords in byte offset order
            sheetIndex++;
            if (orderedBSRs == null) {
                orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords);
            }
            output.println();
            output.println(orderedBSRs[sheetIndex].getSheetname() + " [" + (sheetIndex + 1) + "]:");
        }
        break;

    case SSTRecord.sid:
        sstRecord = (SSTRecord) record;
        break;

    case BlankRecord.sid:
        BlankRecord brec = (BlankRecord) record;

        thisRow = brec.getRow();
        thisColumn = brec.getColumn();
        thisStr = "";
        break;
    case BoolErrRecord.sid:
        BoolErrRecord berec = (BoolErrRecord) record;

        thisRow = berec.getRow();
        thisColumn = berec.getColumn();
        thisStr = "";
        break;

    case FormulaRecord.sid:
        FormulaRecord frec = (FormulaRecord) record;

        thisRow = frec.getRow();
        thisColumn = frec.getColumn();

        if (outputFormulaValues) {
            if (Double.isNaN(frec.getValue())) {
                // Formula result is a string
                // This is stored in the next record
                outputNextStringRecord = true;
                nextRow = frec.getRow();
                nextColumn = frec.getColumn();
            } else {
                thisStr = formatListener.formatNumberDateCell(frec);
            }
        } else {
            thisStr = '"' + HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()) + '"';
        }
        break;
    case StringRecord.sid:
        if (outputNextStringRecord) {
            // String for formula
            StringRecord srec = (StringRecord) record;
            thisStr = srec.getString();
            thisRow = nextRow;
            thisColumn = nextColumn;
            outputNextStringRecord = false;
        }
        break;

    case LabelRecord.sid:
        LabelRecord lrec = (LabelRecord) record;

        thisRow = lrec.getRow();
        thisColumn = lrec.getColumn();
        thisStr = '"' + lrec.getValue() + '"';
        break;
    case LabelSSTRecord.sid:
        LabelSSTRecord lsrec = (LabelSSTRecord) record;

        thisRow = lsrec.getRow();
        thisColumn = lsrec.getColumn();
        if (sstRecord == null) {
            thisStr = '"' + "(No SST Record, can't identify string)" + '"';
        } else {
            thisStr = '"' + sstRecord.getString(lsrec.getSSTIndex()).toString() + '"';
        }
        break;
    case NoteRecord.sid:
        NoteRecord nrec = (NoteRecord) record;

        thisRow = nrec.getRow();
        thisColumn = nrec.getColumn();
        // TODO: Find object to match nrec.getShapeId()
        thisStr = '"' + "(TODO)" + '"';
        break;
    case NumberRecord.sid:
        NumberRecord numrec = (NumberRecord) record;

        thisRow = numrec.getRow();
        thisColumn = numrec.getColumn();

        // Format
        thisStr = formatListener.formatNumberDateCell(numrec);
        break;
    case RKRecord.sid:
        RKRecord rkrec = (RKRecord) record;

        thisRow = rkrec.getRow();
        thisColumn = rkrec.getColumn();
        thisStr = '"' + "(TODO)" + '"';
        break;
    default:
        break;
    }

    // Handle new row
    if (thisRow != -1 && thisRow != lastRowNumber) {
        lastColumnNumber = -1;
    }

    // Handle missing column
    if (record instanceof MissingCellDummyRecord) {
        MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
        thisRow = mc.getRow();
        thisColumn = mc.getColumn();
        thisStr = "";
    }

    // If we got something to print out, do so
    if (thisStr != null) {
        if (thisColumn > 0) {
            output.print(',');
        }
        output.print(thisStr);
    }

    // Update column and row count
    if (thisRow > -1)
        lastRowNumber = thisRow;
    if (thisColumn > -1)
        lastColumnNumber = thisColumn;

    // Handle end of row
    if (record instanceof LastCellOfRowDummyRecord) {
        // Print out any missing commas if needed
        if (minColumns > 0) {
            // Columns are 0 based
            if (lastColumnNumber == -1) {
                lastColumnNumber = 0;
            }
            for (int i = lastColumnNumber; i < (minColumns); i++) {
                output.print(',');
            }
        }

        // We're onto a new row
        lastColumnNumber = -1;

        // End the row
        output.println();
    }
}

From source file:com.googlecode.sqlsheet.stream.XlsSheetIterator.java

License:Apache License

/**
 * Main HSSFListener method, processes events
 *//* w w  w. j ava 2s  .  co m*/
public void processRecord(Record record) {
    int thisRow = -1;
    int thisColumn = -1;
    CellValueHolder thisCellValue = new CellValueHolder();

    switch (record.getSid()) {
    case BoundSheetRecord.sid:
        boundSheetRecords.add(record);
        break;
    case BOFRecord.sid:
        BOFRecord br = (BOFRecord) record;
        if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
            // Create sub workbook if required
            if (workbookBuildingListener != null && stubWorkbook == null) {
                stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
            }
            // Output the worksheet name
            // Works by ordering the BSRs by the location of
            //  their BOFRecords, and then knowing that we
            //  postConstruct BOFRecords in byte offset order
            sheetIndex++;
            if (orderedBSRs == null) {
                orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords);
            }
            inRequiredSheet = getSheetName().equalsIgnoreCase(orderedBSRs[sheetIndex].getSheetname())
                    || ("\"" + orderedBSRs[sheetIndex].getSheetname() + "\"").equalsIgnoreCase(getSheetName());
        }
        break;

    case SSTRecord.sid:
        sstRecord = (SSTRecord) record;
        break;

    case BlankRecord.sid:
        BlankRecord brec = (BlankRecord) record;

        thisRow = brec.getRow();
        thisColumn = brec.getColumn();
        thisCellValue.stringValue = "";
        break;
    case BoolErrRecord.sid:
        BoolErrRecord berec = (BoolErrRecord) record;
        thisRow = berec.getRow();
        thisColumn = berec.getColumn();
        thisCellValue.stringValue = "";
        break;
    case FormulaRecord.sid:
        FormulaRecord frec = (FormulaRecord) record;
        thisRow = frec.getRow();
        thisColumn = frec.getColumn();
        if (outputFormulaValues) {
            if (Double.isNaN(frec.getValue())) {
                // Formula result is a string
                // This is stored in the next record
                outputNextStringRecord = true;
                nextRow = frec.getRow();
                nextColumn = frec.getColumn();
            } else {
                thisCellValue.stringValue = formatListener.formatNumberDateCell(frec);
                thisCellValue.doubleValue = frec.getValue();
                thisCellValue.dateValue = convertDateValue(frec.getValue(), formatListener.getFormatIndex(frec),
                        formatListener.getFormatString(frec));
            }
        } else {
            thisCellValue.stringValue = HSSFFormulaParser.toFormulaString(stubWorkbook,
                    frec.getParsedExpression());
            thisCellValue.doubleValue = frec.getValue();
            thisCellValue.dateValue = convertDateValue(frec.getValue(), formatListener.getFormatIndex(frec),
                    formatListener.getFormatString(frec));
        }
        break;
    case StringRecord.sid:
        if (outputNextStringRecord) {
            // String for formula
            StringRecord srec = (StringRecord) record;
            thisCellValue.stringValue = srec.getString();
            thisRow = nextRow;
            thisColumn = nextColumn;
            outputNextStringRecord = false;
        }
        break;

    case LabelRecord.sid:
        LabelRecord lrec = (LabelRecord) record;
        thisRow = lrec.getRow();
        thisColumn = lrec.getColumn();
        thisCellValue.stringValue = lrec.getValue();
        break;
    case LabelSSTRecord.sid:
        LabelSSTRecord lsrec = (LabelSSTRecord) record;
        thisRow = lsrec.getRow();
        thisColumn = lsrec.getColumn();
        if (sstRecord == null) {
            thisCellValue.stringValue = '"' + "(No SST Record, can't identify string)" + '"';
        } else {
            thisCellValue.stringValue = sstRecord.getString(lsrec.getSSTIndex()).toString();
        }
        break;
    case NoteRecord.sid:
        NoteRecord nrec = (NoteRecord) record;
        thisRow = nrec.getRow();
        thisColumn = nrec.getColumn();
        // TODO: Find object to match nrec.getShapeId()
        thisCellValue.stringValue = '"' + "(TODO)" + '"';
        break;
    case NumberRecord.sid:
        NumberRecord numrec = (NumberRecord) record;
        thisRow = numrec.getRow();
        thisColumn = numrec.getColumn();
        // Format
        thisCellValue.stringValue = formatListener.formatNumberDateCell(numrec);
        thisCellValue.doubleValue = numrec.getValue();
        thisCellValue.dateValue = convertDateValue(numrec.getValue(), formatListener.getFormatIndex(numrec),
                formatListener.getFormatString(numrec));
        break;
    case RKRecord.sid:
        RKRecord rkrec = (RKRecord) record;
        thisRow = rkrec.getRow();
        thisColumn = rkrec.getColumn();
        thisCellValue.stringValue = '"' + "(TODO)" + '"';
        break;
    default:
        break;
    }
    // Handle new row
    if (thisRow != -1 && thisRow != lastRowNumber) {
        lastColumnNumber = -1;
    }
    // Handle missing column
    if (record instanceof MissingCellDummyRecord) {
        MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
        thisRow = mc.getRow();
        thisColumn = mc.getColumn();
        thisCellValue.stringValue = "";
    }
    // If we got something to print out, do so
    if (thisCellValue.stringValue != null) {
        //If we are on the first row - fill column names
        if (getCurrentSheetRowIndex().equals(0L) && inRequiredSheet) {
            getColumns().add(thisCellValue);
        } else if (inRequiredSheet) {
            addCurrentRowValue(thisCellValue);
        }
    }
    // Update column and row count
    if (thisRow > -1)
        lastRowNumber = thisRow;
    if (thisColumn > -1)
        lastColumnNumber = thisColumn;
    // Handle end of row
    if (record instanceof LastCellOfRowDummyRecord) {
        // We're onto a new row
        lastColumnNumber = -1;
        // End the row
        setCurrentSheetRowIndex(getCurrentSheetRowIndex() + 1);
    }
}

From source file:com.googlecode.sqlsheet.XLS2CSVmra.java

License:Apache License

/**
 * Main HSSFListener method, processes events, and outputs the
 *  CSV as the file is processed./*  w  ww  .  jav  a2 s . c om*/
 */
public void processRecord(Record record) {
    int thisRow = -1;
    int thisColumn = -1;
    String thisStr = null;

    switch (record.getSid()) {
    case BoundSheetRecord.sid:
        boundSheetRecords.add(record);
        break;
    case BOFRecord.sid:
        BOFRecord br = (BOFRecord) record;
        if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
            // Create sub workbook if required
            if (workbookBuildingListener != null && stubWorkbook == null) {
                stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
            }

            // Output the worksheet name
            // Works by ordering the BSRs by the location of
            //  their BOFRecords, and then knowing that we
            //  process BOFRecords in byte offset order
            sheetIndex++;
            if (orderedBSRs == null) {
                orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords);
            }
            currentSheetName = orderedBSRs[sheetIndex].getSheetname();
            output.println();
            output.println(orderedBSRs[sheetIndex].getSheetname() + " [" + (sheetIndex + 1) + "]:");
        }
        break;

    case SSTRecord.sid:
        sstRecord = (SSTRecord) record;
        break;

    case BlankRecord.sid:
        BlankRecord brec = (BlankRecord) record;

        thisRow = brec.getRow();
        thisColumn = brec.getColumn();
        thisStr = "";
        break;
    case BoolErrRecord.sid:
        BoolErrRecord berec = (BoolErrRecord) record;

        thisRow = berec.getRow();
        thisColumn = berec.getColumn();
        thisStr = "";
        break;

    case FormulaRecord.sid:
        FormulaRecord frec = (FormulaRecord) record;

        thisRow = frec.getRow();
        thisColumn = frec.getColumn();

        if (outputFormulaValues) {
            if (Double.isNaN(frec.getValue())) {
                // Formula result is a string
                // This is stored in the next record
                outputNextStringRecord = true;
                nextRow = frec.getRow();
                nextColumn = frec.getColumn();
            } else {
                thisStr = formatListener.formatNumberDateCell(frec);
            }
        } else {
            thisStr = '"' + HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()) + '"';
        }
        break;
    case StringRecord.sid:
        if (outputNextStringRecord) {
            // String for formula
            StringRecord srec = (StringRecord) record;
            thisStr = srec.getString();
            thisRow = nextRow;
            thisColumn = nextColumn;
            outputNextStringRecord = false;
        }
        break;

    case LabelRecord.sid:
        LabelRecord lrec = (LabelRecord) record;

        thisRow = lrec.getRow();
        thisColumn = lrec.getColumn();
        thisStr = '"' + lrec.getValue() + '"';
        break;
    case LabelSSTRecord.sid:
        LabelSSTRecord lsrec = (LabelSSTRecord) record;

        thisRow = lsrec.getRow();
        thisColumn = lsrec.getColumn();
        if (sstRecord == null) {
            thisStr = '"' + "(No SST Record, can't identify string)" + '"';
        } else {
            thisStr = '"' + sstRecord.getString(lsrec.getSSTIndex()).toString() + '"';
        }
        break;
    case NoteRecord.sid:
        NoteRecord nrec = (NoteRecord) record;

        thisRow = nrec.getRow();
        thisColumn = nrec.getColumn();
        // TODO: Find object to match nrec.getShapeId()
        thisStr = '"' + "(TODO)" + '"';
        break;
    case NumberRecord.sid:
        NumberRecord numrec = (NumberRecord) record;

        thisRow = numrec.getRow();
        thisColumn = numrec.getColumn();

        // Format
        thisStr = formatListener.formatNumberDateCell(numrec);
        break;
    case RKRecord.sid:
        RKRecord rkrec = (RKRecord) record;

        thisRow = rkrec.getRow();
        thisColumn = rkrec.getColumn();
        thisStr = '"' + "(TODO)" + '"';
        break;
    default:
        break;
    }

    // Handle new row
    if (thisRow != -1 && thisRow != lastRowNumber) {
        lastColumnNumber = -1;
    }

    // Handle missing column
    if (record instanceof MissingCellDummyRecord) {
        MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
        thisRow = mc.getRow();
        thisColumn = mc.getColumn();
        thisStr = "";
    }

    // If we got something to print out, do so
    if (thisStr != null) {
        if (thisColumn > 0) {
            output.print(',');
        }
        output.print(thisStr);
    }

    // Update column and row count
    if (thisRow > -1)
        lastRowNumber = thisRow;
    if (thisColumn > -1)
        lastColumnNumber = thisColumn;

    // Handle end of row
    if (record instanceof LastCellOfRowDummyRecord) {
        // Print out any missing commas if needed
        if (minColumns > 0) {
            // Columns are 0 based
            if (lastColumnNumber == -1) {
                lastColumnNumber = 0;
            }
            for (int i = lastColumnNumber; i < (minColumns); i++) {
                output.print(',');
            }
        }

        // We're onto a new row
        lastColumnNumber = -1;

        // End the row
        output.println("--> " + currentSheetName);
    }
}