Exemplo n.º 1
0
        /// <summary>
        /// 执行合并
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OK_Click(object sender, RoutedEventArgs e)
        {
            ///list<object> 转换成正确类型
            IList <FileNameCustom> currencies = model.FileNameCustoms;

            model.SetPaths(currencies);


            int count = model.FileNameCustoms.Count;

            for (int a = 0; a < count; a++)
            {
                FileNameCustom custom = model.FileNameCustoms[a];
                if (!Utils.CheckFileExists(custom.FilePath))
                {
                    model.FileNameCustoms.RemoveAt(a);
                    a--;
                    count--;
                }
            }
            MyAction myAction = new MyAction(new Action(() =>
            {
                ExcelWrite.MergeExcel(model);
            }), "合并表格", "完成");

            CommHelper.FastTask(myAction);
            SoftwareConfig.SaveRedis(ExcelMergeModel.RedisKey, model);
        }
Exemplo n.º 2
0
        private void OK_Click(object sender, RoutedEventArgs e)
        {
            bool?  isCopy = IsCopyRadio.IsChecked;
            string tem;

            if (isCopy.Value)
            {
                tem = "复制";
            }
            else
            {
                tem = "更名或者移动";
            }
            int successCount          = 0;
            int falseCount            = 0;
            var fileReplaceNameModels = filePagerPage.GetAllList <FileReplaceNameModel>();

            if (fileReplaceNameModels.Count > 0)
            {
                if (MessageBoxCustom.MessageBoxShow("你将" + tem + fileReplaceNameModels.Count + " 个文件"))
                {
                    foreach (FileReplaceNameModel model in fileReplaceNameModels)
                    {
                        WaitFormCustom.ShowCustom();
                        string path     = model.FilePath;
                        string saveName = model.NewFileName;
                        string saveDir  = Path.GetDirectoryName(saveName);
                        if (saveDir == "")
                        {
                            model.Success = false;
                            continue;
                        }
                        if (!Utils.CheckDirExists(saveDir))
                        {
                            Directory.CreateDirectory(saveDir);
                        }
                        if (Utils.CheckFileExists(path))
                        {
                            if (isCopy.Value)
                            {
                                File.Copy(path, saveName, true);
                            }
                            else
                            {
                                File.Move(path, saveName);
                            }
                            successCount++;
                            model.Success = true;
                        }
                        else
                        {
                            model.Success = false;
                            falseCount++;
                        }
                    }
                    WaitFormCustom.CloseWaitForm("成功:" + successCount + " 个文件,失败:" + falseCount + " 个文件");
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 替换word中的内容
        /// </summary>
        /// <param name="replaceViewModels"></param>
        /// <param name="fileNameCustom"></param>
        public static void ReplaceText(IList <ReplaceViewModel> replaceViewModels, FileNameCustom fileNameCustom)
        {
            string path = fileNameCustom.FilePath;

            if (Utils.CheckFileExists(path))
            {
                Document doc = new Document(path);
                ReplaceText(replaceViewModels, doc);

                doc.Save(path);
            }
        }
Exemplo n.º 4
0
        private void AddExcelFile_Click(object sender, RoutedEventArgs e)
        {
            string path = FileUtils.SelectSingleExcelFile();

            if (Utils.CheckFileExists(path))
            {
                IList <string> paths = SheetToList(path);
                if (paths != null)
                {
                    AddFile(paths);
                }
            }
        }
Exemplo n.º 5
0
        private void OpenExcel_Click(object sender, RoutedEventArgs e)
        {
            string path = FileUtils.SelectSingleExcelFile();

            if (Utils.CheckFileExists(path))
            {
                Dictionary <string, string> dic = SheetToDic(path);
                if (dic != null)
                {
                    IList <FileReplaceNameModel> fileReplaceNameModels = new List <FileReplaceNameModel>();
                    foreach (string srcPath in dic.Keys)
                    {
                        FileReplaceNameModel model = new FileReplaceNameModel {
                            FilePath = srcPath, NewFileName = dic[srcPath]
                        };
                        fileReplaceNameModels.Add(model);
                    }
                    filePagerPage.AddObject(fileReplaceNameModels);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 内容,1为开始,2为包含,3结束,4相等,不填为相等
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectRepalceFile_Click(object sender, RoutedEventArgs e)
        {
            IList <string> paths = FileUtils.SelectExcelFiles();

            if (Utils.CheckListExists(paths))
            {
                IList <ReplaceViewModel> list = new List <ReplaceViewModel>();
                foreach (string path in paths)
                {
                    if (Utils.CheckFileExists(path))
                    {
                        ISheet sheet = ExcelRead.ReadExcelSheet(path, 0);
                        foreach (IRow row in sheet)
                        {
                            var replaceModel = new ReplaceViewModel();
                            for (int a = 0; a < 3; a++)
                            {
                                ICell cell = row.GetCell(a);
                                if (cell == null || cell.CellType == CellType.Blank)
                                {
                                    if (a == 3)
                                    {
                                        cell = row.CreateCell(a);
                                        cell.SetCellValue(4);
                                    }
                                    break;
                                }
                                cell.SetCellType(CellType.String);
                                string value = cell.StringCellValue;
                                switch (a)
                                {
                                case 0:
                                    replaceModel.OldText = value;
                                    break;

                                case 1:
                                    replaceModel.NewText = value;
                                    break;

                                case 2:
                                    int gx;
                                    if (int.TryParse(value, out gx))
                                    {
                                        switch (gx)
                                        {
                                        case 0:
                                            replaceModel.StrRelation = MyUtils.StrRelation.StartsWith;
                                            break;

                                        case 1:
                                            replaceModel.StrRelation = MyUtils.StrRelation.Contains;
                                            break;

                                        case 2:
                                            replaceModel.StrRelation = MyUtils.StrRelation.EndsWith;
                                            break;

                                        case 3:
                                            replaceModel.StrRelation = MyUtils.StrRelation.Equals;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        replaceModel.StrRelation = MyUtils.StrRelation.Equals;
                                    }

                                    break;
                                }
                            }
                            list.Add(replaceModel);
                        }
                    }
                }
                replacePagerPage.AddObject(list);
            }
        }