using LinqToExcel.Attributes;
using System;
namespace LinqToExcelDemo.Models
{
class opensource
{
///
/// 活動名稱
///
[ExcelColumn("活動名稱")] //maps the "EventName" property to the "活動名稱" column
public string EventName { get; set; }
///
/// 活動類別
///
[ExcelColumn("活動類別")]
public string EventCategory { get; set; }
///
/// 主辦單位
///
[ExcelColumn("主辦單位")]
public string Organizer { get; set; }
///
/// 來源網站名稱
///
[ExcelColumn("來源網站名稱")]
public string SourceSite { get; set; }
///
/// 活動起始日期
///
[ExcelColumn("活動起始日期")]
public DateTime EventStartDate { get; set; }
///
/// 活動結束日期
///
[ExcelColumn("活動結束日期")]
public DateTime EventEndDate { get; set; }
///
/// 點閱率
///
[ExcelColumn("點閱率")]
public int ClickRate { get; set; }
}
}
using LinqToExcel;
using LinqToExcelDemo.Models;
using System.Collections.Generic;
using System.Linq;
using System;
namespace LinqToExcelDemo
{
class Program
{
static void Main(string[] args)
{
string FilePath = @".\export.xls";
string SheetName = "活動基本資料";
List<opensource> lOpenSource;
ExcelQueryFactory excelFile = new ExcelQueryFactory(FilePath);
// 1. Default worksheet name is "Sheet1"
// 2. Query a specific worksheet by name
lOpenSource = excelFile.Worksheet<opensource>(SheetName).ToList();
}
}
}
- Ref:
- https://github.com/paulyoder/LinqToExcel
- https://chrisbitting.com/2015/12/24/reading-excel-files-in-net-using-linqtoexcel/
沒有留言:
張貼留言