我有两列,即Excel中的Setup和Request,需要使用java在Excel中写入多行
public void WriteExcelValues() throws IOException {
String Ustr= setup.getText();
String urequest = request.getText();
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(Ustr);
cell1.setCellValue(urequest);
//cell.setCellValue("AcknowledgementId");
}
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
fos.close();
}
例如
上面的代码并不完整,也不满足标准。
冉冉说
繁星点点滴滴
相关分类