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();
        }
    }

  • 相关阅读:
    Instruments Tutorial for iOS: How To Debug Memory Leaks
    How to Use Instruments in Xcode
    Demystifying iOS Application Crash Logs
    “iOS 推送通知”详解:从创建到设置到运行
    推送通知iOS客户端编写实现及推送服务器端编写
    cocos2d-iphone 与 UI组件
    ScrollLayer
    TexturePacker
    mybatis的配置
    spring+redis
  • 原文地址:https://www.cnblogs.com/zw520ly/p/6030199.html
Copyright © 2011-2022 走看看