.net 后台生成Excel文件

.net 后台生成Excel文件

                //获取文件路径
                string path = ConfigurationManager.AppSettings[EnumAppSettingKey.UploadFilePath.ToString()];
                string msg00_sendsq = rblModel.reqNo;
                //文件名称
                string fileNM = DateTime.Now.ToString("yyyyMMddHHmmssffff") + "-" + msg00_sendsq;
                string fileExt = string.Empty;
                //创建文件
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //生成Excel
                fileExt = ".xls";
                string fullNM = fileNM + fileExt;
                string filePath = Path.Combine(path, fullNM);
                StreamWriter sw = new StreamWriter(filePath);
                //将拼接好的HTML代码打印成excel文件
                sw.Write(sb.ToString());
                sw.Close(); 
原文地址:https://www.cnblogs.com/zhangweidong/p/5168851.html