Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- using OfficeOpenXml;
- using CsvHelper;
- using CsvHelper.Configuration;
- namespace Test {
- class Entry {
- public int TagNumber { get; set; }
- public DateTime RejectDate { get; set; }
- public string Plant { get; set; }
- public string Model { get; set; }
- public string PartNumber { get; set; }
- public string PartName { get; set; }
- public string Defect { get; set; }
- public int Qty { get; set; }
- public string Shift { get; set; }
- public string Station { get; set; }
- public string Associate { get; set; }
- public string Cause { get; set; }
- public string Found { get; set; }
- public string Responsible { get; set; }
- public string Disposition { get; set; }
- public string EnteredBy { get; set; }
- public string Remark { get; set; }
- public override string ToString() {
- return string.Format("Entry({0}, {1}, {2})", TagNumber, RejectDate.ToString("MM/dd/yy"), Qty);
- }
- }
- class EntryMap : CsvClassMap<Entry> {
- public EntryMap() {
- Map(m => m.TagNumber).Index(0);
- Map(m => m.RejectDate).Index(1);
- Map(m => m.Plant).Index(2);
- Map(m => m.Model).Index(3);
- Map(m => m.PartNumber).Index(4);
- Map(m => m.PartName).Index(5);
- Map(m => m.Defect).Index(6);
- Map(m => m.Qty).Index(7);
- Map(m => m.Shift).Index(8);
- Map(m => m.Station).Index(9);
- Map(m => m.Associate).Index(10);
- Map(m => m.Cause).Index(11);
- Map(m => m.Found).Index(12);
- Map(m => m.Responsible).Index(13);
- Map(m => m.Disposition).Index(14);
- Map(m => m.EnteredBy).Index(15);
- Map(m => m.Remark).Index(16);
- }
- }
- class Program {
- static List<Entry> GetRecords(string filename) {
- StreamReader reader = new StreamReader(new FileStream(filename, FileMode.Open));
- CsvReader csv = new CsvReader(reader);
- csv.Configuration.RegisterClassMap<EntryMap>();
- return csv.GetRecords<Entry>().ToList();
- }
- static List<Entry> FilterList(List<Entry> list, Func<Entry, Boolean> func) {
- return list.Where<Entry>(func).ToList();
- }
- static void Main(string[] args) {
- List<Entry> list = GetRecords("nc_list.csv");
- Console.WriteLine(list.Count());
- FileInfo newFile = new FileInfo("report.xlsx");
- if (newFile.Exists) {
- newFile.Delete();
- newFile = new FileInfo("report.xlsx");
- }
- ExcelPackage package = new ExcelPackage(newFile);
- ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Analysis");
- package.Save();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement