Import Excel vers DataSet (OleDB) problème format xlsx
Bonjour,
Dans un programme, j'importe une feuille d'un fichier Excel *.xls (Excel 97 - 2003) vers un DataSet.
Jusqu'ici, pas de problème. Cependant, j'aimerais pouvoir faire de même avec les fichier *.xlsx.
Connaissez vous une solution?
Actuellement, si j'essaie d'importer un fichier xlsx, j'ai l'erreur suivante:
Citation:
La table externe n'est pas dans le format attendu.
Voici mon code (au cas où):
Code:
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
|
public static DataSet excelToTable(String urlFichier)
{
DataSet ds = new DataSet();
using (OleDbConnection conn = new OleDbConnection())
{
using (OleDbCommand cmd = new OleDbCommand())
{
conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + urlFichier + ";Extended Properties=Excel 8.0;";
String nomFeuille = "Feuil2";
cmd.CommandText = "SELECT * FROM [" + nomFeuille + "$]";
cmd.Connection = conn;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
try
{
da.Fill(ds);
}
catch (Exception ex)
{
log.Error("excelToTable() : " + ex.Message);
}
}
}
return ds;
} |
Merci pour votre aide.