.jsprepare日志[错误]:-phpCosnole日志

让这个应用程序使用 OCR 读取图像文本并将其转换为 JSON 数组,然后将其写入 HTML 工作表并使用 phpspreedsheet 将其导出为 excel 工作表,该应用程序到目前为止运行良好,直到我使用它并且在Javascript函数不再起作用后遗漏了一些东西,所以应该可以通过[Change.php]将表格内容写入Excel文件

prepare.js

function readFile(fileName) {
  console.log({ fileName });
  return await Tesseract.recognize(fileName, 'ara', {
  
    logger: m => console.log(m)
  });
}
function parseDataFromTextAndPropertyNames(text, propertyNames) {
  console.log({ text, propertyNames });
  return propertyNames
    .reduce((table, key) =>
      Object.assign(table, {
        [ key ]: RegExp(`${ key }\W+(\w+)`)
          .exec(text)?.[1] ?? ''
      }), {});
}
function writeParsedTextDataAsJSON(fileName, table) {
  console.log({ table });
   JSON.stringify({ table });
  // fake it ...
  return (await new Promise(resolve =>
    setTimeout(() => {
      console.log({ fileName, json: JSON.stringify({ table }) });
      resolve({ success: true });

    }, 1500)
  ));
}
console.log('... running ...');
function start(filenames) {
  const { data: { text } } = await readFile(filenames);
  const data = await
    parseDataFromTextAndPropertyNames(text, ['نقطة الخدمة', 'رقم العداد']);
 document.getElementById("dvjson").innerHTML = JSON.stringify(data, undefined, 4);
 const final = [JSON.stringify(data)];
 const ff = [JSON.parse(final)];
 constructTable('#table',ff);
 htmlstring = getElementById('table').innerHTML();
$.post('change.php', {string:htmlstring}).done(function(response){
      alert("done");
});
  console.log({ result });
}
// construct JSON array to HTML Table
 function constructTable(selector,data) {
             
            // Getting the all column names
            var cols = Headers(data, selector); 
  

图片[1]-.jsprepare日志[错误]:-phpCosnole日志-唐朝资源网

// Traversing the JSON data for (var i = 0; i < data.length; i++) { var row = $(''); for (var colIndex = 0; colIndex < cols.length; colIndex++) { var val = data[i][cols[colIndex]]; // If there is any key, which is matching // with the column name if (val == null) val = ""; row.append($('').html(val)); } // Adding each row to the table $(selector).append(row); } } function Headers(data, selector) { var columns = []; var header = $(''); for (var i = 0; i < data.length; i++) { var row = data[i]; for (var k in row) { if ($.inArray(k, columns) == -1) { columns.push(k); // Creating the header header.append($('').html(k)); } } } // Appending the header to the table $(selector).append(header); return columns; } setTimeout(function() { document.getElementById("loadspinne").style.display ="none"; document.getElementById("message").style.display = "block"; }, 8000);

prepare.php


<?php
if (!empty($target_file)){
    echo 'start("'.$target_file.'")';
}
?>


    
    
    
    Document

图片[2]-.jsprepare日志[错误]:-phpCosnole日志-唐朝资源网

تم تكوين كشف بنجاح

更改.php

use PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXlsx;
use PhpOfficePhpSpreadsheetReaderIReader;
$htmlString = $_GET[‘htmlstring’];
$reader = new PhpOfficePhpSpreadsheetReaderHtml();
$spreadsheet = $reader->loadFromString($htmlString);
$writer = PhpOfficePhpSpreadsheetIOFactory::createWriter($spreadsheet, ‘Xls’);
$writer->save(‘ddd.xls’);
$spreadsheet = PhpOfficePhpSpreadsheetIOFactory::load(“ddd.xls”);
$sheet = $spreadsheet->getActiveSheet();
$sheet->getColumnDimension(‘A’)->setAutoSize(false);
$sheet->getColumnDimension(‘B’)->setAutoSize(false);
$sheet->getColumnDimension(‘A’)->setWidth(16);
$sheet->getColumnDimension(‘B’)->setWidth(13);
$sheet->getStyle(‘A1:B1’)->getFont()
->setName(‘Arial’)
->setSize(14)
->setBold(true);
$writer = new Xlsx($spreadsheet);
$writer->save(‘ddd.xlsx’);
// header(‘Location: ddd.xlsx’);
?>

Cosnole 日志 [错误]:-

Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules (at prepare.js:4:10)
upload.php:4 Uncaught ReferenceError: start is not defined
    at upload.php:4:9
(anonymous) @ upload.php:4

© 版权声明
THE END
喜欢就支持一下吧
点赞250 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片