日期:2014-05-17  浏览次数:20831 次

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 布尔类型