C#: How to access an Excel cell?

后端 未结 7 1139
忘掉有多难
忘掉有多难 2020-12-05 18:25

I am trying to open an Excel file and populate its cells with data? I have done the following coding so far.

Currently I am at this stage with the following code but

7条回答
  •  感情败类
    2020-12-05 19:25

    This works fine for me

           Excel.Application oXL = null;
            Excel._Workbook oWB = null;
            Excel._Worksheet oSheet = null;
    
            try
            {
                oXL = new Excel.Application();
                string path = @"C:\Templates\NCRepTemplate.xlt";
                oWB = oXL.Workbooks.Open(path, 0, false, 5, "", "",
                    false, Excel.XlPlatform.xlWindows, "", true, false,
                    0, true, false, false);
    
                oSheet = (Excel._Worksheet)oWB.ActiveSheet;
                oSheet.Cells[2, 2] = "Text";
    

提交回复
热议问题