var workbook = Workbook.Create("test.xlsx" );
var worksheet = workbook.Worksheets[ 0 ];
// Define a dataTable, the import options(show specific ColumnNames) and call the ImportData function.
var dataTable = new DataTable( "Employees" );
dataTable.Columns.Add( "Name", typeof( string ) );
dataTable.Columns.Add( "Position", typeof( string ) );
dataTable.Columns.Add( "Experience", typeof( double ) );
dataTable.Columns.Add( "Salary", typeof( int ) );
dataTable.Rows.Add( "Jenny Melchuck", "Project Manager", 11.5d, 77000 );
dataTable.Rows.Add( "Cindy Gartner", "Medical Assistant", 1.3d, 56000 );
dataTable.Rows.Add( "Carl Jones", "Web Designer", 4d, 66000 );
dataTable.Rows.Add( "Anna Karlweiss", "Account Executive", 7.8d, 51000 );
dataTable.Rows.Add( "Julia Robertson", "Marketing Coordinator", 17.6d, 65000 );
var dataTableImportOptions = new DataTableImportOptions() { DestinationTopLeftAddress = "B5", ColumnNames = new string[] { "Name", "Experience", "Position" }, IsColumnNamesShown = true };
worksheet.ImportData( dataTable, dataTableImportOptions );
workbook.Save();
var workbook = Workbook.Create("test.xlsx" );
var worksheet = workbook.Worksheets[ 0 ];
// Define a list of user objects, the import options(vertical by default, specify PropertyNames and show propertyNames) and call the ImportData function.
var userObjectData = new List<Player>()
{
new Player() { Name = "Tom Sawyer", Team = Team.Miami_Ducks, Number = 9 },
new Player() { Name = "Mike Smith", Team = Team.Chicago_Hornets, Number = 18 },
new Player() { Name = "Kelly Tomson", Team = Team.LosAngelese_Raiders, Number = 33 },
new Player() { Name = "John Graham", Team = Team.NewYork_Bucs, Number = 7 },
};
var userObjectImportOptions = new UserObjectImportOptions() { DestinationTopLeftAddress = "H5", PropertyNames = new string[] { "Name", "Team" }, IsPropertyNamesShown = true };
worksheet.ImportData( userObjectData, userObjectImportOptions );
workbook.Save();
private class Player
{
public string Name { get; set; }
public int Number { get; set; }
public Team Team { get; set; }
}