Example usage for org.apache.poi.xssf.model StylesTable getCTStylesheet

List of usage examples for org.apache.poi.xssf.model StylesTable getCTStylesheet

Introduction

In this page you can find the example usage for org.apache.poi.xssf.model StylesTable getCTStylesheet.

Prototype

@Internal
public CTStylesheet getCTStylesheet() 

Source Link

Document

For unit testing only!

Usage

From source file:com.miraisolutions.xlconnect.XCellStyle.java

License:Open Source License

/**
 * Used for querying user-named cell styles (style xf only).
 *
 * @param workbook/*from   w w w  .  j  av  a 2 s .  c  om*/
 * @param name
 * @return          XCellStyle with corresponding (named) style xf
 */
public static XCellStyle get(XSSFWorkbook workbook, String name) {
    StylesTable stylesSource = workbook.getStylesSource();
    CTCellStyles ctCellStyles = stylesSource.getCTStylesheet().getCellStyles();

    if (ctCellStyles != null) {
        for (int i = 0; i < ctCellStyles.getCount(); i++) {
            CTCellStyle ctCellStyle = ctCellStyles.getCellStyleArray(i);
            if (ctCellStyle.getName().equals(name)) {
                int styleXfId = (int) ctCellStyle.getXfId();

                return new XCellStyle(workbook, -1, styleXfId);
            }
        }
    }

    return null;
}