c#写入日期信息到excel中

来源:互联网 发布:极乐净土相机数据 编辑:程序博客网 时间:2024/05/23 13:32
      object Nothing = System.Reflection.Missing.Value;
            var app = new Excel.Application();
            app.Visible = false;
            Excel.Workbook mybook = app.Workbooks.Open(filenameExcel, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);

            Excel.Worksheet mysheet = (Excel.Worksheet)mybook.Worksheets[1];

            mysheet.Activate();

           mysheet.Cells[row, 1].NumberFormatLocal = "@"; //日期格式设置为 文本 类型,否则写入excel后,小数位的秒会被截断
           mysheet.Cells[row, 1] = time;//time= 2015-08-07 10:24:49.079

         //所有信息写入excel完成后

            mybook.Save();
            mybook.Close(false, Type.Missing, Type.Missing);
            mybook = null;
            //quit excel app  
            app.Quit();


          

0 0