您的位置:首页 > 编程语言 > C#

Writing Data to Excel using C#

2012-04-16 14:29 501 查看
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#

引用地址:http://www.dotneter.com/writing-data-to-excel-using-c
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: