-
StackOverflow 文件
-
epplus 教程
-
從現有檔案匯入資料
-
從 CSV 檔案匯入資料
//set the formatting options
ExcelTextFormat format = new ExcelTextFormat();
format.Delimiter = ';';
format.Culture = new CultureInfo(Thread.CurrentThread.CurrentCulture.ToString());
format.Culture.DateTimeFormat.ShortDatePattern = "dd-mm-yyyy";
format.Encoding = new UTF8Encoding();
//read the CSV file from disk
FileInfo file = new FileInfo("C:\\CSVDemo.csv");
//or if you use asp.net, get the relative path
FileInfo file = new FileInfo(Server.MapPath("CSVDemo.csv"));
//create a new Excel package
using (ExcelPackage excelPackage = new ExcelPackage())
{
//create a WorkSheet
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Sheet 1");
//load the CSV data into cell A1
worksheet.Cells["A1"].LoadFromText(file, format);
}