コード例 #1
0
        public void ImproExcel(DataGridView selectDgv)
        {
            SaveFileDialog sdfExport = new SaveFileDialog();

            sdfExport.Filter = "Excel 97-2003文件|*.xls|Excel 2007文件|*.xlsx";
            //   sdfExport.ShowDialog();
            if (sdfExport.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            String filename  = sdfExport.FileName;
            String tableName = "";
            NPOIExcelCompletedToMes NPOIexcel = new NPOIExcelCompletedToMes();
            DataTable tabl = new DataTable();

            tabl = GetDgvToTable(this.selectDgv);

            tableName = "dataGridView1";



            NPOIexcel.ExcelWrite(filename, tabl, tableName);    //excelhelper写出
            if (MessageBox.Show("导出成功,文件保存在" + filename.ToString() + ",是否打开此文件?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                if (File.Exists(filename))    //文件是否存在
                {
                    Process.Start(filename);  //执行打开导出的文件
                }
                else
                {
                    MessageBox.Show("文件不存在!", "提示");
                    return;
                }
            }
        }
コード例 #2
0
        public void ImproExcel()
        {
            String         tableName = this.cbSearchType.SelectedItem.ToString() + "-" + this.dtpStarDate.Value.ToString("yyyy-MM-dd") + "-" + this.dtpStopDate.Value.ToString("yyyy-MM-dd") + ".xlsx";
            SaveFileDialog sdfExport = new SaveFileDialog();

            sdfExport.Filter   = "Excel 2007文件|*.xlsx|Excel 97-2003文件|*.xls";
            sdfExport.FileName = tableName;
            //   sdfExport.ShowDialog();
            if (sdfExport.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            String filename = sdfExport.FileName;

            NPOIExcelCompletedToMes NPOIexcel = new NPOIExcelCompletedToMes();
            DataTable tabl = new DataTable();

            tabl = GetDgvToTable(this.dgvCFoutPut);

            // tableName = "dgvOutgoingTable";
            NPOIexcel.ExcelWrite(filename, tabl, tableName);//excelhelper写出
            if (MessageBox.Show("导出成功,文件保存在" + filename.ToString() + ",是否打开此文件?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                if (File.Exists(filename))   //文件是否存在
                {
                    Process.Start(filename); //执行打开导出的文件
                }
                else
                {
                    MessageBox.Show("文件不存在!", "提示");
                }
            }
        }