C#excel의 명령 양식sheet에 지정된 행렬에 데이터 쓰기

2053 단어
첫 번째, 참조 추가
Microsoft.Office.Interop.Excel
2단계, 함수 호출
        /// <summary>
        ///  excel sheet 
        /// </summary>
        /// <param name="fileName">excel , </param>
        /// <param name="sheetName"> </param>
        /// <param name="lineNbr"> , 1 </param>
        /// <param name="dt"> </param>
        /// <param name="mylog"> , </param>
        public static void WriteToEcel(string fileName, string sheetName, int lineNbr, string dt, log4net.ILog mylog)
        {
            Microsoft.Office.Interop.Excel.Application objExcelApp;// Excel Application 
            Microsoft.Office.Interop.Excel.Workbooks objExcelWorkBooks;// Workbook 
            Microsoft.Office.Interop.Excel.Workbook objExcelWorkbook;// Excel workbook 
            Microsoft.Office.Interop.Excel.Worksheet objExcelWorkSheet;// Workbook 
 
            objExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
            objExcelWorkBooks = objExcelApp.Workbooks;
            try
            {
                objExcelWorkbook = objExcelWorkBooks.Open(fileName, 0, false, 5, "", "", true,
                Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
                objExcelWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)objExcelWorkbook.Worksheets[sheetName]; //strSheetName Exce Sheet , "1"
                objExcelWorkSheet.Select(Type.Missing);
                Microsoft.Office.Interop.Excel.Worksheet objExcelWorkSheetTemp = (Microsoft.Office.Interop.Excel.Worksheet)objExcelApp.ActiveSheet;
                // 
                objExcelWorkSheetTemp.Cells[lineNbr, 2] = dt;
                objExcelWorkbook.Save();
                objExcelWorkbook.Close();
            }
            catch (Exception ex)
            {
                mylog.Error(ex.Message);
            }

        }

이 방법은 매우 느리다

좋은 웹페이지 즐겨찾기