首页 > 代码库 > C# 读取Excel模板 修改某行某列的值 另存为新的Excel
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 finally30 {31 objExcelApp.Quit();32 }
C# 读取Excel模板 修改某行某列的值 另存为新的Excel
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。