zoukankan      html  css  js  c++  java
  • 利用poi向excle写入数据

    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.ss.usermodel.WorkbookFactory;


    public class PoiWriteExcel {

        public void excelWrite(String filePath,String sheetName,int rowNo,int cellNo,String value) throws Exception, InvalidFormatException, IOException{
            //读取excel文件
            FileInputStream inputStream = new FileInputStream(filePath);
            //以工厂模式创建excel文件对象,支持.xls和.xlsx的所有excel文件
            Workbook book = WorkbookFactory.create(inputStream);
            //获取指定名称的sheet文本
            Sheet sheet = book.getSheet(sheetName);
            //获取要写入数据的目标行
            Row row = sheet.getRow(rowNo);
            //向excel文件中写入数据
            FileOutputStream outputStream = new FileOutputStream(filePath);
            //向目标行的目标单元格中写入数据
            row.getCell(cellNo).setCellValue(value);
            outputStream.flush();
            book.write(outputStream);
            outputStream.close();
        }
    }

  • 相关阅读:
    AWS Redshift 采坑记
    EF Core 小工具
    Setup .net core EF
    Bat 使用MSBuild 制作发布包 (更新20180713)
    Https web Api 拉取数据踩坑记录
    C# 后台程序 通过批处理进行监控
    C#计算日期步进
    IIS 预热 (8.0及8.0以上版本)
    MSBuild 执行文档,关于使用命令行编译
    基于Bamboo的CI配置汇总(.Net Web及Api)
  • 原文地址:https://www.cnblogs.com/zw520ly/p/6030199.html
Copyright © 2011-2022 走看看