C# 读取Excel模板 修改某行某列的值 另存为新的Excel
Posted genghuilove
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 读取Excel模板 修改某行某列的值 另存为新的Excel相关的知识,希望对你有一定的参考价值。
1 protected Application objExcelApp;//定义Excel Application对象 2 private Workbooks objExcelWorkBooks;//定义Workbook工作簿集合对象 3 protected Workbook objExcelWorkbook;//定义Excel workbook工作簿对象 4 private Worksheet objExcelWorkSheet;//定义Workbook工作表对象 5 6 7 8 9 try{ 10 string workTmp = Server.MapPath("~/BJYH2014/QuarterReportExcel.xlsx"); 11 objExcelApp = new ApplicationClass(); 12 objExcelWorkBooks = objExcelApp.Workbooks; 13 objExcelWorkbook = objExcelWorkBooks.Open(workTmp, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 14 15 16 objExcelWorkSheet = (Worksheet)objExcelWorkbook.Worksheets[1]; //strSheetName是指的Exce工作簿的Sheet名,如果没有命名则为"1" 17 18 objExcelWorkSheet.Cells[20, 2] = "100";//intRow,行;intCol;列;strValue,你处理完以后的值 19 objExcelWorkSheet.Cells[20, 3] = "200";//intRow,行;intCol;列;strValue,你处理完以后的值 20 objExcelWorkSheet.Cells[20, 4] = "300";//intRow,行;intCol;列;strValue,你处理完以后的值 21 objExcelWorkSheet.Cells[20, 5] = "400";//intRow,行;intCol;列;strValue,你处理完以后的值 22 objExcelWorkSheet.Cells[20, 6] = "500";//intRow,行;intCol;列;strValue,你处理完以后的值 23 //object missing = System.Reflection.Missing.Value; 24 string fileName = string.Format(Server.MapPath("~/BJYH2014/Excel/" + Session["deptname"].ToString() + "隐患排查情况统计表{0}.xlsx"), now.ToString("yyyy-MM-dd-HH-mm-ss")); 25 26 27 objExcelWorkbook.SaveAs(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 28 } 29 finally 30 { 31 objExcelApp.Quit(); 32 }
以上是关于C# 读取Excel模板 修改某行某列的值 另存为新的Excel的主要内容,如果未能解决你的问题,请参考以下文章