public void Run() { //-> File: ExcelExample.cs // Create an excel storage for specific class // By default start row/column is 2/B (index 1) ExcelNPOIStorage.ExcelNPOIStorage storage = new ExcelNPOIStorage.ExcelNPOIStorage(typeof(Student)); // Set storage file name -> that will be excel output file name // Extension must be .xlsx or .xls storage.FileName = "Students.xlsx"; // Sheet name is not required. By default sheet name will be "Sheet0" storage.SheetName = "Students"; storage.ColumnsHeaders.Add("Student number"); storage.ColumnsHeaders.Add("Student name"); storage.ColumnsHeaders.Add("Course name"); // Test data int count = 3; Student[] students = new Student[count]; students[0] = CreateStudent(0, "Chuck Norris", "Karate"); students[1] = CreateStudent(1, "Steven Seagal", "Aikido"); students[2] = CreateStudent(2, "Dennis Ritchie", "Programming"); // Insert students to excel storage // This method will save out excel file storage.InsertRecords(students); //-> /File }
private static ExcelXlsType[] ReadFromExcelStorage(string fileName, int stopAfterEmptyRows) { var provider = new ExcelNPOIStorage.ExcelNPOIStorage(typeof(ExcelXlsType)); provider.FileName = TestCommon.GetPath("Excel", fileName); provider.SheetName = "Sheet1"; provider.StartRow = 1; provider.ExcelReadStopAfterEmptyRows = stopAfterEmptyRows; return((ExcelXlsType[])provider.ExtractRecords()); }
private static ExcelXlsType[] ReadFromExcelStorage(string fileName, int stopAfterEmptyRows) { var provider = new ExcelNPOIStorage.ExcelNPOIStorage(typeof(ExcelXlsType)); provider.FileName = TestCommon.GetPath("Excel", fileName); provider.SheetName = "Sheet1"; provider.StartRow = 1; provider.ExcelReadStopAfterEmptyRows = stopAfterEmptyRows; return (ExcelXlsType[])provider.ExtractRecords(); }
public void Run() { //-> File: ExcelExample.cs // Create an excel storage for specific class // startRow = 2 & startColumn = 1 -> for skipping column header names ExcelNPOIStorage.ExcelNPOIStorage storage = new ExcelNPOIStorage.ExcelNPOIStorage(typeof(Student), 2, 1); // Set storage file name -> represents the excel file name we want to read storage.FileName = "Students.xlsx"; // Read from excel file Student[] students = storage.ExtractRecords() as Student[]; Console.WriteLine("\t\tStudents from file:"); foreach (Student s in students) { Console.WriteLine(s); } // Make some changes students[0].StudentNumber = 420; Console.WriteLine(Environment.NewLine + "Student {0} edited.", students[0].FullName); students[1].Course = "Jiu-Jitsu"; Console.WriteLine("Student {0} edited.", students[1].FullName); Console.WriteLine(Environment.NewLine + "\t\tEdited students:"); foreach (Student s in students) { Console.WriteLine(s); } // Insert students to excel storage // This method will save out excel file storage.InsertRecords(students); Console.WriteLine(Environment.NewLine + "Changes saved."); //-> /File }