且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改下拉列表中的值Excel C#

更新时间:2023-01-21 16:27:08

弄清楚它花了我很长时间,请使用它!

Figured it out took me a long time please use it!!

  using Excel = Microsoft.Office.Interop.Excel;

  public virtual Object ActiveSheet { get; set; }

  private void button15_Click(object sender, EventArgs e)
    {
        //Gets ActiveSheet to Modify
        Excel.Application oXL;
        Excel.Workbook oWB;
        Excel.Worksheet oSheet;

        //Start Excel and get Application object.
        oXL = (Excel.Application)Marshal.GetActiveObject("Excel.Application"); 
        oXL.Visible = true;
        oWB = (Excel.Workbook)oXL.ActiveWorkbook; 
        oSheet = (Excel.Worksheet)oWB.ActiveSheet;

        //Generate Linear Guide Supports using Design Table in Solidworks
        if (comboBox1.Text == "0")//no external rails
        {
            oSheet.Cells[6, 4] = "0"; //Change Value in Cell in Excel Cell Location [y-axis, x-axis]
        }
        //Quit Excel
        oXL.Quit();
    }