예제 #1
0
        public static void ExportToExcel(DataSet ds, Hashtable displaycol_nameList, string otherInfo)
        {
            common_file.common_app.get_czsj();

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                string    filePath     = "";
                string    fileName     = "";
                string    get_fileName = "";
                Hashtable nameList     = new Hashtable();
                nameList = displaycol_nameList;
                SaveFileDialog      saveFileDialog1;
                FolderBrowserDialog folderBrowserDialog1;
                //利用excel对象
                DataToExcel dte = new DataToExcel();
                try
                {
                    common_file.common_app.get_czsj();

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        common_file.common_app.get_czsj();

                        saveFileDialog1        = new SaveFileDialog();
                        saveFileDialog1.Filter = "Excel files (*.xls)|*.xls";

                        folderBrowserDialog1 = new FolderBrowserDialog();
                        if (defaulPath.Trim() != "")
                        {
                            folderBrowserDialog1.SelectedPath = defaulPath;
                        }
                        if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                        {
                            common_file.common_app.get_czsj();

                            filePath     = folderBrowserDialog1.SelectedPath + "\\";
                            defaulPath   = folderBrowserDialog1.SelectedPath;
                            get_fileName = dte.DataExcel(ds.Tables[0], otherInfo, filePath, nameList).Trim();
                            if (get_fileName != "")
                            {
                                fileName = filePath + get_fileName;
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                }
                catch
                {
                    dte.KillExcelProcess();
                }

                if (get_fileName.Trim() != "")
                {
                    common_file.common_app.get_czsj();

                    common_file.common_app.Message_box_show(common_file.common_app.message_title, "导出成功!");
                    //Response.Redirect((ExcelFolder+"\\"+filename,true);
                    //StreamWriter aWriter = new StreamWriter(fileName); aWriter.Write(fileName); aWriter.Close();
                }
            }
            Cursor.Current = Cursors.Default;
        }