Example #1
0
 public static void SaveFilePath()
 {
     if (filePath != null)
     {
         TxtUtil.SaveToPath(configPath, filePath, false);
     }
 }
Example #2
0
    public static void ExportTxt(Dictionary <string, List <ISheet> > dictionary, string outputPath)
    {
        if (!Directory.Exists(outputPath))
        {
            Directory.CreateDirectory(outputPath);
        }
        DirectoryHelper.DelectContent(outputPath);

        foreach (var table in dictionary)
        {
            foreach (var sheet in table.Value)
            {
                try
                {
                    string textPath = Path.Combine(outputPath, sheet.SheetName + ".txt");
                    for (int i = 0; i < sheet.LastRowNum; i++)
                    {
                        IRow row = sheet.GetRow(i);
                        if (row == null)
                        {
                            Form1.Log(false, table.Key + "\t" + sheet.SheetName + "\t" + string.Format("第{0}行出错", i + 1) + "\n");
                        }
                        else
                        {
                            string line = "";
                            for (int j = 0; j < row.LastCellNum; j++)
                            {
                                ICell cell = row.GetCell(j);
                                try
                                {
                                    cell.GetCellValue();
                                    line += cell.GetCellValue().ToString().Replace("\n", "\\n").Replace("\n\r", "\\n") + (j == row.LastCellNum - 1 ? "" : "\t");
                                }
                                catch (Exception e)
                                {
                                    Form1.Log(false, table.Key + "\t" + sheet.SheetName + "\t" + string.Format("第{0}行第{1}列", i + 1, j + 1) + "\t" + e.Message + "\n");
                                    break;
                                }
                            }
                            TxtUtil.WriteToPath(textPath, line, true);
                        }
                    }
                    Form1.Log(true, sheet.SheetName + "\t表文件生成---------------->\tOK\n");
                }
                catch (Exception e)
                {
                    Form1.Log(false, sheet.SheetName + "\t表文件生成---------------->\tFlase\t" + e.Message + "\n");
                }
            }
        }
    }
Example #3
0
        public static FilePath LoadFilePath(Action callback)
        {
            try
            {
                filePath = TxtUtil.ReadFromPath <FilePath>(configPath);
            }
            catch
            {
                filePath = new FilePath();
            }
            callback?.Invoke();

            return(filePath);
        }
        //将需要OCR的文件复制到指定的文件中
        public void Execute(IJobExecutionContext context)
        {
            DirectoryInfo needOcrFolder = new DirectoryInfo(PathUtil.needOcrDestFilePath);

            if (needOcrFolder.GetFiles().Length >= SystemConstant.FILE_COUNT)  //
            {
                Console.WriteLine(DateTime.Now + ":需要ocr的目录中文件个数大于等于2,暂时不添加数据");
                return;
            }

            defaultDate = DateTime.Now;  //保存需要下载文件的时间
            try
            {
                //从接口获取需要ocr数据
                PdfData pdfData = HttpUtil.getPdfStreamDataByPipeLining(SystemConstant.LIMIT);
                foreach (PdfStream pdfInfo in pdfData.data)
                {
                    pdfInfo.program_name = SystemConstant.PROGRAMNAME;
                    String needOcrSourcePath = Path.Combine(PathUtil.tempSoucePath + Path.GetFileName(pdfInfo.pdf_path));
                    String remotePath        = "";
                    //微信文章跟其他类型的报告路径不一样
                    if (pdfInfo.doc_type == SystemConstant.ARTICLE_TYPE)
                    {
                        remotePath = Path.Combine(SystemConstant.ARICLE_PATH, pdfInfo.pdf_path);
                    }
                    else
                    {
                        remotePath = Path.Combine(SystemConstant.NORMAL_PATH, pdfInfo.pdf_path);
                    }
                    bool isExist = Ftp.checkFile(remotePath);
                    if (!isExist)
                    {
                        Console.WriteLine("服务器文件不存在");
                        pdfInfo.ocr_flag = OcrConstant.SERVER_FILE_NO_EXIST;
                        updatePdfStreamOcrStatus(pdfInfo);
                        return;
                    }
                    bool isSuccess = Ftp.donwload(needOcrSourcePath, remotePath);
                    if (!isSuccess)
                    {
                        pdfInfo.ocr_flag = OcrConstant.DOWNLOAD_FAIL;
                        Console.WriteLine("服务器文件下载失败");
                        updatePdfStreamOcrStatus(pdfInfo);
                        return;
                    }

                    if (!File.Exists(needOcrSourcePath))   //将标识更新为文件不存在 -2
                    {
                        pdfInfo.ocr_flag = OcrConstant.FILE_NO_EXIST;
                        updatePdfStreamOcrStatus(pdfInfo);
                        return;
                    }
                    fileNameVal++;
                    String fileName = Path.GetFileName(pdfInfo.pdf_path);  //获取文件名
                    //将文件名做一个映射关系
                    String descFilePath = Path.Combine(PathUtil.needOcrDestFilePath, fileNameVal + Path.GetExtension(fileName));
                    Console.WriteLine(descFilePath);
                    try
                    {
                        TxtUtil.addId(fileNameVal, pdfInfo.id, pdfInfo.doc_type, pdfInfo.pdf_path);
                        File.Move(needOcrSourcePath, descFilePath);
                        Console.WriteLine("复制成功...");
                        //插入数据库
                        Dao dao = new Dao();
                        Task.Run(() =>                                          //异步开始执行
                        {
                            //查询数据库是否存在这条记录
                            if (!dao.select(pdfInfo.id))
                            {
                                dao.insert(pdfInfo.id, pdfInfo.doc_type);
                            }
                            Console.WriteLine("插入数据库成功。。。");                   //异步执行完成标记
                        });
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("复制失败...");
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #5
0
 public PdfVal getPdfValByNum(String num)
 {
     return(TxtUtil.getId(int.Parse(num)));   //获取真实Id
 }