Example usage for org.apache.poi.hssf.record NoteRecord sid

List of usage examples for org.apache.poi.hssf.record NoteRecord sid

Introduction

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

Prototype

short sid

To view the source code for org.apache.poi.hssf.record NoteRecord sid.

Click Source Link

Usage

From source file:XLS2CSVmra.java

License:Apache License

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

    switch (record.getSid()) {
    case SSTRecord.sid:
        sstRecord = (SSTRecord) record;
        break;
    case FormatRecord.sid:
        FormatRecord fr = (FormatRecord) record;
        customFormatRecords.put(new Integer(fr.getIndexCode()), fr);
        break;
    case ExtendedFormatRecord.sid:
        ExtendedFormatRecord xr = (ExtendedFormatRecord) record;
        xfRecords.add(xr);
        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) {
            thisStr = '"' + formatNumberDateCell(frec, frec.getValue()) + '"';
        } else {
            // TODO: Output the formula string
            thisStr = '"' + frec.toString().replaceAll("\"", "\"\"") + '"';
        }
        break;
    case LabelRecord.sid:
        LabelRecord lrec = (LabelRecord) record;

        thisRow = lrec.getRow();
        thisColumn = lrec.getColumn();
        thisStr = '"' + lrec.getValue().replaceAll("\"", "\"\"") + '"';
        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().replaceAll("\"", "\"\"") + '"';
        }
        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 = '"' + formatNumberDateCell(numrec, numrec.getValue()) + '"';
        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;

    //set the minColumns based on the first row (headers)
    if (thisRow == 0)
        minColumns = 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:XLS2CSV.java

License:Apache License

/**
 * Main HSSFListener method, processes events, and outputs the CSV as the
 * file is processed.//from w w w  . ja  v a 2s  . com
 */
@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: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   w  ww .ja  v  a  2  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;
        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.//from www  . j av a 2  s  .  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  ww  w  .ja v  a  2s  .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);
            }
            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.epac.java.converter.ms2text.XLS2CSVmra.java

License:Apache License

/**
 * Main HSSFListener method, processes events, and outputs the
 *  CSV as the file is processed.//from   w ww . ja  v a  2 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);
            }
            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
 *///from  w  ww.  j a  va 2 s  .  c  o  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 w  w  . j  a va2s. 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);
            }
            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);
    }
}

From source file:com.pnf.plugin.ole.parser.xls.BiffRecord.java

License:Apache License

