C# 创建Excel文件

 

 

 //excel 路径创建文件
            
            try
            {
                //string fileTest = "D:\\openexcel.xlsx";
                string fileTest = Gloable.excel_path;
                if (File.Exists(fileTest))
                {
                    File.Delete(fileTest);
                }
                Microsoft.Office.Interop.Excel.Application oApp;
                Excel.Worksheet oSheet;
                Excel.Workbook oBook;

                oApp = new Excel.Application();
                oBook = oApp.Workbooks.Add();
                oSheet = (Excel.Worksheet)oBook.Worksheets.get_Item(1);
                //oSheet.Cells[1, 1] = "some value";
                oBook.SaveAs(fileTest);
                oBook.Close();
                oApp.Quit();
            }
            finally { }

 

你可能感兴趣的:(C#学习)