zoukankan      html  css  js  c++  java
  • .Net操作Excel公式实现

    //传入Excel公式,获取公式计算结果
    private
    string GetValue(string formula) { string result = ""; try { Object missing = System.Reflection.Missing.Value; Excel.Application excelApp = new Excel.Application(); Excel.Workbooks wbooks = (Excel.Workbooks)excelApp.Workbooks; string path1 = AppDomain.CurrentDomain.BaseDirectory + ("UpFiles\") + "635236681202245225.xls"; Excel.Workbook wbook = wbooks.Open(path1, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); excelApp.Visible = false; excelApp.DisplayAlerts = false; //s写入sheet1 Excel.Worksheet wsheet = (Excel.Worksheet)wbook.Worksheets.get_Item(1); Excel.Range range = (Excel.Range)wsheet.Cells[1, 1]; range.Formula = formula; //range = (Excel.Range)wsheet.Cells[1, 2]; //range.Value2 = 5; //range = (Excel.Range)wsheet.Cells[1, 3]; //range.Value2 = 123; wbook.Save(); range = (Excel.Range)wsheet.Cells[1, 1]; result = range.Value2.ToString(); wbook.Close(); wbooks.Close(); } catch { } finally { Process[] myProcesses = Process.GetProcessesByName("Excel"); foreach (Process myProcess in myProcesses) { myProcess.Kill(); } } return result; }
  • 相关阅读:
    2021.5.24 团队第二阶段冲刺第一天
    2021.5.21
    2021.5.20
    2021.5.19
    2021.5.18
    软件包安装
    Selenium中的PageObject模式
    理解Python中的装饰器
    Selenium中的断言
    Selenium处理隐藏元素
  • 原文地址:https://www.cnblogs.com/senyier/p/3498526.html
Copyright © 2011-2022 走看看