\timport java.io.FileInputStream; \timport java.io.IOException; \t \timport org.apache.poi.ss.usermodel.Cell; \timport org.apache.poi.ss.usermodel.Row; \timport org.apache.poi.ss.usermodel.Sheet; \timport org.apache.poi.ss.usermodel.Workbook; \timport org.apache.poi.ss.usermodel.WorkbookFactory; \t \tpublic class ExcelReader { \t \t public static void main(String[] args) { \t try { \t FileInputStream file = new FileInputStream("sample.xlsx"); \t Workbook workbook = WorkbookFactory.create(file); \t Sheet sheet = workbook.getSheetAt(0); \t \t for (Row row : sheet) { \t for (Cell cell : row) { \t System.out.println(cell.toString()); \t } \t } \t \t workbook.close(); \t file.close(); \t } catch (IOException e) { \t e.printStackTrace(); \t } \t } \t} \timport java.io.FileOutputStream; \timport java.io.IOException; \t \timport org.apache.poi.ss.usermodel.Cell; \timport org.apache.poi.ss.usermodel.Row; \timport org.apache.poi.ss.usermodel.Sheet; \timport org.apache.poi.ss.usermodel.Workbook; \timport org.apache.poi.ss.usermodel.WorkbookFactory; \timport org.apache.poi.xssf.usermodel.XSSFWorkbook; \t \tpublic class ExcelWriter { \t \t public static void main(String[] args) { \t try { \t Workbook workbook = new XSSFWorkbook(); \t Sheet sheet = workbook.createSheet("Sheet1"); \t \t Row row = sheet.createRow(0); \t Cell cell = row.createCell(0); \t cell.setCellValue("Hello, World!"); \t \t FileOutputStream file = new FileOutputStream("output.xlsx"); \t workbook.write(file); \t \t workbook.close(); \t file.close(); \t } catch (IOException e) { \t e.printStackTrace(); \t } \t } \t}


上一篇:
下一篇:
切换中文