Autor Beitrag
tomo2403
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 46

Win10
C#, VS 2019
BeitragVerfasst: Sa 16.06.18 18:15 
Hey Leute, :wink2:

ich habe eine Excel Datei (.xls) erstellt und möchte diese nun in ein DataGridView einbinden, habe aber keine Ahnung wie das geht! :gruebel:
Kann mir das bitte jemand sagen?

Danke im Voraus!
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Sa 16.06.18 18:27 
Hallo,

z.B. per OLE:
C# DataGridView Loading data from Excel
Import data from Excel file to Windows Forms DataGridView using C# and VB.Net
Importing Any Excel Spreadsheet into a DataGridView - C#
Import Excel to Datagridview
Dazu muß aber Excel auf dem Rechner installiert sein.

Die Suche nach "C# import xls to datagridview" im Internet müßte weitere Ergebnisse liefern.

Für diesen Beitrag haben gedankt: tomo2403
tomo2403 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 46

Win10
C#, VS 2019
BeitragVerfasst: Sa 16.06.18 18:38 
Danke für die Tipps aber, ich möchte die Datei sofort laden wenn die Anwendung gestartet wird und nicht über einen OpenFileDialog öffnen.

Gibt es aber auch einen anderen weg? Ich habe Excel nicht auf meinem Rechner. Die Datei habe ich an einem anderen Gerät erstellt.
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Sa 16.06.18 19:01 
Das mit dem OpenFileDialog ist natürlich optional. Du kannst selbstverständlich einen festen Dateinamen beim Import angeben.

Da XLS ein proprietäres Format von MS ist, benötigst du dazu eigentlich Excel. Evtl. reicht aber auch einfach die Installation des passenden "Microsoft.ACE.OLEDB" Treibers (für die jeweilige Excel-Version, z.B. Microsoft Access Database Engine 2016 Redistributable), dann sollte auch der OLE-Import ohne installiertes Excel klappen (kannst es ja mal probieren).
Ansonsten mußt du ein anderes Format verwenden, z.B. XLSX oder eben CSV.

Es gibt aber auch externe Libs, wie z.B. ExcelDataReader.
Weitere findest du unter How to read an excel file in C# without using Microsoft.Office.Interop.Excel libraries.


Zuletzt bearbeitet von Th69 am So 17.06.18 08:40, insgesamt 1-mal bearbeitet

Für diesen Beitrag haben gedankt: tomo2403
tomo2403 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 46

Win10
C#, VS 2019
BeitragVerfasst: Sa 16.06.18 20:11 
Ok Danke, ich probiere es mal aus.

Gibt es eigentlich noch einen anderen Weg eine xls-Datei in einer WinForm darzustellen?

PS: Ich kann Microsoft.Jet.OLEDB.4.0 nicht finden/downloaden
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 17.06.18 08:36 
Der Treiber ist in "Microsoft Access Database Engine 2010/16 Redistributable" enthalten (der Excel-Import/Export ist nur eine abgespeckte Access-Variante).
Trotzdem würde ich dann den Zugriff eher mittels der (neueren) Microsoft ACE OLEDB 12.0 connection strings verwenden.

Wenn du ein Excel-ähnlicheres Aussehen (für WinForms) haben möchtest, dann schau dir mal SourceGrid an.
tomo2403 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 46

Win10
C#, VS 2019
BeitragVerfasst: So 17.06.18 11:28 
1. Ich habe Microsoft Access Database Engine 2010/16 Redistributable installiert und es Funktioniert immer noch nicht.

2. Wenn ich SourceGrid in meiner WinForm ausführe kommt die Fehlermeldung das das Projekt im falschen Framework ist. Ich habe das Framework geändert und es Funktioniert immer noch nicht.
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 17.06.18 16:26 
Dann machst du wohl etwas falsch. :gruebel: