Writing Data to Excel using C#

44 篇文章 0 订阅
2 篇文章 0 订阅

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 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:

  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#
引用地址: http://www.dotneter.com/writing-data-to-excel-using-c



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值