日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

通过excel模板文件根据数据库数据修改其中的单元格数据

發布時間:2025/3/16 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 通过excel模板文件根据数据库数据修改其中的单元格数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 /// <summary> 2 /// 根據文件模板生成excel 3 /// </summary> 5 /// <param name="dttew">利潤表_月報</param> 11 /// <param name="opetes">文件名</param> 12 /// <param name="queryKey">資產負債表{稅款所屬期起-稅款所屬期止}</param> 13 public void LeadExcelone(DataTable dttew, string opetes, string[] queryKey) 14 { 15 string filePath = Server.MapPath("/FilePath/" + "報表申報官方模板.xls");//項目內置文件模板地址 16 using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) 17 { 18 MemoryStream ms = new MemoryStream(); 19 var hssfworkbook = new HSSFWorkbook(file); 95 var sheet2 = hssfworkbook.GetSheetAt(1);//獲取文件第二個sheet 96 row3 = 4; 97 if (dttew != null && dttew.Rows.Count > 0) 98 { 99 for (int i = 0; i < dttew.Rows.Count; i++) 100 { 101 sheet2.GetRow(row3).GetCell(2).SetCellValue(dttew.Rows[i]["F_BalanceCP"].ToString() == "" ? "0.00" : dttew.Rows[i]["F_BalanceCP"].ToString()); 102 sheet2.GetRow(row3).GetCell(3).SetCellValue(dttew.Rows[i]["F_BalanceCY"].ToString() == "" ? "0.00" : dttew.Rows[i]["F_BalanceCY"].ToString()); 103 row3++; 104 } 105 } 223 hssfworkbook.Write(ms); 224 System.Web.HttpContext.Current.Response.Clear(); 225 System.Web.HttpContext.Current.Response.ClearHeaders(); 226 System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); 227 System.Web.HttpContext.Current.Response.ContentType = "application/vnd.ms-excel.sheet.binary.macroEnabled.12"; 228 System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename="+ opetes + ".xls"); 229 System.Web.HttpContext.Current.Response.BinaryWrite(ms.ToArray()); 230 //清除緩存 231 System.Web.HttpContext.Current.Response.Flush(); 232 System.Web.HttpContext.Current.Response.End(); 233 //關閉緩沖區 234 ms.Close(); 235 } 236 }

?

轉載于:https://www.cnblogs.com/shanshuiYiCheng/p/11563985.html

總結

以上是生活随笔為你收集整理的通过excel模板文件根据数据库数据修改其中的单元格数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。