drupal stats

Writing Data to Excel using C#

July 14th, 2011 Windows Forms 0 Comments


Add a reference “Microsoft.Office.Interop.Excel” into project

Add a reference to the Microsoft.Office.Interop thumb Writing Data to Excel using C#

 

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 to excel using c#, c# write to excel, write data to excel in c#, write data in excel using c#, write in excel using c#, how to store data in excel using c#, writing data to excel using c#, write data to excel c#, c# write excel

Related posts:

  1. Reading Excel and Binding to DataGridView using Microsoft.Office.Interop.Excel
  2. Export DataGridView to Excel
  3. Import Excel Data to GridView
  4. Import Excel file into DataGridView
  5. Get Excel Sheet Names using C#

No Comments