java xssfdataformat_JAVA使用poi进行EXCEL模板导入导出,XSSFCell数据类型

该博客介绍了如何使用JAVA的POI库处理EXCEL模板,特别是针对XSSFCell的数据类型进行操作。内容包括读取模板文件,创建并设置样式,替换模板中的固定字符,以及向工作表中添加数据行和单元格。此外,还提供了处理数值型单元格的方法,并展示了如何输出到文件或HTTP响应。
摘要由CSDN通过智能技术生成

();//用于模板固定字符替换

public Exxx(String url, int rowNum) {

File file = new File(url);

String realPath = ("H://uploadfile");

String newFileName = System.currentTimeMillis() + ".xlsx";

// 判断路径是否存在

File dir = new File(realPath);

if (!dir.exists()) {

dir.mkdirs();

}

// 写入到新的excel

File newFile = new File(realPath, newFileName);

try {

newFile.createNewFile();

// 写数据

fileChannelCopy(file, newFile);

InputStream io = new FileInputStream(newFile);

this.workbook = new XSSFWorkbook(io);// 创建workbook,

this.sheet = workbook.getSheetAt(0);//获取工作表(1)

if(sheet!=null) {

this.fos = new FileOutputStream(newFile);

}else {

log.debug("Write error: ["+row.getRowNum()+"] 数据为空");

}

//检测是否有数据,因为是走的模板所以不需要

row = sheet.getRow(5);

if (row == null) {

row = sheet.createRow(5);

}

XSSFCell cell = row.getCell(1);

if (cell == null) {

cell = row.createCell(1);

}

} catch (Exception e) {

e.printStackTrace();

}

this.rowNum = rowNum;

}

/**

*

*@param m当前插入行数

*@return Row对象

*/

publi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值