Leggere file excel xml

giovedì 17 dicembre 2009 - 13.48

secks Profilo | Senior Member

Con C# 2008 ho generato un file excel in formato xml.
Ora però dovrei leggerlo con
string s = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFil + ";Extended Properties=\"Excel 8.0;HDR={1};IMEX=1\"";
ma nella connessione oledb non viene riconosciuto il formato.

C'è un modo?

Ciao a tutti.
Paolo.

brazero Profilo | Junior Member

Prova con questa Impostazione:

Connection String:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";"

SQL Query:
"SELECT * FROM [sheet1$]"

Ciaooo

secks Profilo | Senior Member

Da sempre l'errore di formato nella connessione.

brazero Profilo | Junior Member

Puoi postare il codice?

Ciaoo

secks Profilo | Senior Member

Ecco il codice.
Cmq ribadisco che il file non è un vero file excel, bensì un file creato da c# in formato xml. Se lo apri come testo si vede il contenuto. Se lo converto in excel 97/2003 funziona.
Evidentemente ci dovrà essere qualche altro modo ...

Allego il file.

// Dichiaro la tabella
DataTable t = new DataTable("DbXls");

string s = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFil + ";Extended Properties=\"Excel 8.0;HDR={1};IMEX=1\"";

//Prove varie
//s = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFil + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";";

////Microsoft.ACE.OLEDB.8.0; Data Source = C: \ Cartella \ myExcel2007file.xlsx; Extended Properties = "Excel 12.0 Xml; HDR = YES"; "
// //s = "Microsoft.ACE.OLEDB.8.0 = Provider;Data Source=" + strFil + ";" + "Data Source =" & strFil & ";Extended Properties=\"Excel 12.0 Xml;HDR=NO;IMEX=1\""; "Extended Properties =\"Excel 12.0 Xml; HDR = NO; IMEX = 1\"";
// s = "Provider=Microsoft.ACE.OLEDB.8.0;Data Source=" + strFil + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";
// s = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + strFil + "; Extended Properties = Excel 12.0";
// s = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFil + ";Extended Properties=\"Excel 8.0;HDR=YES;";

using (OleDbConnection connection = new OleDbConnection(s))
{
connection.Open(); //---------> ERRORE SUL FORMATO

using (OleDbDataAdapter da = new OleDbDataAdapter(string.Format("select * from [{0}]", "Sheet1$"), connection))
{
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5