<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
import org.apache.poi.ss.usermodel.*;
import java.io.*;
public class ReadExcelFile {
public static void main(String[] args) {
try {
InputStream inputStream = new FileInputStream(new File("path/to/excel/file.xlsx"));
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0);
for (Row row : sheet) {
for (Cell cell : row) {
System.out.println(cell.getStringCellValue());
}
}
workbook.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import org.apache.poi.ss.usermodel.*;
import java.io.*;
public class WriteExcelFile {
public static void main(String[] args) {
try {
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet1");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Hello, World!");
FileOutputStream outputStream = new FileOutputStream("path/to/output/excel/file.xlsx");
workbook.write(outputStream);
workbook.close();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}