zoukankan      html  css  js  c++  java
  • c# 操作excel 替代方案

      一直使用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

  • 相关阅读:
    20151225jquery学习笔记---编辑器插件
    20151225jquery学习笔记---折叠菜单UI
    hihocoder1078 线段树的区间修改
    hihocoder1067 最近公共祖先·二
    poj1857 To Europe! To Europe!
    PKU_campus_2017_K Lying Island
    PKU_campus_2018_H Safe Upper Bound
    PKU_campus_2018_D Chocolate
    poj3254 Corn Fields
    poj2441 Arrange the Bulls
  • 原文地址:https://www.cnblogs.com/gwazy/p/3233173.html
Copyright © 2011-2022 走看看