Example usage for org.apache.poi.ss.usermodel Sheet getCellComments

List of usage examples for org.apache.poi.ss.usermodel Sheet getCellComments

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Sheet getCellComments.

Prototype

Map<CellAddress, ? extends Comment> getCellComments();

Source Link

Document

Returns all cell comments on this sheet.

Usage

From source file:jp.qpg.ExcelTo.java

License:Apache License

/**
 * excel to text//ww w.  j a  v a  2s. co  m
 * 
 * @param book excel workbook
 * @param out output to text
 */
public static void text(Workbook book, OutputStream out) {
    Objects.requireNonNull(book);
    Objects.requireNonNull(out);
    try (PrintStream printer = Try.to(() -> new PrintStream(out, true, System.getProperty("file.encoding")))
            .get()) {
        for (int i = 0, end = book.getNumberOfSheets(); i < end; i++) {
            Sheet sheet = book.getSheetAt(i);
            int rowCount = sheet.getPhysicalNumberOfRows();
            if (rowCount <= 0) {
                logger.info(sheet.getSheetName() + ": empty");
                continue; /* skip blank sheet */
            }
            logger.info(sheet.getSheetName() + ": " + rowCount + " rows");
            printer.println("sheet name: " + sheet.getSheetName());
            printer.println("max row index: " + sheet.getLastRowNum());
            printer.println("max column index: "
                    + Tool.stream(sheet.rowIterator(), rowCount).mapToInt(Row::getLastCellNum).max().orElse(0));
            eachCell(sheet, (cell, range) -> Tool.cellValue(cell).ifPresent(value -> printer.println(
                    '[' + (range == null ? new CellReference(cell).formatAsString() : range.formatAsString())
                            + "] " + value)));
            sheet.getCellComments().entrySet().forEach(entry -> {
                printer.println("[comment " + entry.getKey() + "] " + entry.getValue().getString());
            });
            eachShape(sheet, shapeText(text -> printer.println("[shape text] " + text)));
            printer.println("--------");
        }
    }
}