コード例 #1
0
        // 点击“仅导出需要翻译行的Excel文件”按钮
        private void btnGenerateNeedTranslateExcelFile_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.ValidateNames = true;
            dialog.Title         = "请选择保存Excel文件的路径";
            dialog.Filter        = "Excel files (*.xlsx)|*.xlsx";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string filePath = dialog.FileName;
                // 检查要导出的Excel文件是否已存在且正被其他程序使用
                if (Utils.GetFileState(filePath) == FileState.IsOpen)
                {
                    MessageBox.Show("要覆盖的Excel文件正被其他程序打开,请关闭后重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                txtNeedTranslateExcelPath.Text = filePath;
                string errorString   = null;
                string promptMessage = null;
                if (ExportExcelFileHelper.ExportNeedTranslateExcelFile(filePath, out errorString, out promptMessage) == true)
                {
                    string text = string.Format("已将新增Key、翻译变动Key所在行信息导出至{0}", filePath);
                    if (promptMessage != null)
                    {
                        text = string.Concat(text, "\n\n", promptMessage);
                    }

                    if (MessageBox.Show(text, "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        System.Diagnostics.Process.Start("explorer.exe", Path.GetDirectoryName(filePath));
                    }
                }
                else
                {
                    if (errorString != null)
                    {
                        errorString = string.Concat("导出新增Key、翻译变动Key所在行信息至新建Excel文件失败:", errorString);
                        MessageBox.Show(errorString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (promptMessage != null)
                    {
                        if (MessageBox.Show(promptMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                        {
                            System.Diagnostics.Process.Start("explorer.exe", Path.GetDirectoryName(filePath));
                        }
                    }
                }
            }
        }
コード例 #2
0
        // 点击“合并翻译完的Excel文件”按钮
        private void btnMergeTranslatedExcelFile_Click(object sender, EventArgs e)
        {
            // 检查是否指定了合法的合并后的Excel文件的保存路径
            string mergedExcelSavePath = txtMergedExcelPath.Text.Trim();

            if (string.IsNullOrEmpty(mergedExcelSavePath))
            {
                MessageBox.Show("必须输入合并后的Excel文件的保存路径", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!AppValues.EXCEL_FILE_EXTENSION.Equals(Path.GetExtension(mergedExcelSavePath), StringComparison.CurrentCultureIgnoreCase))
            {
                MessageBox.Show(string.Format("合并后的Excel文件扩展名必须为{0}", AppValues.EXCEL_FILE_EXTENSION), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // 检查要导出的后的Excel文件是否已存在且正被其他程序使用
            if (Utils.GetFileState(mergedExcelSavePath) == FileState.IsOpen)
            {
                MessageBox.Show("要覆盖的合并后的Excel文件正被其他程序打开,请关闭后重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // 检查是否指定了合法的翻译完的Excel文件
            string translatedExcelPath = txtTranslatedExcelPath.Text.Trim();

            if (string.IsNullOrEmpty(translatedExcelPath))
            {
                MessageBox.Show("必须输入翻译完的Excel文件所在路径", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            FileState fileState = Utils.GetFileState(translatedExcelPath);

            if (fileState == FileState.Inexist)
            {
                MessageBox.Show("输入的翻译完的Excel文件所在路径不存在,建议点击\"选择\"按钮进行文件选择", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!AppValues.EXCEL_FILE_EXTENSION.Equals(Path.GetExtension(translatedExcelPath), StringComparison.CurrentCultureIgnoreCase))
            {
                MessageBox.Show(string.Format("本工具仅支持读取扩展名为{0}的Excel文件", AppValues.EXCEL_FILE_EXTENSION), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (fileState == FileState.IsOpen)
            {
                MessageBox.Show("指定的翻译完的Excel文件正被其他软件打开,请关闭后重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // 检查选择的翻译完的Excel文件和新版母表不能为同一个文件
            string translatedExcelFileFullPath = Path.GetFullPath(translatedExcelPath);

            if (translatedExcelFileFullPath.Equals(AppValues.ExcelFullPath))
            {
                MessageBox.Show("你选择的翻译完的Excel文件和新版母表是同一个文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // 解析翻译完的Excel文件
            string        errorString         = null;
            LangExcelInfo translatedExcelInfo = AnalyzeHelper.AnalyzeLangExcelFile(translatedExcelPath, AppValues.CommentLineStartChar, out errorString);

            if (errorString != null)
            {
                MessageBox.Show(string.Format("选定的翻译完后的Excel文件存在以下错误,请修正后重试\n\n{0}", errorString), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // 检查翻译完的Excel文件与新版母表的主语言名称是否相同
            string excelDefaultLanguageName           = AppValues.LangExcelInfo.DefaultLanguageInfo.Name;
            string translatedExcelDefaultLanguageName = translatedExcelInfo.DefaultLanguageInfo.Name;

            if (!excelDefaultLanguageName.Equals(translatedExcelDefaultLanguageName))
            {
                MessageBox.Show(string.Format("翻译完的Excel文件与新版母表的主语言名称不同,无法进行对比,请统一后重试\n新版母表中主语言名称:{0},翻译完的Excel文件中主语言名称:{1}", excelDefaultLanguageName, translatedExcelDefaultLanguageName), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // 记录翻译完的Excel文件中存在的外语名
            List <string> translatedExcelFileOtherLanguageNames = new List <string>();
            // 检查翻译完的Excel文件中的外语在新版母表中是否都存在
            List <string> inexistentOtherLanguageName = new List <string>();

            foreach (string otherLanguageName in translatedExcelInfo.OtherLanguageInfo.Keys)
            {
                if (!AppValues.LangExcelInfo.OtherLanguageInfo.ContainsKey(otherLanguageName))
                {
                    inexistentOtherLanguageName.Add(otherLanguageName);
                }

                translatedExcelFileOtherLanguageNames.Add(otherLanguageName);
            }
            if (inexistentOtherLanguageName.Count > 0)
            {
                MessageBox.Show(string.Format("翻译完后的Excel文件中存在以下新版母表中不存在的外语名,无法进行合并\n{0}", Utils.CombineString <string>(inexistentOtherLanguageName, ",")), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // 检查完毕执行合并功能并生成合并结果报告文件(保存路径与合并后的Excel文件相同)
            string reportExcelSavePath = Utils.CombinePath(Path.GetDirectoryName(mergedExcelSavePath), string.Format("合并报告 {0:yyyy年MM月dd日 HH时mm分ss秒}.xlsx", DateTime.Now));

            ExportExcelFileHelper.ExportMergedExcelFile(mergedExcelSavePath, reportExcelSavePath, AppValues.LangExcelInfo, translatedExcelInfo, translatedExcelFileOtherLanguageNames, out errorString);
            if (errorString == null)
            {
                DialogResult dialogResult = MessageBox.Show(string.Format("合并操作成功\n合并后的Excel文件存储路径为{0}\n报告文件存储路径为{1}\n\n点击“确定”按钮后将自动打开此报告文件", mergedExcelSavePath, reportExcelSavePath), "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (dialogResult == DialogResult.OK)
                {
                    System.Diagnostics.Process.Start(reportExcelSavePath);
                }
            }
            else
            {
                errorString = string.Concat("合并操作失败:", errorString);
                MessageBox.Show(errorString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
        // 点击“生成对比Excel文件”按钮
        private void btnGenarateComparedExcelFile_Click(object sender, EventArgs e)
        {
            // 如果选择的标注新增Key、主语言翻译变动所在行的背景色相同弹出警告对话框
            Color colorForAdd    = lblShowColorForAdd.BackColor;
            Color colorForChange = lblShowColorForChange.BackColor;

            if (colorForAdd == colorForChange)
            {
                if (MessageBox.Show("选择的标注新增Key、主语言翻译变动所在行的背景色相同,不容易分辨,建议选择不同的背景色\n\n确实要采用相同的颜色吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    return;
                }
            }
            // 如果输入的用于填充空单元格(新增Key行的外语译文单元格)的字符串为纯空格弹出警告对话框
            string fillNullCellText = txtFillNullCellText.Text;

            if (!string.IsNullOrEmpty(fillNullCellText) && string.IsNullOrEmpty(fillNullCellText.Trim()))
            {
                if (MessageBox.Show("输入的用于填充未翻译的语种单元格的字符串为纯空格,不容易分辨,建议选用特殊字符\n\n确实要采用目前输入的纯空格字符串吗?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    return;
                }
            }

            // 选择保存路径并新建Excel文件
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.ValidateNames = true;
            dialog.Title         = "请选择保存Excel文件的路径";
            dialog.Filter        = "Excel files (*.xlsx)|*.xlsx";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string filePath = dialog.FileName;
                // 检查要导出的Excel文件是否已存在且正被其他程序使用
                if (Utils.GetFileState(filePath) == FileState.IsOpen)
                {
                    MessageBox.Show("要覆盖的Excel文件正被其他程序打开,请关闭后重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                txtComparedExcelPath.Text = filePath;
                string errorString   = null;
                string promptMessage = null;
                if (ExportExcelFileHelper.ExportComparedExcelFile(colorForAdd, colorForChange, fillNullCellText, filePath, out errorString, out promptMessage) == true)
                {
                    string text = string.Format("已将用指定背景色标注后的复制Excel母表导出至{0}", filePath);
                    if (promptMessage != null)
                    {
                        text = string.Concat(text, "\n\n", promptMessage);
                    }

                    if (MessageBox.Show(text, "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        System.Diagnostics.Process.Start("explorer.exe", Path.GetDirectoryName(filePath));
                    }
                }
                else
                {
                    if (errorString != null)
                    {
                        errorString = string.Concat("导出用指定背景色标注后的复制Excel母表失败:", errorString);
                        MessageBox.Show(errorString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (promptMessage != null)
                    {
                        if (MessageBox.Show(promptMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                        {
                            System.Diagnostics.Process.Start("explorer.exe", Path.GetDirectoryName(filePath));
                        }
                    }
                }
            }
        }