读写Excel文档

实践中经常用到,故写下备用

1、引用COM,包括Microsoft Excel 12.0 Object Library与Microsoft Office 12.0 Object Library

2、using Excel = Microsoft.Office.Interop.Excel;

/// <summary>
/// 根据Excel格坐标写Excel文件
/// </summary>
private void WriteExcel()
{
    Excel.Application oXL;
    Excel._Workbook oWB;
    Excel._Worksheet oSheet;

    oXL = new Excel.Application();
    oXL.Visible = true;
    oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
    oSheet = (Excel._Worksheet)oWB.ActiveSheet;
    oSheet.Cells[1, 1] = "";//写入第一格内容
}

原文地址:https://www.cnblogs.com/guyichang/p/2724950.html