根据界面到处excel表格

根据界面到处excel表格
  private void 拟办单excelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (txtinfoid.Text.Trim() == "")
            {
                MessageBox.Show("请先保存信访件!", "提示");
                return;
            }
            saveFileDialog1.FileName = txtinfoid.Text.Trim() + "的信访举报记录.xls";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {  
                    FileInfo mode = new FileInfo(Application.StartupPath + "\\word\\niban_jjkg.xls");
                    Excel.Application app = new Excel.Application();
                    if (app == null)
                    {
                        MessageBox.Show("您的电脑上未装Excel!或缺少Excel文件,请重新安装Excel");
                        return;
                    }

                    app.Application.DisplayAlerts = false;
                    app.Visible = false;
                    if (mode.Exists)
                    {
                        Excel.Workbook tworkbook;
                        Object missing = System.Reflection.Missing.Value;

                        app.Workbooks.Add(missing);
                        //调用模板
                        tworkbook = app.Workbooks.Open(mode.FullName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                        Excel.Worksheet tworksheet = (Excel.Worksheet)tworkbook.Sheets[1];

                        //
                        if (comboBoxxffs.SelectedIndex > -1)
                        {
                            tworksheet.Cells[2, 3] = comboBoxxffs.SelectedItem.ToString();
                        }
                        if (comboBoxxfaddress.SelectedIndex > -1)
                        {
                            tworksheet.Cells[2, 5] = comboBoxxfaddress.SelectedItem.ToString();
                        }
                        //被反映人
                        tworksheet.Cells[3, 3] = txtbname.Text;
                        tworksheet.Cells[3, 5] = txtbaddress.Text;
                        tworksheet.Cells[4, 5] = txtbzhiwu.Text;
                        tworksheet.Cells[4, 7] = comboBoxbjibie.Text;
                        //反映人
                        tworksheet.Cells[5, 3] = txtfname.Text;
                        tworksheet.Cells[5, 5] = txtfaddress.Text;
                        tworksheet.Cells[6, 5] = txtfzhiwu.Text;
                        tworksheet.Cells[6, 7] = txtfphone.Text;

                        tworksheet.SaveAs(saveFileDialog1.FileName, missing, missing, missing, missing, missing, missing, missing, missing, missing);

                        tworkbook.Close(false, mode.FullName, missing);
                        app.Workbooks.Close();
                        app.Quit();

                        tworkbook = null;
                        app = null;
                        //强制对所有代进行垃圾回收
                        GC.Collect();
                        if (MessageBox.Show("已导出,需要打开吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            try
                            {
                                System.Diagnostics.Process.Start(saveFileDialog1.FileName);
                            }
                            catch
                            {
                                MessageBox.Show("自动打开失败,请手动打开!", "提示");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("excel模板不存在,请联系管理员!", "提示");
                    }
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message, "提示");
                }
            } 

        }
根据界面到处excel表格

根据界面到处excel表格

上一篇:Fitness training


下一篇:java-->模拟Stack