Example usage for org.apache.poi.xssf.streaming SXSSFSheet getColumnWidth

List of usage examples for org.apache.poi.xssf.streaming SXSSFSheet getColumnWidth

Introduction

In this page you can find the example usage for org.apache.poi.xssf.streaming SXSSFSheet getColumnWidth.

Prototype

@Override
public int getColumnWidth(int columnIndex) 

Source Link

Document

get the width (in units of 1/256th of a character width )

Usage

From source file:com.plugin.excel.util.ExcelUtil.java

License:Apache License

/**
 * @param newSheet//from w w  w  .  jav  a2 s  .  co m
 *            the sheet to create from the copy.
 * @param sheet
 *            the sheet to copy.
 * @param copyStyle
 *            true copy the style.
 */
public static void copySheets(SXSSFSheet newSheet, SXSSFSheet sheet, boolean copyStyle) {
    int maxColumnNum = 0;
    Map<Integer, CellStyle> styleMap = (copyStyle) ? new HashMap<Integer, CellStyle>() : null;
    for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
        Row srcRow = sheet.getRow(i);
        Row destRow = newSheet.createRow(i);
        if (srcRow != null) {
            ExcelUtil.copyRow(sheet, newSheet, srcRow, destRow, styleMap);
            if (srcRow.getLastCellNum() > maxColumnNum) {
                maxColumnNum = srcRow.getLastCellNum();
            }
        }
    }
    for (int i = 0; i <= maxColumnNum; i++) {
        newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
    }
}