Java uses poi to Execl simple _ read and write _ Operations, poiexecl
1 2/** 1. Simple Steps to read Execl: 3*1. Read Execl through the stream and put it in the memory; 4*2. Read the execl file stream stored in the memory through the WorkbookFactory workbook factory and create a workbook 5*3. Obtain each sheet file in the workbook 6*4. each sheet document obtains 7x5 rows in each row, 8x6 cells in each row, and 9x10 * WorkbookFactory --> Workbook (XSSFWorkbook \ HSSFWorkbook) 11 * | -- Sheet (XSSFSheet \ HSSFSheet) 12 * | -- Row (XSSFRow \ HSSFRow) 13 * | -- Cell (XSSFCell \ HSSFCell) 14 * | -- CellValue15 */16 17 InputStream FCM = new FileInputStream ("F:/execl/readTest1.xlsx"); // read the execl document 18 Workbook wb = WorkbookFactory first. create (FS); // use the WorkbookFactory workbook factory to create a workbook 19 Sheet sheetAt = wb by reading the execl Document Stream. getSheetAt (0); // obtain each sheet document 20 Row = sheetAt In the workbook. getRow (0); // obtain 21 Cell = row for each row through each sheet. getCell (1); // obtain each cell 22 double val = cell by each row. getNumericCellValue (); // obtain the value 23 in the cell. // ============================== ========================================================== ===========25 26/** 27*1. perform the following steps to write Execl: 28*1. Create a blank execl document 29*2. Create a Workbook 30*3. Create a Sheet document 31*4. creates a 32*5 row, creates a cell 33*6 through a row, sets the value 34*7 in the cell, and writes data to the blank ecxecl file stream in the memory through the Workbook. content 35*36 * Workbook --> XSSFWorkbook \ HSSFWorkbook37 * | -- Sheet (XSSFSheet \ HSSFSheet) 38 * | -- Row (XSSFRow \ HSSFRow) 39 * | -- Cell (XSSFCell \ HSSFCell) 40 * | -- CellValue41 */42 43 OutputStream OS = new FileOutputStream ("F: /execl/writeTest1.xlsx "); // creates a blank execl document 44 Workbook wb = new XSSFWorkbook () in the memory through a stream; // creates a Workbook 45 Sheet sheet = wb. createSheet (); // create a Sheet document using the workbook 46 Row = sheet. createRow (0); // create a 47 Cell cell = row in the Sheet document. createCell (0, Cell. CELL_TYPE_STRING); // create a cell 48 cell by using a row. setCellValue ("execl write test haha... "); // set the value in the cell to 49 wb. write (OS); // use the Workbook to write 50 OS content to the blank ecxecl file stream in the memory. close (); 51 52