You can break all your records into multiple tables, as they are in you database.
You will create one excel file per table and import it using mysql-excel mechanism. You can also export the excel files as .csv
and import it directly either by using MySQL Workbench or by command prompt
Another way, if you don't want to normalize the excel file, is to parse the file and import it programmatically. You can use apache-poi to read the excel file, or you can export the excel file as csv file and parse it as a text file.
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class App {
public static void main(String[] args) {
Workbook wb = null;
InputStream inp = null;
try {
// InputStream inp = new FileInputStream("workbook.xls");
inp = new FileInputStream("workbook.xlsx");
wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
for (Row row : sheet) {
for (Cell cell : row) {
System.out.println(getCellValue(cell));
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try { if(wb != null) wb.close(); } catch (Exception e) {}
try { if(inp != null) inp.close(); } catch (Exception e) {}
}
}
private static Object getCellValue(Cell cell) {
switch(cell.getCellType()) {
case Cell.CELL_TYPE_STRING :
return cell.getStringCellValue();
case Cell.CELL_TYPE_NUMERIC :
return cell.getNumericCellValue();
case Cell.CELL_TYPE_BOOLEAN :
return cell.getBooleanCellValue();
case Cell.CELL_TYPE_ERROR :
return cell.getErrorCellValue();
case Cell.CELL_TYPE_FORMULA :
return cell.getCellFormula();
case Cell.CELL_TYPE_BLANK :
return null;
default :
return null;
}
}
}
The excel sample (xlsx)
id Name Number Designation
1 manan_1 9876543211 software eng._1
2 manan_2 9876543212 software eng._2
3 manan_3 9876543213 software eng._3
Dependencies (Maven)
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-excelant</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-examples</artifactId>
<version>3.12</version>
</dependency>