I am trying to create a class to read a XLSX file when I upload it to a website.
I have the code to upload the file to the server. The file can be uploaded but it can't capture the data from the excel.
May I know how do I solve or modify this code such that the data is being able to be seen on the web?
I know there's some other duplicate questions out there but after trying, those answers can't seem to work for me.
If I remove the line public static void... , then I will get this error: Package should contain a content type part [M1.13]
public HashMap getConstructJXLList_xlsx(UploadedFile File, int Sheetindex) {
String _LOC = "[PageCodeBase: getConstructJXLList_xlsx]";
HashMap _m = new HashMap();
return _m;
}
//InputStream _is = null;
public static void main(String[] args)
{
try {
FileInputStream input = new FileInputStream(new File("C:\\Users\\admin\\Desktop\\Load_AcctCntr_Template.xlsx"));
org.apache.poi.ss.usermodel.Workbook wb = WorkbookFactory.create(input);
org.apache.poi.ss.usermodel.Sheet s = wb.getSheetAt(0);
Iterator<Row> rows = s.rowIterator();
while (rows.hasNext())
{
Row row = rows.next();
Iterator cells = row.cellIterator();
while (cells.hasNext())
{
XSSFCell cell = (XSSFCell) cells.next();
if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING)
{
System.out.print(cell.getStringCellValue() + "t");
}
else if(cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC)
{
System.out.print(cell.getNumericCellValue() + "t");
}
else if(cell.CELL_TYPE_BLANK==cell.getCellType())
System.out.print( "BLANK " );
else
System.out.print("Unknown cell type");
}
input.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
If I just run the main method from above, this is the output:
0000002b SystemOut O [RedirectLogin: requiredRights]1.0en1102.xhtml
0000002b SystemOut O [En1102: doEn1102_command_readfileAction]1.0
0000002b SystemOut O [En1102: onPageLoadBegin]1.0
it seems that the server did not even run through this code above..
I can just download the excel template on the website and it will be saved on my desktop. The file will contain the title header and I am able to key in whatever data I want in the cells.