• c# 将datatable中的数据保存到excel文件中


    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.IO;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebAPIServer.Models
    {
        [Serializable]
        public class Product
        {
            public int ProductID { get; set; }
            public string Name { get; set; }
            public string Description { get; set; }
            public decimal Price { get; set; }
            public string Category { get; set; }
    
    
    
            public static void SaveAsXlS(string fileName, DataTable dataTable)
            {
                DataGrid grid = new DataGrid();
                DataSet set = new DataSet();
    
                dataTable.TableName = fileName;
                set.Tables.Add(dataTable.Copy());
    
                grid.HeaderStyle.Font.Bold = true;
                grid.DataSource = set;
                grid.DataMember = set.Tables[dataTable.TableName].TableName;
                grid.DataBind();
    
                using (StreamWriter sw = new StreamWriter(fileName))
                {
                    using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                    {
                        grid.RenderControl(hw);
                    }
                }
    
            }
        }
    }
  • 相关阅读:
    sort color (荷兰国旗)
    先序遍历和后序遍历构建二叉树
    二叉树的遍历
    排序
    内存相关内容
    chrome控制台console方法表
    记一次移动端CSS引发的小Bug
    JavaScript的事件
    浅谈webpack打包原理
    JS模块化进程
  • 原文地址:https://www.cnblogs.com/mibing/p/7845688.html
Copyright © 2020-2023  润新知