public void CollectionExcelExportTest() { var datas = new List <Excel_Test> { new Excel_Test { Name = "AAA", Age = 18, BirthDate = DateTime.Now, Enabled = true }, new Excel_Test { Name = "BBB", Age = 19, BirthDate = DateTime.Now, Enabled = true }, new Excel_Test { Name = "CCC", Age = 17, BirthDate = DateTime.Now, Enabled = true }, new Excel_Test { Name = "DDD", Age = 16, BirthDate = DateTime.Now, Enabled = true }, new Excel_Test { Name = "EEE", Age = 18, BirthDate = DateTime.Now, Enabled = true } }; var excel = ExcelFactory.Create("test_sheet", datas); var bytes = excel.SaveAsBytes(); this.Save(@"D:\Collection_Test.xlsx", bytes); Assert.IsNotNull(bytes); }
public void DataReaderExcelExportTest() { var sql = "SELECT Name, Sex, Age, Birthdate, Address FROM Students"; var dataReader = this.ExecuteReader(sql); var excel = ExcelFactory.Create("test_sheet", dataReader); var bytes = excel.SaveAsBytes(); this.Save(@"D:\DataReader_Test.xlsx", bytes); }
public byte[] ExecuteExcelExport(string sheetName) { var connectionOpt = this.GetConnectionOption(); var sqlQueryAndParms = this.GetSqlQueryAndParms(SelectClauseBuildMode.Raw); var reader = DatabaseReader.Create(connectionOpt.Item1, connectionOpt.Item2) .Reader.GetDataReader(sqlQueryAndParms.Item1, sqlQueryAndParms.Item2); var excel = ExcelFactory.Create(sheetName, reader); return(excel.SaveAsBytes()); }
private byte[] GetBytesOfAttachment() { IDataReader dataReader = null; try { dataReader = this.GetDataReaderOfAttachment(); var sheetname = this._attachmentTopic.TopicName; return(ExcelFactory.Create(sheetname, dataReader).SaveAsBytes()); } catch (Exception) { if (dataReader != null && !dataReader.IsClosed) { dataReader.Close(); } this.SetErrorStatus("Create the dataReader failure."); return(null); } }