List of usage examples for org.apache.poi.xssf.streaming SXSSFSheet getRow
@Override public SXSSFRow getRow(int rownum)
From source file:com.plugin.excel.util.ExcelUtil.java
License:Apache License
/** * @param newSheet//from w w w .j a v a2s .c o 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)); } }
From source file:tools.xor.service.AggregateManager.java
License:Apache License
private void writeColumnNames(SXSSFSheet sh, Map<String, Integer> propertyColIndex) { Row row = sh.getRow(0); if (row != null) { // Column names have already been populated return;// www .j a v a2 s. c o m } row = sh.createRow(0); for (Map.Entry<String, Integer> entry : propertyColIndex.entrySet()) { Cell cell = row.createCell(entry.getValue()); cell.setCellValue(entry.getKey()); sh.autoSizeColumn(entry.getValue()); } }