Changing the value in a drop down list Excel C#

后端 未结 3 1215
南旧
南旧 2021-01-25 19:02

so I have asked how to change the value in a cell inside of excel using c#, but what if I want to change the value of a drop down list. The code I am using for sheet modifying i

3条回答
  •  盖世英雄少女心
    2021-01-25 19:57

    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();
        }
    

提交回复
热议问题