ExcelReportsGenerator generator = new ExcelReportsGenerator(); //Trial Mode
//ExcelReportsGenerator generator = new ExcelReportsGenerator("place user name here", "place license key here"); //License Mode
//Parameters
string filePath = "AddWorksheetWithColumnDefinitionsExample.xlsx";
Workbook workbook = generator.WorkbookFactory(filePath);
workbook.Author = "John Smith";
workbook.CreatedTime = DateTime.Now;
workbook.LastSavedBy = "John Smith";
workbook.Subject = "This is a subject";
workbook.Title = "This is a title";
List<ColumnDefinition> definitions = new List<ColumnDefinition>
{
//Put the last name column first
new ColumnDefinition("LastName"),
new ColumnDefinition("FirstName"),
new ColumnDefinition("Married"),
new ColumnDefinition("NumberOfChildren"),
new ColumnDefinition("Salary"),
new ColumnDefinition("BirthDate")
};
Worksheet worksheet = generator.AddWorksheet(workbook, "Employees", definitions);
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName", typeof(string));
dataTable.Columns.Add("LastName", typeof(string));
dataTable.Columns.Add("Married", typeof(bool));
dataTable.Columns.Add("NumberOfChildren", typeof(int));
dataTable.Columns.Add("Salary", typeof(decimal));
dataTable.Columns.Add("BirthDate", typeof(DateTime));
DataRow employee1 = dataTable.NewRow();
employee1["FirstName"] = "John";
employee1["LastName"] = "Smith";
employee1["Married"] = true;
employee1["NumberOfChildren"] = 3;
employee1["Salary"] = 60000M;
employee1["BirthDate"] = new DateTime(1977, 12, 15);
dataTable.Rows.Add(employee1);
DataRow employee2 = dataTable.NewRow();
employee2["FirstName"] = "Joe";
employee2["LastName"] = "Jones";
employee2["Married"] = false;
employee2["NumberOfChildren"] = 0;
employee2["Salary"] = 30000M;
employee2["BirthDate"] = new DateTime(1993, 6, 25);
dataTable.Rows.Add(employee2);
generator.FillFromDataTable(worksheet,dataTable);
generator.SaveWorkbook(workbook);