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

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

Introduction

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

Prototype

short sid

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

Click Source Link

Usage

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

License:Open Source License

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

From source file:com.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
        }//from   ww  w. ja va2s  . c  om
        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.luna.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
        }//from   w w w.j  a  v  a 2  s. c  o m
        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()));
                try {
                    add(current);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            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);
                try {
                    add(current);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            break;
        }
        break;
    }

}

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

License:Open Source License

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

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

    // Produce a multiple kvp for the .xls

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

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

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

        break;

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

    case RowRecord.sid:

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

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

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

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

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

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

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

            value = this.formatNumberDateCell(numrec, numValue);

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

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

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

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

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

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

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

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

        }

        break;
    }
    return OK;
}

From source file: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/*from   www . ja  va2 s . c o m*/
    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:org.tonguetied.datatransfer.importing.ExcelKeywordParser.java

License:Apache License

public void processRecord(Record record) {
    if (record == null) {
        if (logger.isInfoEnabled())
            logger.info("no record to process");
    } else {//from   ww  w  .ja va2 s.  c om
        switch (record.getSid()) {
        // the BOFRecord can represent either the beginning of a sheet 
        // or the workbook
        case BOFRecord.sid:
            if (!(record instanceof BOFRecord))
                throw new ImportException("unknown excel element", null);
            final BOFRecord bof = (BOFRecord) record;
            if (bof.getType() == BOFRecord.TYPE_WORKBOOK) {
                if (logger.isInfoEnabled())
                    logger.info("Processing excel workbook");
                // assigned to the class level member
            } else if (bof.getType() == BOFRecord.TYPE_WORKSHEET) {
                if (logger.isInfoEnabled())
                    logger.info("recordsize = " + bof.getRecordSize() + ", required version = "
                            + bof.getRequiredVersion());
            }
            break;
        case BoundSheetRecord.sid:
            if (!(record instanceof BoundSheetRecord))
                throw new ImportException("unknown excel element", null);
            final BoundSheetRecord bsr = (BoundSheetRecord) record;
            // sheets named have no impact on generating query
            if (logger.isDebugEnabled())
                logger.debug("processing sheet: " + bsr.getSheetname());
            break;
        case RowRecord.sid:
            if (!(record instanceof RowRecord))
                throw new ImportException("unknown excel element", null);
            if (logger.isDebugEnabled()) {
                final RowRecord rowrec = (RowRecord) record;
                logger.debug("processing row: " + rowrec.getRowNumber());
            }
            break;
        case NumberRecord.sid:
            if (!(record instanceof NumberRecord))
                throw new ImportException("unknown excel element", null);
            final NumberRecord numrec = (NumberRecord) record;
            logger.warn("Cell [" + numrec.getRow() + "," + numrec.getColumn()
                    + "] expecting a string value not numeric: " + numrec.getValue() + ". Ignoring value");
            break;
        case SSTRecord.sid:
            if (!(record instanceof SSTRecord))
                throw new ImportException("unknown excel element", null);
            // SSTRecords store a array of unique strings used in Excel.
            sstrec = (SSTRecord) record;
            if (logger.isDebugEnabled()) {
                logger.debug("file contains " + sstrec.getNumUniqueStrings() + " unique strings");
            }
            break;
        case LabelSSTRecord.sid:
            if (!(record instanceof LabelSSTRecord))
                throw new ImportException("unknown excel element", null);
            final LabelSSTRecord lrec = (LabelSSTRecord) record;
            if (lrec.getRow() != 0) {
                if (lrec.getColumn() == 0) {
                    evaluateRowType(lrec);
                } else {
                    final String cellValue = sstrec.getString(lrec.getSSTIndex()).getString();
                    if (lrec.getColumn() == 1) {
                        switch (rowType) {
                        case keyword:
                            // there were no translations for the previous keyword, so add to keywords
                            if (keyword != null && keyword.getTranslations().isEmpty())
                                keywords.put(keyword.getKeyword(), keyword);
                            loadKeyword(cellValue);
                            break;
                        case context:
                            if (StringUtils.isNotBlank(cellValue))
                                keyword.setContext(cellValue);
                            break;
                        default:
                            break;
                        }
                    } else if (lrec.getColumn() == 2) {
                        baseTranslation = new Translation();
                        baseTranslation.setKeyword(keyword);
                        final LanguageCode code = ImporterUtils.evaluateLanguageCode(cellValue, errorCodes);
                        Language language = null;
                        if (code != null) {
                            language = keywordService.getLanguage(code);
                            if (language == null)
                                errorCodes.add(ImportErrorCode.unknownLanguage);
                        }
                        baseTranslation.setLanguage(language);
                    } else if (lrec.getColumn() == 4) {
                        final CountryCode code = ImporterUtils.evaluateCountryCode(cellValue, errorCodes);
                        Country country = null;
                        if (code != null) {
                            country = keywordService.getCountry(code);
                            if (country == null)
                                errorCodes.add(ImportErrorCode.unknownCountry);
                        }
                        baseTranslation.setCountry(country);
                    } else if (lrec.getColumn() == 6) {
                        final Bundle bundle = keywordService.getBundleByName(cellValue);
                        if (bundle == null)
                            errorCodes.add(ImportErrorCode.unknownBundle);
                        baseTranslation.setBundle(bundle);
                    } else if (lrec.getColumn() == 7) {
                        final TranslationState state = ImporterUtils.evaluateTranslationState(cellValue,
                                errorCodes);
                        baseTranslation.setState(state);
                    } else if (lrec.getColumn() == 8) {
                        baseTranslation.setValue(cellValue);
                        keyword.addTranslation(baseTranslation);
                        keywords.put(keyword.getKeyword(), keyword);
                    }
                }

            }
            break;
        default:
            break;
        }
    }
}

