コード例 #1
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="xlsSheet"></param>
        /// <param name="xlsBook"></param>
        /// <param name="xlsSheetName"></param>
        private string SaveAsExcel(Excel.Worksheet xlsSheet, Excel.Workbook xlsBook)
        {
            //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) ;
            string desktopPath = @"C:\NPOI";

            if (System.IO.Directory.Exists(desktopPath) == false)
            {
                System.IO.Directory.CreateDirectory(desktopPath);
            }
            desktopPath = desktopPath + "\\" + "IQC";
            if (System.IO.Directory.Exists(desktopPath) == true)
            {
                System.IO.Directory.Delete(desktopPath);
            }
            xlsSheet.SaveAs(desktopPath, 56); //保存在
            ////OpenXls(desktopPath);
            //PrinttheExcel(xlsSheet, desktopPath);
            xlsBook.Close();
            xlsSheet = null;
            KillProcess("Excel");
            string dd = System.IO.Path.GetExtension(desktopPath);


            return(desktopPath + ".xls");
        }
コード例 #2
0
        //文档另存为
        public bool SaveAs(string FileName)
        {
            try
            {
                ws.SaveAs(FileName, Excel.XlFileFormat.xlTemplate, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                return(true);
            }

            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #3
0
ファイル: ClsAllExcel.cs プロジェクト: fengyubox/SFIS
 /// <summary>
 /// 保存Excel文件,格式xml.
 /// </summary>
 public void SaveExcelAsXML()
 {
     if (xlsSaveFileName == "")
     {
         throw new Exception("未指定要保存的文件名");
     }
     try
     {
         xlsWs.SaveAs(xlsSaveFileName, Missing.Value,
                      Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                      Excel.XlSaveAsAccessMode.xlNoChange,
                      Missing.Value, Missing.Value);
     }
     catch (Exception e)
     {
         CloseExcelApplication();
         throw new Exception(e.Message);
     }
 }