使用Java Selenium在Excel表格中写入数据可以通过以下步骤实现:
完整的代码示例:
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.io.FileOutputStream;
import java.io.IOException;
public class ExcelWriter {
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
WebDriver driver = new ChromeDriver(options);
Workbook workbook = new XSSFWorkbook("path/to/excel.xlsx");
Sheet sheet = workbook.getSheet("Sheet1");
Row row = sheet.getRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Data to be written");
FileOutputStream outputStream = new FileOutputStream("path/to/excel.xlsx");
workbook.write(outputStream);
workbook.close();
outputStream.close();
driver.quit();
}
}
注意事项:
推荐的腾讯云相关产品:腾讯云对象存储(COS)
领取专属 10元无门槛券
手把手带您无忧上云