简体   繁体   中英

How to read column wise in excel using java?

If suppose excel having date value format in any column means, I need to change the whole column as date format and insert "N/A" value in an empty record of the date column. Anyone, please help me to solve this.

private void processExcelFromLocal() {

        FileInputStream fis = null;
        try {
            fis = new FileInputStream(
                    new File("/home/rajat/Downloads/excelFile.xlsx"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();

        }

        if (fis != null) {

            @SuppressWarnings("resource")
            XSSFWorkbook workbook = null;
            try {
                workbook = new XSSFWorkbook(fis);
            } catch (IOException e) {
                e.printStackTrace();

            }

            XSSFSheet spreadsheet = workbook.getSheetAt(0);

            for (int i = 0; i <= spreadsheet.getLastRowNum(); i++) {
                XSSFRow row = spreadsheet.getRow(i);
                String value = row.getCell().getStringCellValue();    
            }
        }

        try {
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

enter image description here

this is the final output file. have to insert constant value in empty cells of date column without mentioning date column name. empty cells are highlighted as green colour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM