public void WriteBookWithAttributesToCells() { WorkBook wb = WorkBook.CreateNew(); WorkSheet sheet = wb.Sheets["sheet1"]; sheet.Name = "FirstSheet"; IEnumerable <BookWithAttributes> books = FillBookWithAttributesData(10240); sheet.LoadFromCollection(books); wb.Save("WriteBookWithAttributesToCells.xlsx"); }
public void WriteBookWithoutAttributesToCells() { WorkBook wb = WorkBook.CreateNew(); WorkSheet sheet = wb.Sheets["sheet1"]; sheet.Name = "FirstSheet"; IEnumerable <BookWithoutAttributes> books = FillBookWithoutAttributesData(10240); TableDescription tableDesp = new TableDescription("Books"); tableDesp.AllColumns.Add(new TableColumnDescription(new DataColumn("书名", typeof(string))) { PropertyName = "Name" }); tableDesp.AllColumns.Add(new TableColumnDescription(new DataColumn("价格", typeof(double))) { PropertyName = "Price" }); tableDesp.AllColumns.Add(new TableColumnDescription(new DataColumn("发行日期", typeof(DateTime))) { PropertyName = "IssueDate" }); sheet.LoadFromCollection(books, tableDesp, (cell, dcp) => { cell.Value = dcp.PropertyValue; if (dcp.ColumnName == "发行日期") { cell.Value = string.Format("{0:yyyy-MM-dd HH:mm}", dcp.PropertyValue); } }); wb.Save("WriteBookWithoutAttributesToCells.xlsx"); }