c# - increment excel cells according to data being written each time -


currently have specify cells values have added to. how increment in fashion no matter how many times user hits add file button should increment previous pattern. eg. have :

        xlworksheet.cells[1, 1] = combobox2.text;         xlworksheet.cells[1, 2] = textbox5.text;         xlworksheet.cells[1, 3] = textbox2.text;         xlworksheet.cells[1, 4] = combobox3.text;         xlworksheet.cells[1, 5] = textbox3.text;         xlworksheet.cells[1, 6] = combobox1.text; 

upon clicking "add xls file" button, how make follow pattern , save file without having write code:

        xlworksheet.cells[2, 1] = combobox2.text;         xlworksheet.cells[2, 2] = textbox5.text;         xlworksheet.cells[2, 3] = textbox2.text;         xlworksheet.cells[2, 4] = combobox3.text;         xlworksheet.cells[2, 5] = textbox3.text;         xlworksheet.cells[2, 6] = combobox1.text; 

it's not can copy , paste every single time, way tedious. answers , comments welcome. in advance

you can use property.

public int indexprop {get; set;}  public void addtoexcelbtn_click(object sender, eventargs e)  {     //... other code      index +=1;     xlworksheet.cells[indexprop , 1] = combobox2.text;     xlworksheet.cells[indexprop , 2] = textbox5.text;     xlworksheet.cells[indexprop , 3] = textbox2.text;     xlworksheet.cells[indexprop , 4] = combobox3.text;     xlworksheet.cells[indexprop , 5] = textbox3.text;     xlworksheet.cells[indexprop , 6] = combobox1.text; } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -