Bonjour à la communauté,
je souhaiterai exporter les données d'un fichier excel dans une table mysql.
J'arrive à récupérer les données mais je ne sais vraiment pas comment les mettre dans ma table. Mon problème est de faire la correspondance entre les valeurs des cellules et celles des attribut de la table.
Ma table à le même nombre de colonne que mon fichier excel (le nombre de colonne étant variable).

voici le code me permettant de lire le fichier excel avec l'API POI.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
 
package pOIExample;
 
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
 
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
 
//import org.apache.poi.xssf.usermodel.xssfd
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFDataFormat;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
public class ExtractData {
 
    public static void main( String [] args ) {
    	 int i=0;
    	 String valeur;
    	 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");
        try {
            InputStream input = ExtractData.class.getResourceAsStream( "qa.xlsx" );
 
            OPCPackage opc=OPCPackage.open(input);
            XSSFWorkbook wb = new XSSFWorkbook(opc);
            XSSFSheet sheet = wb.getSheetAt(0);
 
            Iterator rows = sheet.rowIterator(); 
 
            while(rows.hasNext()) {           
            	XSSFRow  row = (XSSFRow ) rows.next();                
               Iterator cells = row.cellIterator(); 
 
                while(cells.hasNext()){    
 
                	XSSFCell cell = (XSSFCell) cells.next(); 
 
 
                	switch ( cell.getCellType() ) {
 
                        case XSSFCell.CELL_TYPE_NUMERIC:
                        	if(HSSFDateUtil.isCellDateFormatted(cell)){
                        		System.out.print ( sdf.format(cell.getDateCellValue()) );
                        	}else{
                        		System.out.print ( cell.getNumericCellValue() );
                        	}                           
                            break;
                        case XSSFCell.CELL_TYPE_STRING:
                        	valeur = (cell.getRichStringCellValue().getString()).replaceAll("  ", "");
                        	if(valeur.charAt(valeur.length()-1)==32)
                            {valeur = valeur.substring(0,valeur.length()-1);
                            }
                        	System.out.print (" STRING "+ valeur );                            
                            break;
                        default:
                            System.out.print( "unsuported sell type" );
                            break;
                    }
 
 
                }System.out.println(" ");
            }
 
        } catch ( IOException ex ) {
            ex.printStackTrace();
        }catch (InvalidFormatException ex ) {
            ex.printStackTrace();
        }
    }
 
}
Merci!