Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
Leggere file excel xml
giovedì 17 dicembre 2009 - 13.48
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
secks
Profilo
| Senior Member
442
messaggi | Data Invio:
gio 17 dic 2009 - 13:48
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
63
messaggi | Data Invio:
gio 17 dic 2009 - 23:42
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
442
messaggi | Data Invio:
ven 18 dic 2009 - 15:10
Da sempre l'errore di formato nella connessione.
brazero
Profilo
| Junior Member
63
messaggi | Data Invio:
ven 18 dic 2009 - 15:31
Puoi postare il codice?
Ciaoo
secks
Profilo
| Senior Member
442
messaggi | Data Invio:
ven 18 dic 2009 - 17:37
1226_Pippo.zip
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))
{
Torna su
Stanze Forum
Elenco Threads
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 !