当前位置: 代码迷 >> Java Web开发 >> HSSF创建单元格的有关问题 待
  详细解决方案

HSSF创建单元格的有关问题 待

热度:483   发布时间:2016-04-17 11:06:09.0
HSSF创建单元格的问题 在线等待!
Java code
public String downloadTemplate() throws FileNotFoundException, IOException {        String template = get("template");        URL url = ClassLoaderUtil.getResource(template, this.getClass());        String fileName = url.getFile();        Workbook workbook = new HSSFWorkbook(url.openStream());        Sheet sheet = workbook.getSheetAt(0);        Row titles = sheet.getRow(0);        Row keys = sheet.getRow(1);        List<CourseHourType> courseHourTypes = baseCodeService.getCodes(CourseHourType.class);        for (CourseHourType courseHourType : courseHourTypes) {            Cell hourTitleCell = titles.createCell(titles.getLastCellNum(), Cell.CELL_TYPE_STRING);            hourTitleCell.setCellValue(courseHourType.getName());            Cell hourKeyCell = keys.createCell(keys.getLastCellNum(), Cell.CELL_TYPE_STRING);            hourKeyCell.setCellValue("period_hours_" + courseHourType.getCode());        }        response.reset();        String contentType = response.getContentType();        String attch_name = DownloadHelper.getAttachName(fileName);        if (null == contentType) {            contentType = "application/x-msdownload";            response.setContentType(contentType);            logger.debug("set content type {} for {}", contentType, attch_name);        }        response.addHeader("Content-Disposition",                "attachment; filename=\"" + RequestUtils.encodeAttachName(request, attch_name) + "\"");        workbook.write(response.getOutputStream());        return null;    }

求解释一下
createCell(titles.getLastCellNum(), Cell.CELL_TYPE_STRING)
这样传2个参数创建cell起到的作用是什么?



------解决方案--------------------
HSSFCell.CELL_TYPE_STRING 字符串
HSSFCell.CELL_TYPE_NUMERIC 数字
HSSFCell.CELL_TYPE_BOOLEAN 布尔类型