예제 #1
0
파일: MainForm.cs 프로젝트: AESCR/DBCHM
        private void ExportToWord()
        {
            #region 引用Microsoft.Office.Interop.Word.dll导出word文档方法弃用,改为引用Aspose.Words.dll方法导出word文档
            //FormUtils.ShowProcessing("正在导出数据字典Word文档,请稍等......", this, arg =>
            //{
            //    try
            //    {
            //        System.Collections.Generic.List<TableDto> tableDtos = DBInstanceTransToDto();
            //        TryOpenXml.Text.WordUtils.ExportWordByMicrosoftOfficeInteropWord(DBUtils.Instance.Info.DBName, tableDtos);

            //        MessageBox.Show("生成数据库字典Word文档成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //    }
            //    catch (Exception ex)
            //    {
            //        LogUtils.LogError("DBCHM执行出错", Developer.MJ, ex);
            //    }

            //}, null);
            #endregion

            string         fileName = string.Empty;
            SaveFileDialog saveDia  = new SaveFileDialog();
            saveDia.Filter             = "Word files (*.doc)|*.doc";
            saveDia.Title              = "另存文件为";
            saveDia.CheckPathExists    = true;
            saveDia.AddExtension       = true;
            saveDia.AutoUpgradeEnabled = true;
            saveDia.DefaultExt         = ".doc";
            saveDia.InitialDirectory   = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            saveDia.OverwritePrompt    = true;
            saveDia.ValidateNames      = true;
            saveDia.FileName           = DBUtils.Instance.Info.DBName + "表结构信息.doc";
            if (saveDia.ShowDialog(this) == DialogResult.OK)
            {
                //System.Diagnostics.Process process;
                //if (IsExistProcess(Path.GetFileName(saveDia.FileName), out process))
                //{
                //    var dia = MessageBox.Show("文件已打开,导出前需关闭,是否继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                //    if (dia == DialogResult.OK)
                //    {
                //        process.Kill();
                //    }
                //}

                FormUtils.ShowProcessing("正在导出数据字典Word文档,请稍等......", this, arg =>
                {
                    try
                    {
                        System.Collections.Generic.List <TableDto> tableDtos = DBInstanceTransToDto();
                        TryOpenXml.Text.WordUtils.ExportWordByAsposeWords(saveDia.FileName, DBUtils.Instance.Info.DBName, tableDtos);

                        if (MessageBox.Show("生成数据库字典Word文档成功,是否打开?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            System.Diagnostics.Process.Start(saveDia.FileName);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogUtils.LogError("DBCHM执行出错", Developer.MJ, ex);
                    }
                }, null);
            }
        }