Example usage for org.apache.poi.hssf.record TextObjectRecord getStr

List of usage examples for org.apache.poi.hssf.record TextObjectRecord getStr

Introduction

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

Prototype

public HSSFRichTextString getStr() 

Source Link

Usage

From source file:org.opencrx.kernel.text.ExcelToText.java

License:BSD License

/**
 * This method listens for incoming records and handles them as required.
 * /*from   w w  w  . j  ava2  s.  com*/
 * @param record
 *        The record that was found while reading.
 */
public void processRecord(Record record) {
    int curentRow = 0;
    if (this.sstrec != null) {
        try {
            if (record instanceof CellValueRecordInterface) {
                if (record instanceof LabelSSTRecord) {
                    LabelSSTRecord bof2 = (LabelSSTRecord) record;
                    int rowNum = ((CellValueRecordInterface) record).getRow();
                    if (curentRow < rowNum) {
                        this.text.append(" ");
                        curentRow = rowNum;
                    }
                    try {
                        String value = sstrec.getString(bof2.getSSTIndex()).toString();
                        this.text.append(value + " ");
                    } catch (Exception e) {
                    }
                }
                if (record instanceof NumberRecord) {
                    NumberRecord bof2 = (NumberRecord) record;
                    int rowNum = ((CellValueRecordInterface) record).getRow();
                    if (curentRow < rowNum) {
                        this.text.append(" ");
                        curentRow = rowNum;
                    }
                    String value = (new Double(bof2.getValue())).toString();
                    this.text.append(value + " ");
                }
            }
        } catch (Exception ex) {
        } catch (NoSuchMethodError e) {
        }
    }
    switch (record.getSid()) {
    case BoundSheetRecord.sid:
        BoundSheetRecord bsr = (BoundSheetRecord) record;
        this.text.append(bsr.getSheetname() + " ");
        break;
    case SSTRecord.sid:
        this.sstrec = (SSTRecord) record;
        break;
    case DSFRecord.sid:
        break;

    case TextObjectRecord.sid:
        TextObjectRecord textObjectRecord = (TextObjectRecord) record;
        HSSFRichTextString q = textObjectRecord.getStr();
        String st = q.getString();
        if (st != null && !"".equals(st)) {
            int ind = this.text.indexOf(st);
            if (ind == -1) {
                this.text.append(st + " ");
            }
        }
        break;

    case StringRecord.sid:
        StringRecord selectionRecord = (StringRecord) record;
        String str = selectionRecord.getString();
        if (str != null && !"".equals(str)) {
            int ind = this.text.indexOf(str);
            if (ind == -1) {
                this.text.append(str + " ");
            }
        }
        break;
    }
}