private static Class<? extends Record> getClass(int sid) {
    switch (sid) {
    case AreaFormatRecord.sid:
        return AreaFormatRecord.class;
    case AreaRecord.sid:
        return AreaRecord.class;
    case ArrayRecord.sid:
        return ArrayRecord.class;
    case AxisLineFormatRecord.sid:
        return AxisLineFormatRecord.class;
    case AxisOptionsRecord.sid:
        return AxisOptionsRecord.class;
    case AxisParentRecord.sid:
        return AxisParentRecord.class;
    case AxisRecord.sid:
        return AxisRecord.class;
    case AxisUsedRecord.sid:
        return AxisUsedRecord.class;
    case AutoFilterInfoRecord.sid:
        return AutoFilterInfoRecord.class;
    case BOFRecord.sid:
        return BOFRecord.class;
    case BackupRecord.sid:
        return BackupRecord.class;
    case BarRecord.sid:
        return BarRecord.class;
    case BeginRecord.sid:
        return BeginRecord.class;
    case BlankRecord.sid:
        return BlankRecord.class;
    case BookBoolRecord.sid:
        return BookBoolRecord.class;
    case BoolErrRecord.sid:
        return BoolErrRecord.class;
    case BottomMarginRecord.sid:
        return BottomMarginRecord.class;
    case BoundSheetRecord.sid:
        return BoundSheetRecord.class;
    case CFHeaderRecord.sid:
        return CFHeaderRecord.class;
    case CFRuleRecord.sid:
        return CFRuleRecord.class;
    case CalcCountRecord.sid:
        return CalcCountRecord.class;
    case CalcModeRecord.sid:
        return CalcModeRecord.class;
    case CategorySeriesAxisRecord.sid:
        return CategorySeriesAxisRecord.class;
    case ChartFormatRecord.sid:
        return ChartFormatRecord.class;
    case ChartRecord.sid:
        return ChartRecord.class;
    case CodepageRecord.sid:
        return CodepageRecord.class;
    case ColumnInfoRecord.sid:
        return ColumnInfoRecord.class;
    case ContinueRecord.sid:
        return ContinueRecord.class;
    case CountryRecord.sid:
        return CountryRecord.class;
    case DBCellRecord.sid:
        return DBCellRecord.class;
    case DSFRecord.sid:
        return DSFRecord.class;
    case DatRecord.sid:
        return DatRecord.class;
    case DataFormatRecord.sid:
        return DataFormatRecord.class;
    case DateWindow1904Record.sid:
        return DateWindow1904Record.class;
    case DConRefRecord.sid:
        return DConRefRecord.class;
    case DefaultColWidthRecord.sid:
        return DefaultColWidthRecord.class;
    case DefaultDataLabelTextPropertiesRecord.sid:
        return DefaultDataLabelTextPropertiesRecord.class;
    case DefaultRowHeightRecord.sid:
        return DefaultRowHeightRecord.class;
    case DeltaRecord.sid:
        return DeltaRecord.class;
    case DimensionsRecord.sid:
        return DimensionsRecord.class;
    case DrawingGroupRecord.sid:
        return DrawingGroupRecord.class;
    case DrawingRecordForBiffViewer.sid:
        return DrawingRecordForBiffViewer.class;
    case DrawingSelectionRecord.sid:
        return DrawingSelectionRecord.class;
    case DVRecord.sid:
        return DVRecord.class;
    case DVALRecord.sid:
        return DVALRecord.class;
    case EOFRecord.sid:
        return EOFRecord.class;
    case EndRecord.sid:
        return EndRecord.class;
    case ExtSSTRecord.sid:
        return ExtSSTRecord.class;
    case ExtendedFormatRecord.sid:
        return ExtendedFormatRecord.class;
    case ExternSheetRecord.sid:
        return ExternSheetRecord.class;
    case ExternalNameRecord.sid:
        return ExternalNameRecord.class;
    case FeatRecord.sid:
        return FeatRecord.class;
    case FeatHdrRecord.sid:
        return FeatHdrRecord.class;
    case FilePassRecord.sid:
        return FilePassRecord.class;
    case FileSharingRecord.sid:
        return FileSharingRecord.class;
    case FnGroupCountRecord.sid:
        return FnGroupCountRecord.class;
    case FontBasisRecord.sid:
        return FontBasisRecord.class;
    case FontIndexRecord.sid:
        return FontIndexRecord.class;
    case FontRecord.sid:
        return FontRecord.class;
    case FooterRecord.sid:
        return FooterRecord.class;
    case FormatRecord.sid:
        return FormatRecord.class;
    case FormulaRecord.sid:
        return FormulaRecord.class;
    case FrameRecord.sid:
        return FrameRecord.class;
    case GridsetRecord.sid:
        return GridsetRecord.class;
    case GutsRecord.sid:
        return GutsRecord.class;
    case HCenterRecord.sid:
        return HCenterRecord.class;
    case HeaderRecord.sid:
        return HeaderRecord.class;
    case HideObjRecord.sid:
        return HideObjRecord.class;
    case HorizontalPageBreakRecord.sid:
        return HorizontalPageBreakRecord.class;
    case HyperlinkRecord.sid:
        return HyperlinkRecord.class;
    case IndexRecord.sid:
        return IndexRecord.class;
    case InterfaceEndRecord.sid:
        return InterfaceEndRecord.class;
    case InterfaceHdrRecord.sid:
        return InterfaceHdrRecord.class;
    case IterationRecord.sid:
        return IterationRecord.class;
    case LabelRecord.sid:
        return LabelRecord.class;
    case LabelSSTRecord.sid:
        return LabelSSTRecord.class;
    case LeftMarginRecord.sid:
        return LeftMarginRecord.class;
    case LegendRecord.sid:
        return LegendRecord.class;
    case LineFormatRecord.sid:
        return LineFormatRecord.class;
    case LinkedDataRecord.sid:
        return LinkedDataRecord.class;
    case MMSRecord.sid:
        return MMSRecord.class;
    case MergeCellsRecord.sid:
        return MergeCellsRecord.class;
    case MulBlankRecord.sid:
        return MulBlankRecord.class;
    case MulRKRecord.sid:
        return MulRKRecord.class;
    case NameRecord.sid:
        return NameRecord.class;
    case NameCommentRecord.sid:
        return NameCommentRecord.class;
    case NoteRecord.sid:
        return NoteRecord.class;
    case NumberRecord.sid:
        return NumberRecord.class;
    case ObjRecord.sid:
        return ObjRecord.class;
    case ObjectLinkRecord.sid:
        return ObjectLinkRecord.class;
    case PaletteRecord.sid:
        return PaletteRecord.class;
    case PaneRecord.sid:
        return PaneRecord.class;
    case PasswordRecord.sid:
        return PasswordRecord.class;
    case PasswordRev4Record.sid:
        return PasswordRev4Record.class;
    case PlotAreaRecord.sid:
        return PlotAreaRecord.class;
    case PlotGrowthRecord.sid:
        return PlotGrowthRecord.class;
    case PrecisionRecord.sid:
        return PrecisionRecord.class;
    case PrintGridlinesRecord.sid:
        return PrintGridlinesRecord.class;
    case PrintHeadersRecord.sid:
        return PrintHeadersRecord.class;
    case PrintSetupRecord.sid:
        return PrintSetupRecord.class;
    case ProtectRecord.sid:
        return ProtectRecord.class;
    case ProtectionRev4Record.sid:
        return ProtectionRev4Record.class;
    case RKRecord.sid:
        return RKRecord.class;
    case RecalcIdRecord.sid:
        return RecalcIdRecord.class;
    case RefModeRecord.sid:
        return RefModeRecord.class;
    case RefreshAllRecord.sid:
        return RefreshAllRecord.class;
    case RightMarginRecord.sid:
        return RightMarginRecord.class;
    case RowRecord.sid:
        return RowRecord.class;
    case SCLRecord.sid:
        return SCLRecord.class;
    case SSTRecord.sid:
        return SSTRecord.class;
    case SaveRecalcRecord.sid:
        return SaveRecalcRecord.class;
    case SelectionRecord.sid:
        return SelectionRecord.class;
    case SeriesIndexRecord.sid:
        return SeriesIndexRecord.class;
    case SeriesListRecord.sid:
        return SeriesListRecord.class;
    case SeriesRecord.sid:
        return SeriesRecord.class;
    case SeriesTextRecord.sid:
        return SeriesTextRecord.class;
    case SeriesToChartGroupRecord.sid:
        return SeriesToChartGroupRecord.class;
    case SharedFormulaRecord.sid:
        return SharedFormulaRecord.class;
    case SheetPropertiesRecord.sid:
        return SheetPropertiesRecord.class;
    case StringRecord.sid:
        return StringRecord.class;
    case StyleRecord.sid:
        return StyleRecord.class;
    case SupBookRecord.sid:
        return SupBookRecord.class;
    case TabIdRecord.sid:
        return TabIdRecord.class;
    case TableStylesRecord.sid:
        return TableStylesRecord.class;
    case TableRecord.sid:
        return TableRecord.class;
    case TextObjectRecord.sid:
        return TextObjectRecord.class;
    case TextRecord.sid:
        return TextRecord.class;
    case TickRecord.sid:
        return TickRecord.class;
    case TopMarginRecord.sid:
        return TopMarginRecord.class;
    case UncalcedRecord.sid:
        return UncalcedRecord.class;
    case UnitsRecord.sid:
        return UnitsRecord.class;
    case UseSelFSRecord.sid:
        return UseSelFSRecord.class;
    case VCenterRecord.sid:
        return VCenterRecord.class;
    case ValueRangeRecord.sid:
        return ValueRangeRecord.class;
    case VerticalPageBreakRecord.sid:
        return VerticalPageBreakRecord.class;
    case WSBoolRecord.sid:
        return WSBoolRecord.class;
    case WindowOneRecord.sid:
        return WindowOneRecord.class;
    case WindowProtectRecord.sid:
        return WindowProtectRecord.class;
    case WindowTwoRecord.sid:
        return WindowTwoRecord.class;
    case WriteAccessRecord.sid:
        return WriteAccessRecord.class;
    case WriteProtectRecord.sid:
        return WriteProtectRecord.class;

    // chart//www .j  a v a  2  s .  c  om
    case CatLabRecord.sid:
        return CatLabRecord.class;
    case ChartEndBlockRecord.sid:
        return ChartEndBlockRecord.class;
    case ChartEndObjectRecord.sid:
        return ChartEndObjectRecord.class;
    case ChartFRTInfoRecord.sid:
        return ChartFRTInfoRecord.class;
    case ChartStartBlockRecord.sid:
        return ChartStartBlockRecord.class;
    case ChartStartObjectRecord.sid:
        return ChartStartObjectRecord.class;

    // pivot table
    case StreamIDRecord.sid:
        return StreamIDRecord.class;
    case ViewSourceRecord.sid:
        return ViewSourceRecord.class;
    case PageItemRecord.sid:
        return PageItemRecord.class;
    case ViewDefinitionRecord.sid:
        return ViewDefinitionRecord.class;
    case ViewFieldsRecord.sid:
        return ViewFieldsRecord.class;
    case DataItemRecord.sid:
        return DataItemRecord.class;
    case ExtendedPivotTableViewFieldsRecord.sid:
        return ExtendedPivotTableViewFieldsRecord.class;
    default:
        break;
    }

    return UnknownRecord.class;
}

