JAVA用来读写XLSX的代码发我
时间: 2023-03-29 20:03:17 浏览: 99
你可以使用Apache POI库来读写XLSX文件,以下是一个简单的示例代码:
```
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class XLSXReadWriteExample {
public static void main(String[] args) throws IOException {
// 读取XLSX文件
FileInputStream inputStream = new FileInputStream(new File("example.xlsx"));
Workbook workbook = new XSSFWorkbook(inputStream);
Sheet sheet = workbook.getSheetAt();
// 写入XLSX文件
Row row = sheet.createRow();
Cell cell = row.createCell();
cell.setCellValue("Hello, World!");
FileOutputStream outputStream = new FileOutputStream("example.xlsx");
workbook.write(outputStream);
workbook.close();
}
}
```