zoukankan      html  css  js  c++  java
  • 读取Excel二进制写入DB,并从DB中读取生成Excel文件

    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; }
        }
    }
  • 相关阅读:
    MFC菜单、工具栏和状态栏
    MFC控件
    MFC对话框
    MFC消息映射机制
    性能优化可使用的工具
    常见的内存问题分析思路
    k8s之Probe
    docker swarm
    keepalived配置虚拟ip(vip)实现双机热备以及自动切换主备
    linux安装openjdk1.8
  • 原文地址:https://www.cnblogs.com/itjeff/p/10031616.html
Copyright © 2011-2022 走看看