Install-Package ExcelDataReader
using ExcelDataReader; using System.Text; using System.IO; namespace ConsoleApp50 { internal class Program { static void Main(string[] args) { ReadExcel("aaa.xls"); Console.ReadLine(); } static void ReadExcel(string excelPath) { System.Text.Encoding encoding = System.Text.Encoding.UTF8 ; if (!File.Exists(excelPath)) { return; } Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); using (var fs = File.Open(excelPath, FileMode.Open,FileAccess.Read)) { using (var excelReader = ExcelReaderFactory.CreateReader(fs)) { while (excelReader.Read()) { Console.WriteLine($"{excelReader.GetString(0)},{excelReader.GetString(4)},{excelReader.GetString(7)}"); } while (excelReader.NextResult()) ; } } } } }
标签:via,GetString,C#,excel,System,excelReader,using,ExcelDataReader,excelPath From: https://www.cnblogs.com/Fred1987/p/18370300