Comobox's and executing Excel C#
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
精彩评论