开发者

Comobox's and executing Excel C#

开发者 https://www.devze.com 2023-04-04 15:51 出处:网络
I want my code to be able to execute a command if the comboBox is equal to a certain variable. It\'s basically if combobox = 0 then excel will change the cell value to 0. The problem is that the if st

I want my code to be able to execute a command if the comboBox is equal to a certain variable. It's basically if combobox = 0 then excel will change the cell value to 0. The problem is that the if statement It开发者_StackOverflow is not properly formatted. Thanks for any help

        if (comboBox1.SelectedText == "0") 
        var xl = new Excel.Application(); 
        xl.Visible = true; 
        var wb = (Excel._Workbook)(xl.Workbooks.Add(Missing.Value)); 
        var sheet = (Excel._Worksheet)wb.ActiveSheet; 
        sheet.Cells[4, 6] = "0"; 


You are missing {}. This shold be all right.

if (comboBox1.SelectedText == "0")
{
    var xl = new Excel.Application(); 
    xl.Visible = true; 
    var wb = (Excel._Workbook)(xl.Workbooks.Add(Missing.Value)); 
    var sheet = (Excel._Worksheet)wb.ActiveSheet; 
    sheet.Cells[4, 6] = "0";
}

If there is more then one command following If statement, you have to use {}.


Try using

if (comboBox1.Text == "0") 

instead

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号