支持pdf/图片/表格等格式文件转换成excel文件或其他格式文件一、图像识别过程@Testvoidrequest_002()throwsFileNotFoundException{//读取文件夹StringfileSource="C:\\Users\\管理员\\Desktop\\work\\20221217\\invoice\\pageFiles";StringfileName=fileSource+"\\excelFile\\"+"note_"+DateUtil.format(DateUtil.date(),DatePattern.PURE_DATETIME_PATTERN)+".xlsx";longbeginTime=System.currentTimeMillis();列表<文件>files=FileUtil.loopFiles(fileSource);ListgetList=newArrayList<>();对于(文件文件:文件){控制台。log("开始识别文件:{}",file.getName());//请求参数RecognizeInvoiceRequestrequest=newRecognizeInvoiceRequest();运行时选项runtime=newRuntimeOptions();request.body=newFileInputStream(file.getPath());尝试{RecognizeInvoiceResponse响应=客户端().recognizeInvoiceWithOptions(请求,运行时);Console.log("文件:{}识别成功",file.getName());JSONObjectjsonObject=JSONObject.parseObject(response.body.data);字符串数据=jsonObject。getString("数据");Console.log("数据:=>{}",数据);InvoiceVOinvoiceData=JSONUtil.toBean(data,InvoiceVO.class);getList.add(发票数据);}catch(TeaExceptionerror){Console.log(error.message);}catch(Exception_error){TeaExceptionerror=newTeaException(_error.getMessage(),_error);控制台日志(错误信息);}}//执行writeif(getList.size()>0){Console.log("开始写入excel文件~");toExcel(getList,文件名);Console.log("文件:{}写入成功!总时间:{}秒",fileName,(System.currentTimeMillis()-开始时间)/1000);}}接下来写出excel文件privatevoidtoExcel(ListgetList,StringfilePathName){//合并单元格(开始列,结束列)intbeforeRow=1;//不合并的列ListunMergeList=newArrayList<>();//写入文件列表ListdataList=newArrayList<>();for(inti=0;idetails=invoiceVO.getInvoiceDetails();for(InvoiceDetailsdetail:details){InvoiceVOvo=newInvoiceVO();BeanUtil.copyProperties(invoiceVO,vo);BeanUtil.copyProperties(细节,vo);dataList.add(vo);}//防止合并处理intdetailSize=details.size();intafterRowSize=beforeRow+细节尺寸;treeMap.put(beforeRow,afterRowSize-1);如果(detailSize<=1){unMergeList.add(beforeRow);}beforeRow=afterRowSize;}//写入文件ExcelWriterwriter=ExcelUtil.getWriter(filePathName);//标题addHeader(writer);//自动列宽writer.autoSizeColumnAll();treeMap.forEach((k,v)->{//一行细节不会合并if(!unMergeList.contains(k)){for(inti=0;i<22;i++){//merge:起始列号,结束列号,起始行号,结束行号,合并数据(自动填充输出数据列表),是否保持原样式writer.merge(k,v,i,i,"合并数据“,错误的);}}});writer.setOnlyAlias(true);writer.write(dataList,true);writer.close();}最后,效果图中更具体的功能实现微/电:16717696360