From source file:com.sonicle.webtop.core.io.input.XlsPartsProcessorOLD.java

License:Open Source License

@Override
public void processRecord(Record record) {
    cellValue = null;/*w ww . j  av  a 2  s  .  c  o m*/

    switch (record.getSid()) {
    case BoundSheetRecord.sid:
        BoundSheetRecord bsr = (BoundSheetRecord) record;
        if (!sheetFound) {
            if (StringUtils.equals(bsr.getSheetname(), sheetName)) {
                sheetFound = true;
                columnNames = new LinkedHashMap<>();
                columnIndexes = new HashMap<>();
            }
        } else {
            close();
        }
        break;

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

    case BlankRecord.sid:
        BlankRecord br = (BlankRecord) record;
        row = br.getRow();
        col = br.getColumn();
        cellValue = "";
        break;

    case BoolErrRecord.sid:
        BoolErrRecord ber = (BoolErrRecord) record;
        row = ber.getRow();
        col = ber.getColumn();
        cellValue = "";
        break;

    case FormulaRecord.sid:
        FormulaRecord fr = (FormulaRecord) record;
        row = fr.getRow();
        col = fr.getColumn();
        if (Double.isNaN(fr.getValue())) {
            // Formula result is a string that is stored in the next record!
            findNextStringRecord = true;
            nextRow = fr.getRow();
            nextCol = fr.getColumn();
            cellValue = null;
        } else {
            cellValue = formatTrackingListener.formatNumberDateCell(fr);
        }
        break;

    case StringRecord.sid:
        if (findNextStringRecord) {
            // String for formula 
            StringRecord sr = (StringRecord) record;
            cellValue = sr.getString();
            row = nextRow;
            col = nextCol;
            // Resets markers...
            findNextStringRecord = false;
            nextRow = -1;
            nextCol = -1;
        }
        break;

    case LabelRecord.sid:
        LabelRecord lr = (LabelRecord) record;
        row = lr.getRow();
        col = lr.getColumn();
        cellValue = lr.getValue();
        break;

    case LabelSSTRecord.sid:
        LabelSSTRecord lsstr = (LabelSSTRecord) record;
        row = lsstr.getRow();
        col = lsstr.getColumn();
        if (sstRecord == null) {
            cellValue = "#ERROR(undefined string)";
        } else {
            cellValue = sstRecord.getString(lsstr.getSSTIndex()).toString();
        }
        break;

    case NoteRecord.sid:
        NoteRecord nr = (NoteRecord) record;
        row = nr.getRow();
        col = nr.getColumn();
        // TODO: Find object to match nrec.getShapeId() 
        cellValue = "#ERROR(TODO)";
        break;

    case NumberRecord.sid:
        NumberRecord rn = (NumberRecord) record;
        row = rn.getRow();
        col = rn.getColumn();
        cellValue = formatTrackingListener.formatNumberDateCell(rn);
        break;

    case RKRecord.sid:
        RKRecord rkr = (RKRecord) record;
        row = rkr.getRow();
        col = rkr.getColumn();
        cellValue = "#ERROR(TODO)";
        break;

    default:
        cellValue = null;
    }

    if (row == headersRow) {
        String cellReference = CellReference.convertNumToColString(col);
        String name = (headersRow == firstDataRow) ? cellReference
                : StringUtils.defaultIfBlank(cellValue, cellReference);
        columnNames.put(name.toLowerCase(), name);
        columnIndexes.put(name, col);
    }
}