Search in sources :

Example 41 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project financial by greatkendy123.

the class ExportTGExcel method setWaizhaiData.

/**
 * 设置外债的Excel数据
 * @time 2018年3月20日
 * @param workbook
 * @param excelModel
 */
private void setWaizhaiData(HSSFWorkbook workbook, TGExcelModel excelModel) {
    HSSFSheet sheet = workbook.createSheet(excelModel.getSheetName());
    Map<String, List<Object[]>> waizhaiMap = excelModel.getWaizhaiMap();
    // 获取列头样式对象
    HSSFCellStyle columnTopStyle = this.getColumnTopStyle(workbook);
    // 单元格样式对象
    HSSFCellStyle style = this.getStyle(workbook);
    // 第几个表
    int index = 1;
    for (Map.Entry<String, List<Object[]>> entry : waizhaiMap.entrySet()) {
        HSSFRow r = sheet.getRow(1);
        if (r == null)
            r = sheet.createRow(1);
        int start = (index - 1) * 3;
        int end = (index - 1) * 3 + 1;
        // 标题
        String teamString = entry.getKey();
        HSSFCell cellName = r.createCell((index - 1) * 3);
        cellName.setCellType(HSSFCell.CELL_TYPE_STRING);
        HSSFRichTextString text = new HSSFRichTextString(teamString.split("#")[0]);
        cellName.setCellValue(text);
        cellName.setCellStyle(columnTopStyle);
        cellName = r.createCell((index - 1) * 3 + 1);
        cellName.setCellType(HSSFCell.CELL_TYPE_STRING);
        text = new HSSFRichTextString(teamString.split("#")[1]);
        cellName.setCellValue(text);
        cellName.setCellStyle(columnTopStyle);
        // 外债明细
        int i = 1;
        List<Object[]> waizhaiList = entry.getValue();
        for (Object[] obj : waizhaiList) {
            HSSFRow row = sheet.getRow(i + 1);
            if (row == null) {
                row = sheet.createRow(i + 1);
                row.setHeight((short) 400);
            }
            HSSFCell type = row.createCell(start, HSSFCell.CELL_TYPE_STRING);
            type.setCellStyle(style);
            type.setCellValue(obj[0].toString());
            HSSFCell sum = row.createCell(start + 1, HSSFCell.CELL_TYPE_STRING);
            sum.setCellStyle(style);
            sum.setCellValue(obj[1].toString());
            sheet.setColumnWidth((i - 1) * 3, 3500);
            sheet.setColumnWidth((i - 1) * 3 + 1, 3500);
            i += 1;
        }
        index += 1;
    }
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 42 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project bitcampSCOpen2017 by ryuyj.

the class MemberListXlsView method createColumnLabel.

private void createColumnLabel(HSSFSheet sheet) {
    HSSFRow firstRow = sheet.createRow(0);
    HSSFCell cell = firstRow.createCell(0);
    cell.setCellValue("회원번호");
    cell = firstRow.createCell(1);
    cell.setCellValue("이메일");
    cell = firstRow.createCell(2);
    cell.setCellValue("이름");
    cell = firstRow.createCell(3);
    cell.setCellValue("가입일");
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow)

Example 43 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project bitcampSCOpen2017 by ryuyj.

the class MemberListXlsView method createColumnLabel.

private void createColumnLabel(HSSFSheet sheet) {
    HSSFRow firstRow = sheet.createRow(0);
    HSSFCell cell = firstRow.createCell(0);
    cell.setCellValue("회원번호");
    cell = firstRow.createCell(1);
    cell.setCellValue("이름");
    cell = firstRow.createCell(2);
    cell.setCellValue("아이디");
    cell = firstRow.createCell(3);
    cell.setCellValue("가입일");
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow)

Example 44 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project rxlib by RockyLOMO.

the class Helper method readExcel.

public static List<Object[]> readExcel(String filePath, boolean skipColumn) throws IOException {
    List<Object[]> result = new ArrayList<>();
    HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filePath));
    for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
        HSSFSheet sheet = workbook.getSheetAt(sheetIndex);
        for (int rowIndex = skipColumn ? 1 : sheet.getFirstRowNum(); rowIndex < sheet.getLastRowNum(); rowIndex++) {
            HSSFRow row = sheet.getRow(rowIndex);
            List<Object> cellValues = new ArrayList<>();
            for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
                HSSFCell cell = row.getCell(i);
                if (cell == null) {
                    cellValues.add(null);
                    continue;
                }
                Object value;
                switch(cell.getCellTypeEnum()) {
                    case NUMERIC:
                        value = cell.getNumericCellValue();
                        break;
                    case BOOLEAN:
                        value = cell.getBooleanCellValue();
                        break;
                    default:
                        value = cell.getStringCellValue();
                        break;
                }
                cellValues.add(value);
            }
            if (cellValues.contains(null)) {
                Logger.debug(String.format("current=%s offset=%s count=%s -> %s/%s", toJsonString(cellValues), row.getFirstCellNum(), row.getLastCellNum(), rowIndex, sheetIndex));
            }
            result.add(cellValues.toArray());
        }
    }
    return result;
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) ArrayList(java.util.ArrayList) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) FileInputStream(java.io.FileInputStream)

Example 45 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project selenium_java by sergueik.

the class ExcelUtils method createTitle.

/**
 * 设置表头
 *
 * @param sheet
 */
private void createTitle(HSSFSheet sheet) {
    if (currentRow > 0) {
        return;
    }
    HSSFRow row = sheet.createRow(currentRow++);
    int column = 0;
    for (String key : headerMap.keySet()) {
        HSSFCell cell = row.createCell(column++);
        cell.setCellValue(key);
    }
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow)

Aggregations

HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)124 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)98 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)82 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)71 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)29 FileOutputStream (java.io.FileOutputStream)24 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)24 Test (org.junit.Test)18 IOException (java.io.IOException)16 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)15 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)14 File (java.io.File)13 ArrayList (java.util.ArrayList)12 CellValue (org.apache.poi.ss.usermodel.CellValue)10 OutputStream (java.io.OutputStream)8 HashMap (java.util.HashMap)8 Map (java.util.Map)7 AssertionFailedError (junit.framework.AssertionFailedError)7 FileInputStream (java.io.FileInputStream)6 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)6