From source file:org.tonguetied.datatransfer.importing.ExcelLanguageCentricParser.java

License:Apache License

/**
 * This method listens for incoming records and handles them as required.
 * /*from   ww w  .  j a v  a2s . c o m*/
 * @param record The record that was found while reading.
 */
public void processRecord(Record record) {
    if (record == null) {
        if (logger.isInfoEnabled())
            logger.info("no record to process");
    } else {
        switch (record.getSid()) {
        // the BOFRecord can represent either the beginning of a sheet 
        // or the workbook
        case BOFRecord.sid:
            if (!(record instanceof BOFRecord))
                throw new ImportException("unknown excel element", null);
            final BOFRecord bof = (BOFRecord) record;
            if (bof.getType() == BOFRecord.TYPE_WORKBOOK) {
                if (logger.isInfoEnabled())
                    logger.info("Processing excel workbook");
                // assigned to the class level member
            } else if (bof.getType() == BOFRecord.TYPE_WORKSHEET) {
                if (logger.isInfoEnabled())
                    logger.info("recordsize = " + bof.getRecordSize() + ", required version = "
                            + bof.getRequiredVersion());
            }
            break;
        case BoundSheetRecord.sid:
            if (!(record instanceof BoundSheetRecord))
                throw new ImportException("unknown excel element", null);
            final BoundSheetRecord bsr = (BoundSheetRecord) record;
            // sheets named have no impact on generating query
            if (logger.isDebugEnabled())
                logger.debug("processing sheet: " + bsr.getSheetname());
            break;
        case RowRecord.sid:
            if (!(record instanceof RowRecord))
                throw new ImportException("unknown excel element", null);
            final RowRecord rowrec = (RowRecord) record;
            lastColOfRow = rowrec.getLastCol();
            //                    if (rowrec.getRowNumber() > 0) {
            //                        if (logger.isDebugEnabled())
            //                            logger.debug("creating new keyword instance");
            //                        keyword = new Keyword();
            //                    }
            break;
        case NumberRecord.sid:
            if (!(record instanceof NumberRecord))
                throw new ImportException("unknown excel element", null);
            final NumberRecord numrec = (NumberRecord) record;
            logger.warn("Cell [" + numrec.getRow() + "," + numrec.getColumn()
                    + "] expecting a string value not numeric: " + numrec.getValue() + ". Ignoring value");
            break;
        case SSTRecord.sid:
            if (!(record instanceof SSTRecord))
                throw new ImportException("unknown excel element", null);
            // SSTRecords store a array of unique strings used in Excel.
            sstrec = (SSTRecord) record;
            if (logger.isDebugEnabled()) {
                logger.debug("file contains " + sstrec.getNumUniqueStrings() + " unique strings");
            }
            break;
        case LabelSSTRecord.sid:
            if (!(record instanceof LabelSSTRecord))
                throw new ImportException("unknown excel element", null);
            final LabelSSTRecord lrec = (LabelSSTRecord) record;
            if (lrec.getRow() == 0) {
                processHeader(lrec);
            } else {
                if (lrec.getColumn() == 0) {
                    String keywordStr = sstrec.getString(lrec.getSSTIndex()).getString();
                    loadKeyword(keywordStr);
                } else if (lrec.getColumn() == 1) {
                    keyword.setContext(sstrec.getString(lrec.getSSTIndex()).getString());
                } else if (lrec.getColumn() == 2) {
                    baseTranslation = new Translation();
                    baseTranslation.setKeyword(keyword);
                    String name = sstrec.getString(lrec.getSSTIndex()).getString();
                    Bundle bundle = keywordService.getBundleByName(name);
                    baseTranslation.setBundle(bundle);
                } else if (lrec.getColumn() == 3) {
                    String colHeader = sstrec.getString(lrec.getSSTIndex()).getString();
                    String[] headers = colHeader.split(":");
                    CountryCode code = CountryCode.valueOf(headers[0]);
                    Country country = keywordService.getCountry(code);
                    baseTranslation.setCountry(country);
                } else {
                    Language language = languages.get(lrec.getColumn() - 4);
                    String value = sstrec.getString(lrec.getSSTIndex()).getString();
                    Translation translation = baseTranslation.deepClone();
                    if (language.getCode() == LanguageCode.zht) {
                        language = keywordService.getLanguage(LanguageCode.zh);
                        Country country = keywordService.getCountry(CountryCode.TW);
                        translation.setCountry(country);
                    }
                    translation.setLanguage(language);
                    translation.setState(TranslationState.UNVERIFIED);
                    translation.setValue(value);
                    keyword.addTranslation(translation);
                    //                        System.out.println("String cell found with value "
                    //                                + sstrec.getString(lrec.getSSTIndex()));
                }

                if (isLastColumn(lrec.getColumn())) {
                    keywords.put(keyword.getKeyword(), keyword);
                }
            }
            break;
        default:
            break;
        }
    }
}

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

License:Apache License

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

From source file:util.XLSReader.java

License:Open Source License

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

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

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

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

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

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

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

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

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

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

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

        break;
    }
}