C
C#8mo ago
Piixel

✅ Read a xlsx file with c#

I am trying to read a xlsx file "Distance.xlsx" with an array of string, just like this code:
string[] lines = File.ReadAllLines("Distances.xlsx");
foreach (string line in lines)
{
Console.WriteLine(line);
}
string[] lines = File.ReadAllLines("Distances.xlsx");
foreach (string line in lines)
{
Console.WriteLine(line);
}
But it only return of bunch of random symbol, do u know how I shloud procede to read my file?
6 Replies
Pobiega
Pobiega8mo ago
excel files are not plaintext its like trying to read an imagefile with notepad, it aint gonna work
x0rld 👻 🎃
x0rld 👻 🎃8mo ago
$closedxml is nice to read excel ah $excel better
MODiX
MODiX8mo ago
ClosedXML 0.102.2
See release notes https://github.com/ClosedXML/ClosedXML/releases/tag/0.102.2 ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.
Piixel
PiixelOP8mo ago
thx, closedxml worked, I did this :
string cheminFichier = "filepath";

using (var classeur = new XLWorkbook(cheminFichier))
{
var feuille = classeur.Worksheet(1);

foreach (var cellule in feuille.CellsUsed())
{
Console.WriteLine($"Cellule {cellule.Address}: {cellule.Value}");
}
}
string cheminFichier = "filepath";

using (var classeur = new XLWorkbook(cheminFichier))
{
var feuille = classeur.Worksheet(1);

foreach (var cellule in feuille.CellsUsed())
{
Console.WriteLine($"Cellule {cellule.Address}: {cellule.Value}");
}
}
And it worked well how do I mark that this problem is solved?
MODiX
MODiX8mo ago
Use the /close command to mark a forum thread as answered
Piixel
PiixelOP8mo ago
thx for you help
Want results from more Discord servers?
Add your server