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; }
  • 相关阅读:
    离开学校一年多
    ZOJ Problem Set–1337 Pi
    Old Bill
    ZOJ Problem Set–1382 A Simple Task
    ZOJ Problem Set 2975 Kinds of Fuwas
    ZOJ Problem Set 2952 Find All M^N Please
    Generate Passwords
    Java 数据类型转换之字符串
    ZOJ Problem Set 2987 Misspelling
    Digital Roots
  • 原文地址:https://www.cnblogs.com/senyier/p/3498526.html
Copyright © 2011-2022 走看看