code: def save_structure_res(res, save_folder, img_name, img_idx=0):
      excel_save_folder = os.path.join(save_folder, img_name)
      os.makedirs(excel_save_folder, exist_ok=True)
      res_cp = deepcopy(res)
      # save res
      with open(
          os.path.join(excel_save_folder, "res_{}.txt".format(img_idx)),
          "w",
          encoding="utf8",
      ) as f:
          for region in res_cp:
              roi_img = region.pop("img")
              f.write("{}\n".format(json.dumps(region)))
  
              if (
                  region["type"].lower() == "table"
                  and len(region["res"]) > 0
                  and "html" in region["res"]
              ):
                  excel_path = os.path.join(
                      excel_save_folder,
                      "{}_{}.xlsx".format(region["bbox"], img_idx),
                  )
                  to_excel(region["res"]["html"], excel_path)
              elif region["type"].lower() == "figure":
                  img_path = os.path.join(
                      excel_save_folder,
                      "{}_{}.jpg".format(region["bbox"], img_idx),
                  )
                  cv2.imwrite(img_path, roi_img)
  
imports: import os
  import sys
  import subprocess
  import cv2
  import json
  import numpy
  import time
  import logging
  from copy import deepcopy
  from ppocr.utils.utility import get_image_file_list, check_and_read
  from ppocr.utils.logging import get_logger
  from ppocr.utils.visual import draw_ser_results, draw_re_results
  from tools.infer.predict_system import TextSystem
  from ppstructure.layout.predict_layout import LayoutPredictor
  from ppstructure.table.predict_table import TableSystem, to_excel
  from ppstructure.utility import parse_args, draw_structure_result
label_desc: Use image node_id 1 for calling a global function with example usage: save_structure_res(res, save_folder, img_name, img_idx) without return types