1. 程式人生 > >讀取Excel二進制寫入DB,並從DB中讀取生成Excel文件

讀取Excel二進制寫入DB,並從DB中讀取生成Excel文件

ada pac 讀取excel class rgs unique stat fir tco

namespace 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文件