import org.apache.poi.ss.usermodel.*;
import java.io.*;
public class ReadExcel {
public static void main(String[] args) throws IOException {
FileInputStream file = new FileInputStream(new File("example.xlsx"));
Workbook workbook = WorkbookFactory.create(file);
Sheet sheet = workbook.getSheetAt(0);
DataFormatter dataFormatter = new DataFormatter();
for (Row row : sheet) {
for (Cell cell : row) {
String cellValue = dataFormatter.formatCellValue(cell);
System.out.print(cellValue + "\t");
}
System.out.println();
}
workbook.close();
file.close();
}
}
import org.apache.poi.ss.usermodel.*;
import java.io.*;
public class WriteExcel {
public static void main(String[] args) throws IOException {
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet1");
Row headerRow = sheet.createRow(0);
Cell headerCell = headerRow.createCell(0);
headerCell.setCellValue("Hello");
FileOutputStream fileOut = new FileOutputStream("example.xlsx");
workbook.write(fileOut);
workbook.close();
fileOut.close();
}
}
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>