N
N
Nikolay Baranenko2016-09-26 15:02:53
Java
Nikolay Baranenko, 2016-09-26 15:02:53

Why is it not loading from *.xlsx (Apache POI)?

Hello.

I'm trying to load information from an excel file (*.xlsx) to JSP using Apache POI (3.15)

Information in C:\\server\\to_db.xlsx looks like this:
num solution
1 First
2 Second
3 Third

<%
   try {
            InputStream ExcelFileToRead = new FileInputStream("C:\\server\\to_db.xlsx");
            XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);

            XSSFWorkbook test = new XSSFWorkbook();

            XSSFSheet sheet = wb.getSheetAt(0);
            XSSFRow row;
            XSSFCell cell;

            Iterator rows = sheet.rowIterator();

            while (rows.hasNext()) {
                row = (XSSFRow) rows.next();
                Iterator cells = row.cellIterator();
                while (cells.hasNext()) {
                    cell = (XSSFCell) cells.next();

                    if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
                        out.print(cell.getStringCellValue() + " ");
                    } else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
                        out.print(cell.getNumericCellValue() + " ");
                    } else {
                        //U Can Handel Boolean, Formula, Errors
                    }
                }
                out.println("Succefully!!!");
            }
        }
         catch (Exception e) {
        out.println( "exception: "+e);
        }
%>


I get a strange result and the browser does not return any errors and does not display anything.
When you try to do something with the file C:\\server\\to_db.xlsx, Windows reports that the file is busy.
What could be the problem and how to solve it?

Thank you in advance for your response.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolay Baranenko, 2016-09-29
@drno-reg

added commons files and everything worked
it would be nice if some error was returned in this case....

R
Rou1997, 2016-09-26
@Rou1997

Hello.

Good day to you!
Well, it means that the problem you have is that the code is strange, and in order to solve it, you need to remove the strangeness!
Not at all, I hope it helped, since I answered the question, I will ask you to mark the Solution, and click Like, don't you like me?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question