Add a reference “Microsoft.Office.Interop.Excel” into project
Reading and Writing Data to Excel using Microsoft.Office.Interop.Excel
using Excel=Microsoft.Office.Interop.Excel;
using System.Reflection;
Excel.ApplicationClass excelApp = new Excel.ApplicationClass();
Excel.Workbook workbook = (Excel.Workbook)excelApp.Workbooks.Add(Missing.Value);
Excel.Worksheet worksheet;
// Opening excel file
workbook = excelApp.Workbooks.Open("D:\\test.xlsx", 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
// Get first Worksheet
worksheet = (Excel.Worksheet)workbook.Sheets.get_Item(1);
// Setting cell values
((Excel.Range)worksheet.Cells["1", "A"]).Value2 = "5";
((Excel.Range)worksheet.Cells["2", "A"]).Value2 = "7";
workbook.Save();
workbook.Close(0, 0, 0);
excelApp.Quit();
Tags: Write Data to Excel using C#, write in excel using c#, write data to excel in c#, writing data to excel using c#, write data in excel using c#, write to excel using c#, write into excel using C#, writing into excel using c#, c# excel, How to Write data to excel using C#
Related posts:
- Reading Excel and Binding to DataGridView using Microsoft.Office.Interop.Excel
- Export DataGridView to Excel
- Import Excel Data to GridView
- Import Excel file into DataGridView
- Get Excel Sheet Names using C#