博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c# 操作excel 替代方案
阅读量:7069 次
发布时间:2019-06-28

本文共 1388 字,大约阅读时间需要 4 分钟。

  一直使用excel com 接口进行excel 操作,最近一次因为权限折腾了个够呛,果断放弃,使用 NPOI

FileStream file = new FileStream(url, FileMode.Open, FileAccess.Read);            HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);            HSSFSheet sheet1 = hssfworkbook.GetSheet("Sheet1") as HSSFSheet;            sheet1.GetRow(1).Cells[5].SetCellValue (Convert.ToDateTime(Date1).ToString("yyyy年MM月dd日") + "-" + Convert.ToDateTime(Date2).ToString("yyyy年MM月dd日"));            sheet1.ForceFormulaRecalculation = true;            string filePath=context.Server.MapPath("~/Resource/books/" + RuleTypeID + ".xls");            FileStream newfile = new FileStream(filePath, FileMode.Create); hssfworkbook.Write(newfile);            file.Close();            newfile.Close();string fileName = RuleTypeID + ".xls";//客户端保存的文件名FileInfo fileInfo = new FileInfo(filePath);context.Response.Clear();context.Response.ClearContent();context.Response.ClearHeaders();context.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());context.Response.AddHeader("Content-Transfer-Encoding", "binary");context.Response.ContentType = "application/octet-stream";context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");context.Response.WriteFile(fileInfo.FullName);context.Response.Flush();context.Response.End();

 

 http://npoi.codeplex.com

 

转载地址:http://ohqll.baihongyu.com/

你可能感兴趣的文章
【汇编】1.汇编环境的搭建:DOSBox的安装
查看>>
requests 简单爬虫
查看>>
datatable&list<T>
查看>>
【Python3爬虫】selenium入门
查看>>
C语言语法
查看>>
Ruby判断文件是否存在
查看>>
servlet中避免405错误的产生
查看>>
Git的checkout, reset, revert
查看>>
取余递归
查看>>
Java金钱小写转大写
查看>>
林小宅的点名册
查看>>
常用算法Java实现之直接插入排序
查看>>
《第一行代码》书籍阅读笔记
查看>>
java基础知识点复习
查看>>
[Hive_add_10] Hive 的 serde (序列化 & 反序列化) 操作
查看>>
7月18日实习日志
查看>>
python面向对象之类成员修饰符
查看>>
Linux命令大全之基本命令
查看>>
HDU2048 神、上帝以及老天爷
查看>>
Android开发指南(35) —— Toast Notifications
查看>>