Example usage for org.apache.poi.hssf.model InternalSheet getRecords

List of usage examples for org.apache.poi.hssf.model InternalSheet getRecords

Introduction

In this page you can find the example usage for org.apache.poi.hssf.model InternalSheet getRecords.

Prototype

public List<RecordBase> getRecords() 

Source Link

Usage

From source file:com.vaadin.addon.spreadsheet.CellValueManager.java

License:Open Source License

/**
 * Removes hyperlink from the given cell
 *
 * @param cell/*from   w  w w . j a  v a 2s .c om*/
 *            Target cell
 * @param sheet
 *            Sheet the target cell belongs to
 */
protected void removeHyperlink(Cell cell, Sheet sheet) {
    try {
        if (sheet instanceof XSSFSheet) {
            Field f;
            f = XSSFSheet.class.getDeclaredField("hyperlinks");
            f.setAccessible(true);
            @SuppressWarnings("unchecked")
            List<XSSFHyperlink> hyperlinks = (List<XSSFHyperlink>) f.get(sheet);
            hyperlinks.remove(cell.getHyperlink());
            f.setAccessible(false);
        } else if (sheet instanceof HSSFSheet && cell instanceof HSSFCell) {
            HSSFHyperlink link = (HSSFHyperlink) cell.getHyperlink();
            Field sheetField = HSSFSheet.class.getDeclaredField("_sheet");
            sheetField.setAccessible(true);
            InternalSheet internalsheet = (InternalSheet) sheetField.get(sheet);
            List<RecordBase> records = internalsheet.getRecords();
            Field recordField = HSSFHyperlink.class.getDeclaredField("record");
            recordField.setAccessible(true);
            records.remove(recordField.get(link));
            sheetField.setAccessible(false);
            recordField.setAccessible(false);
        }
    } catch (SecurityException e) {
        LOGGER.log(Level.FINEST, e.getMessage(), e);
    } catch (NoSuchFieldException e) {
        LOGGER.log(Level.FINEST, e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        LOGGER.log(Level.FINEST, e.getMessage(), e);
    } catch (IllegalAccessException e) {
        LOGGER.log(Level.FINEST, e.getMessage(), e);
    }
}