当前位置:Gxlcms > 数据库问题 > 读取Excel二进制写入DB,并从DB中读取生成Excel文件

读取Excel二进制写入DB,并从DB中读取生成Excel文件

时间:2021-07-01 10:21:17 帮助过:11人阅读

SendMailSMSService { class Program { static void Main(string[] args) { var connString = SqlDataHelper.GetConnectionString<FileContent>(); //读取Excle文件并写入表中 var bytes = File.ReadAllBytes("a.xlsx"); var entity = new FileContent { FileContentID = Guid.NewGuid(), Content = bytes }; var count = entity.InsertToSql(connString); //从表中读取二进制并生成Excel文件 var query = entity; var newEntity = entity.Query(connString, _ => _.FileContentID).FirstOrDefault(); var newBytes = newEntity.Content; var fs = File.Create("b.xlsx"); fs.Write(newBytes, 0, newBytes.Length); fs.Flush(); fs.Close(); fs.Dispose(); } } [DB("FileDB")] [Table("Portal.FileContent")] public class FileContent { [Key] [DataMapping] [SqlDataType(System.Data.SqlDbType.UniqueIdentifier)] public Guid FileContentID { get; set; } [DataMapping("FileContent")] [SqlDataType(System.Data.SqlDbType.VarBinary)] public byte[] Content { get; set; } } }

 

读取Excel二进制写入DB,并从DB中读取生成Excel文件

标签:ide   stat   span   first   nbsp   write   sys   etc   nec   

人气教程排行