Reputation: 11
I'm trying to insert data inside Excel sheet using C# everything in code and run is OK but the data did not insert in the Excel sheet.
Hint: I inserted another data in another Excel sheet using the same code an data inserted successfully.
Upvotes: 0
Views: 4647
Reputation: 801
Try the below code
var excelApp = new Excel.Application();
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(@"Excel.xlsx");
Excel._Worksheet excelWorkSheet = (Excel._Worksheet)excelWorkbook.Sheets[1];
excelWorkSheet = (Excel._Worksheet)excelApp.ActiveSheet;
Excel.Range excelRange = excelWorkSheet.UsedRange;
int rowCount = excelRange.Rows.Count;
excelApp.Visible = true;
excelWorkSheet.Cells[1, "A"] = "Insert";
excelWorkSheet.Cells[1, "B"] = "your";
excelWorkSheet.Cells[1, "C"] = "text";
excelWorkSheet.Cells[1, "D"] = "here";
excelWorkbook.Close(true, "output.xlsx");
excelApp.Quit();
Upvotes: 1