使用Java在excel的两列中写入多个记录

问题描述 投票:0回答:2

我有两列,即Excel中的Setup和Request,需要使用Java在Excel中写多行

public void WriteExcelValues() throws IOException {
    File file = new File(System.getProperty("user.dir") 
                            + "/src/main/uat/testdata/FreeTestData.xlsx");
    FileInputStream fis = new FileInputStream(file);
    Workbook workbook = new XSSFWorkbook(fis);
    Sheet sheet = workbook.getSheetAt(0);
    int lastRow = sheet.getLastRowNum();
    int n = 1;

    for (int i = 1; i <= n; i++) {   
        Row row = sheet.getRow(i); 
        Cell cell = row.createCell(8);
        Cell cell1 = row.createCell(9);

        cell.setCellValue(str1);
        cell1.setCellValue(part);
        //cell.setCellValue("AcknowledgementId"); 
    }

    FileOutputStream fos = new FileOutputStream(file);   
    workbook.write(fos);
    fos.close();
}

例如

enter image description here

以上代码不完整,也不满足标准。

java automation excel-2010
2个回答
0
投票
for(int i=1; i<=n; i++){

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.