# blog_article

title: ChatGPT: 调用PC摄像头并可以实时标注识别到的多个二维码或条形码
created_time: 2023-03-24 03:41:45.808509
intro:
  好的，以下是一个基于 Python 的程序，可以调用 PC 摄像头并实时标注识别到的多个二维码或条形码。在实现这个程序之前，你需要安装 OpenCV 和 pyzbar 库。OpenCV 是一个开源的计算机视觉库，可以用于图像处理和计算机视觉任务，而 pyzbar 则是一个 Python 的二维码和条形码识别库，基于 ZBar 库实现。

html_text:
  <h4 id="h4-chatgpt-pc-"><a name="ChatGPT 生成 调用PC摄像头并可以实时标注识别到的多个二维码或条形码" class="reference-link"></a><span class="header-link octicon octicon-link"></span>ChatGPT 生成 调用PC摄像头并可以实时标注识别到的多个二维码或条形码</h4><pre><code class="lang-python">import cv2
  from pyzbar import pyzbar

  # 打开摄像头
  cap = cv2.VideoCapture(0)

  while True:
      # 读取摄像头的图像
      ret, image = cap.read()

      # 对图像进行灰度处理
      gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

      # 识别图像中的二维码和条形码
      barcodes = pyzbar.decode(gray)

      # 遍历每一个二维码或条形码，进行标注
      for barcode in barcodes:
          # 获取二维码或条形码的位置和内容
          (x, y, w, h) = barcode.rect
          barcodeData = barcode.data.decode("utf-8")

          # 在图像上绘制标注框和文字
          cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
          cv2.putText(image, barcodeData, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)

      # 显示处理后的图像
      cv2.imshow("Barcode Scanner", image)

      # 等待按下 ESC 键退出程序
      if cv2.waitKey(1) == 27:
          break

  # 关闭摄像头和窗口
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>

markdown_text:
  #### ChatGPT 生成 调用PC摄像头并可以实时标注识别到的多个二维码或条形码
  ````python
  import cv2
  from pyzbar import pyzbar

  # 打开摄像头
  cap = cv2.VideoCapture(0)

  while True:
      # 读取摄像头的图像
      ret, image = cap.read()

      # 对图像进行灰度处理
      gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

      # 识别图像中的二维码和条形码
      barcodes = pyzbar.decode(gray)

      # 遍历每一个二维码或条形码，进行标注
      for barcode in barcodes:
          # 获取二维码或条形码的位置和内容
          (x, y, w, h) = barcode.rect
          barcodeData = barcode.data.decode("utf-8")

          # 在图像上绘制标注框和文字
          cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
          cv2.putText(image, barcodeData, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)

      # 显示处理后的图像
      cv2.imshow("Barcode Scanner", image)

      # 等待按下 ESC 键退出程序
      if cv2.waitKey(1) == 27:
          break

  # 关闭摄像头和窗口
  cap.release()
  cv2.destroyAllWindows()
  ````


title: RouteBox NAT Forward
intro: 待整理
created_time: 2023-04-12 08:08:21.114293
html_text:
  <pre><code class="lang-bash">route add -net 192.168.1.0 netmask 255.255.255.0 dev eth1
  route add -net 192.168.56.0 netmask 255.255.255.0 dev eth0



  route add -net 192.168.1.0 netmask 255.255.255.0 dev eth1
  route add -net 192.168.0.0 netmask 255.255.255.0 dev eth0




  route add -net 192.168.2.0 netmask 255.255.255.0 dev eth0
  route del -net 192.168.2.0 netmask 255.255.255.0 dev eth0
  route del -net 192.168.2.0 netmask 255.255.255.0 dev eth1

  route add -net 192.168.0.0/24 netmask 255.255.255.0 dev eth0


  sudo route add default gw 192.168.0.1


  route del default gw 192.168.2.0 dev eth0

  route del -net 192.168.2.0 netmask 255.255.255.0 dev eth1



  sudo ip addr add 10.0.0.11/ dev eth1

  systemctl stop isc-dhcp-server
  systemctl restart isc-dhcp-server
  systemctl status isc-dhcp-server 

  sudo route add default gw 192.168.0.1

  route add -net 192.168.2.1/24 gw 192.168.0.0 eth1

  route add -net 192.168.2.1/24 gw 192.168.0.0 eth1


  route add -net 192.168.2.0/24 gw 192.168.0.0 eth1
  route add -net 192.168.2.1/24 gw 192.168.0.9 eth1

  route add default gw _gateway 0.0.0.0 eth0


  default         _gateway        0.0.0.0         UG        0 0          0 eth0

  route add -net 192.168.20.0 netmask 255.255.255.0 gw 192.168.10.1


  iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE


  iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  iptables -A INPUT -i eth1 -j ACCEPT
  iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
  iptables -A INPUT -i eth2 -j ACCEPT
  iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
  iptables -A OUTPUT -j ACCEPT


  iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
  iptables -A INPUT -i tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT



  route add -net 192.168.31.0 netmask 255.255.255.0 gw 192.168.112.5




  sudo vi /etc/netplan/01-installer-config.yaml





  vim /etc/dhcp/dhcpd.conf

  subnet 192.168.2.0 netmask 255.255.255.0 {
   range 192.168.2.10 192.168.2.99;
   option domain-name-servers 192.168.10.8,192.168.11.8;
   option domain-name "splend";
   option subnet-mask 255.255.255.0;
   option routers 192.168.3.1;
   option broadcast-address 192.168.3.255;
   default-lease-time 600;
   max-lease-time 7200;
  }

  option domain-name-servers 114.114.114.114,8.8.8.8,
  option domain-name "splend";





  subnet 192.168.2.0 netmask 255.255.255.0 {
     range 192.168.2.100 192.168.2.200;
     option domain-name-servers 114.114.114.114,8.8.8.8;
     option domain-name "splend";
     option routers 192.168.2.1;
     option broadcast-address 192.168.2.255;
     default-lease-time 600;
     max-lease-time 7200;
  }

  subnet 192.168.3.0 netmask 255.255.255.0 {
     range 192.168.3.100 192.168.3.200;
     option domain-name-servers 114.114.114.114,8.8.8.8;
     option domain-name "splend";
     option routers 192.168.3.1;
     option broadcast-address 192.168.3.255;
     default-lease-time 600;
     max-lease-time 7200;
  }



  iptables -A FORWARD -i eth1 -o tun0 -j ACCEPT
  iptables -A FORWARD -i tun0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT


  iptables -A FORWARD -i eth2 -o tun0 -j ACCEPT
  iptables -A FORWARD -i tun0 -o eth2 -m state --state ESTABLISHED,RELATED -j ACCEPT
  iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

  apt install iptables-persistent


  iptables-save &gt; /etc/iptables/rules.v4
  </code></pre>
  <p><img src="/upload/files/png/21c03b118d6c203afe835cae4949e603.png" alt="">
  <p><img src="/upload/files/png/ba07dabb62d2ecdb334ab22c9ee7d76c.png" alt="">
  <p><img src="/upload/files/png/416963effd401873767c5124f45fa7cd.png" alt="">

markdown_text:
  ```bash
  route add -net 192.168.1.0 netmask 255.255.255.0 dev eth1
  route add -net 192.168.56.0 netmask 255.255.255.0 dev eth0



  route add -net 192.168.1.0 netmask 255.255.255.0 dev eth1
  route add -net 192.168.0.0 netmask 255.255.255.0 dev eth0




  route add -net 192.168.2.0 netmask 255.255.255.0 dev eth0
  route del -net 192.168.2.0 netmask 255.255.255.0 dev eth0
  route del -net 192.168.2.0 netmask 255.255.255.0 dev eth1

  route add -net 192.168.0.0/24 netmask 255.255.255.0 dev eth0


  sudo route add default gw 192.168.0.1


  route del default gw 192.168.2.0 dev eth0

  route del -net 192.168.2.0 netmask 255.255.255.0 dev eth1



  sudo ip addr add 10.0.0.11/ dev eth1

  systemctl stop isc-dhcp-server
  systemctl restart isc-dhcp-server
  systemctl status isc-dhcp-server 

  sudo route add default gw 192.168.0.1

  route add -net 192.168.2.1/24 gw 192.168.0.0 eth1

  route add -net 192.168.2.1/24 gw 192.168.0.0 eth1


  route add -net 192.168.2.0/24 gw 192.168.0.0 eth1
  route add -net 192.168.2.1/24 gw 192.168.0.9 eth1

  route add default gw _gateway 0.0.0.0 eth0


  default         _gateway        0.0.0.0         UG        0 0          0 eth0

  route add -net 192.168.20.0 netmask 255.255.255.0 gw 192.168.10.1


  iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE


  iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  iptables -A INPUT -i eth1 -j ACCEPT
  iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
  iptables -A INPUT -i eth2 -j ACCEPT
  iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
  iptables -A OUTPUT -j ACCEPT


  iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
  iptables -A INPUT -i tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT



  route add -net 192.168.31.0 netmask 255.255.255.0 gw 192.168.112.5


   
   
  sudo vi /etc/netplan/01-installer-config.yaml





  vim /etc/dhcp/dhcpd.conf

  subnet 192.168.2.0 netmask 255.255.255.0 {
   range 192.168.2.10 192.168.2.99;
   option domain-name-servers 192.168.10.8,192.168.11.8;
   option domain-name "splend";
   option subnet-mask 255.255.255.0;
   option routers 192.168.3.1;
   option broadcast-address 192.168.3.255;
   default-lease-time 600;
   max-lease-time 7200;
  }

  option domain-name-servers 114.114.114.114,8.8.8.8,
  option domain-name "splend";





  subnet 192.168.2.0 netmask 255.255.255.0 {
     range 192.168.2.100 192.168.2.200;
     option domain-name-servers 114.114.114.114,8.8.8.8;
     option domain-name "splend";
     option routers 192.168.2.1;
     option broadcast-address 192.168.2.255;
     default-lease-time 600;
     max-lease-time 7200;
  }

  subnet 192.168.3.0 netmask 255.255.255.0 {
     range 192.168.3.100 192.168.3.200;
     option domain-name-servers 114.114.114.114,8.8.8.8;
     option domain-name "splend";
     option routers 192.168.3.1;
     option broadcast-address 192.168.3.255;
     default-lease-time 600;
     max-lease-time 7200;
  }



  iptables -A FORWARD -i eth1 -o tun0 -j ACCEPT
  iptables -A FORWARD -i tun0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT


  iptables -A FORWARD -i eth2 -o tun0 -j ACCEPT
  iptables -A FORWARD -i tun0 -o eth2 -m state --state ESTABLISHED,RELATED -j ACCEPT
  iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

  apt install iptables-persistent


  iptables-save > /etc/iptables/rules.v4
  ```
  ![](/upload/files/png/21c03b118d6c203afe835cae4949e603.png)

  ![](/upload/files/png/ba07dabb62d2ecdb334ab22c9ee7d76c.png)

  ![](/upload/files/png/416963effd401873767c5124f45fa7cd.png)


title: 代码记录: 三个excel合并 Copy HLink 整合输出
intro: 代码记录: 三个excel合并 Copy HLink 整合输出
created_time: 2023-05-15 00:32:25.877607
html_text:
  <pre><code class="lang-python">import copy
  import random

  import openpyxl
  from openpyxl import Workbook
  from openpyxl.styles import Font

  file1 = r'C:\Users\chaojie\Desktop\接口\API\工作表 在 SAIC-HY_智能制造数字化项目_MOM系统与底盘&amp;总装中控详细对接会议纪要-20230328.xlsx'
  file2 = r'C:\Users\chaojie\Desktop\接口\API\工作表 在 SAIC-HY_智能制造数字化项目_MOM系统与焊装中控详细对接会议纪要-20230323(1).xlsx'
  file3 = r'C:\Users\chaojie\Desktop\接口\API\工作表 在 SAIC-HY_智能制造数字化项目_MOM系统与涂装中控详细对接会议纪要-20230327(1).xlsx'
  file_list = [file1, file2, file3]
  wb = Workbook()
  to_name = 'API_DOC_{0}.xlsx'.format(random.randint(100, 10000))

  api_sheet = wb.create_sheet(title="接口目录")

  header = ['接口代码', '接口名称', '接口描述', '源系统', '目标系统', '消息协议']

  row_data = []

  sheet_code = []


  def get_sheet_name(code, idx):
      global sheet_code
      for item in sheet_code:
          if item['code'] == code and item['wb'] == idx:
              return item['sheet']
      return None


  def get_sheet(idx):
      items = []
      global sheet_code
      for item in sheet_code:
          if item['wb'] == idx:
              items.append(item)
      return items


  def get_row(code):
      global row_data
      for row in row_data:
          if row[0] == code:
              return row
      return None


  def get_row_already(data_list, code):
      for row in data_list:
          if row[1] == code:
              return True
      return False


  def get_all_work():
      data_list = []
      serial = 0
      for f_name in file_list:
          workbook = openpyxl.load_workbook(f_name)
          sheet1 = workbook['接口目录']
          rows = sheet1.max_row
          # 获取工作表总列数
          cols = sheet1.max_column
          # sheet_code.append(
          #     {'code': cell_value, 'wb': file_list.index(f_name),
          #      'sheet': str(sheet1.cell(row=row_index, column=i).hyperlink.location).split('!')[0]})

          for row_index in range(4, rows):
              sheet_obj = {'code': None, 'wb': file_list.index(f_name),
                           'sheet': None, 'sheet_name': None}
              is_hl_obj = False
              row_data = []
              for i in range(1, cols):
                  cell_value = sheet1.cell(row=row_index, column=i).value
                  if i == 6:
                      if (cell_value is None or cell_value == '') or get_row_already(data_list, cell_value):
                          break
                      serial += 1
                      if (serial + 1) &gt; 10:
                          row_data.append('IF_IOT_0' + str(serial))
                      else:
                          row_data.append('IF_IOT_00' + str(serial))

                      row_data.append(cell_value)
                      hl_obj = sheet1.cell(row=row_index, column=i).hyperlink
                      if hl_obj:
                          sheet_obj['code'] = row_data[0]
                          sheet_obj['sheet'] = str(sheet1.cell(row=row_index, column=i).hyperlink.location).split('!')[0]
                          sheet_obj['sheet_name'] = f"{row_data[0]}_{cell_value}".replace(
                              '/', ' ')
                          is_hl_obj = True
                  if i == 7:
                      row_data.append(cell_value)
                  if i == 11:
                      row_data.append(cell_value)
                  if i == 13:
                      row_data.append(cell_value)
                  if i == 19:
                      row_data.append(cell_value)

              if len(row_data) &gt; 0:
                  data_list.append(row_data)
              if is_hl_obj:
                  sheet_code.append(sheet_obj)
      # for idx in range(0, len(data_list)):
      #     if idx &gt; 8:
      #         data_list[idx].insert(0, 'IF_IOT_0' + str(idx + 1))
      #     else:
      #         data_list[idx].insert(0, 'IF_IOT_00' + str(idx + 1))
      return data_list


  def save_to_sheet1():
      global row_data
      api_sheet.append(header)
      for row in row_data:
          api_sheet.append(row)
      for row in range(0, len(row_data)):
          cell = api_sheet.cell(row=row + 2, column=1)
          sheet_name = f"{api_sheet.cell(row=row + 2, column=1).value}_{api_sheet.cell(row=row + 2, column=2).value}".replace(
              '/', ' ')
          link = f"{to_name}#{sheet_name}!A1"
          if cell is not None:
              cell.hyperlink = (link)
              cell.style = 'Hyperlink'
      # set link


  def generate():
      for f_name in file_list:
          wb1 = openpyxl.load_workbook(f_name)
          file_idx = file_list.index(f_name)
          sheets = get_sheet(file_idx)
          for sheet_obj in sheets:
              rows = get_row(sheet_obj['code'])
              sheet = wb.create_sheet(sheet_obj['sheet_name'])
              sheet.column_dimensions['K'].width = 120
              sheet.column_dimensions['L'].width = 50
              sheet.column_dimensions['M'].width = 50
              sheet.column_dimensions['E'].width = 80

              sheet['a1'] = '接口代码'
              sheet['a2'] = '接口名称'
              sheet['a1'].font = Font(bold=True)
              sheet['a2'].font = Font(bold=True)
              sheet['b1'] = rows[0]
              sheet['b2'] = rows[1]
              sheet['b1'].font = Font(bold=True)
              sheet['b2'].font = Font(bold=True)

              sheet['a3'] = '调用方   '
              sheet['a4'] = '被调用方  '
              sheet['a5'] = '通讯方式  '
              sheet['a6'] = '请求地址  '
              sheet['a7'] = '说明     '

              sheet['b3'] = rows[3]
              sheet['b4'] = rows[4]
              sheet['b5'] = rows[5]
              sheet['b6'] = ''
              sheet['b7'] = rows[2]
              sheet['d1'] = '返回'
              link = f"{to_name}#接口目录!A1"
              sheet['d1'].hyperlink = (link)
              sheet['d1'].style = 'Hyperlink'
              api_sheet = None
              try:
                  api_sheet = wb1.get_sheet_by_name(sheet_obj['sheet'])
              except KeyError as ke:
                  pass
              if api_sheet is None:
                  pass
              else:
                  mr = api_sheet.max_row
                  mc = api_sheet.max_column
                  for i in range(5, mr + 1):
                      for j in range(1, mc + 1):

                          c = api_sheet.cell(row=i, column=j)
                          sheet.cell(row=i + 5, column=j).value = c.value
                          sheet.cell(row=i + 5, column=j).fill = copy.copy(c.fill)

                          if c.has_style:
                              sheet.cell(row=i + 5, column=j)._style = copy.copy(c._style)
                              sheet.cell(row=i + 5, column=j).font = copy.copy(c.font)
                              sheet.cell(row=i + 5, column=j).border = copy.copy(c.border)
                              sheet.cell(row=i + 5, column=j).fill = copy.copy(c.fill)
                              sheet.cell(row=i + 5, column=j).number_format = copy.copy(c.number_format)
                              sheet.cell(row=i + 5, column=j).protection = copy.copy(c.protection)
                              sheet.cell(row=i + 5, column=j).alignment = copy.copy(c.alignment)
                  # area1 = CellRange("c11:c28")  # area being copied
                  # area2 = CellRange("d12:d28")  # area being copied
                  # area3 = CellRange("c24:c28")  # area being copied
                  # area4 = CellRange("d24:d28")  # area being copied

                  sheet.merge_cells(range_string='c11:c28')
                  sheet.merge_cells(range_string='d11:d14')
                  sheet.merge_cells(range_string='d15:d28')
                  sheet.merge_cells(range_string='c29:c33')
                  sheet.merge_cells(range_string='d29:d33')


  if __name__ == '__main__':
      row_data = get_all_work()
      print(row_data)
      save_to_sheet1()
      print(sheet_code)
      # print(len(sheet_code))
      generate()
      wb.save(to_name)
  </code></pre>

markdown_text:
  ```python
  import copy
  import random

  import openpyxl
  from openpyxl import Workbook
  from openpyxl.styles import Font

  file1 = r'C:\Users\chaojie\Desktop\接口\API\工作表 在 SAIC-HY_智能制造数字化项目_MOM系统与底盘&总装中控详细对接会议纪要-20230328.xlsx'
  file2 = r'C:\Users\chaojie\Desktop\接口\API\工作表 在 SAIC-HY_智能制造数字化项目_MOM系统与焊装中控详细对接会议纪要-20230323(1).xlsx'
  file3 = r'C:\Users\chaojie\Desktop\接口\API\工作表 在 SAIC-HY_智能制造数字化项目_MOM系统与涂装中控详细对接会议纪要-20230327(1).xlsx'
  file_list = [file1, file2, file3]
  wb = Workbook()
  to_name = 'API_DOC_{0}.xlsx'.format(random.randint(100, 10000))

  api_sheet = wb.create_sheet(title="接口目录")

  header = ['接口代码', '接口名称', '接口描述', '源系统', '目标系统', '消息协议']

  row_data = []

  sheet_code = []


  def get_sheet_name(code, idx):
      global sheet_code
      for item in sheet_code:
          if item['code'] == code and item['wb'] == idx:
              return item['sheet']
      return None


  def get_sheet(idx):
      items = []
      global sheet_code
      for item in sheet_code:
          if item['wb'] == idx:
              items.append(item)
      return items


  def get_row(code):
      global row_data
      for row in row_data:
          if row[0] == code:
              return row
      return None


  def get_row_already(data_list, code):
      for row in data_list:
          if row[1] == code:
              return True
      return False


  def get_all_work():
      data_list = []
      serial = 0
      for f_name in file_list:
          workbook = openpyxl.load_workbook(f_name)
          sheet1 = workbook['接口目录']
          rows = sheet1.max_row
          # 获取工作表总列数
          cols = sheet1.max_column
          # sheet_code.append(
          #     {'code': cell_value, 'wb': file_list.index(f_name),
          #      'sheet': str(sheet1.cell(row=row_index, column=i).hyperlink.location).split('!')[0]})

          for row_index in range(4, rows):
              sheet_obj = {'code': None, 'wb': file_list.index(f_name),
                           'sheet': None, 'sheet_name': None}
              is_hl_obj = False
              row_data = []
              for i in range(1, cols):
                  cell_value = sheet1.cell(row=row_index, column=i).value
                  if i == 6:
                      if (cell_value is None or cell_value == '') or get_row_already(data_list, cell_value):
                          break
                      serial += 1
                      if (serial + 1) > 10:
                          row_data.append('IF_IOT_0' + str(serial))
                      else:
                          row_data.append('IF_IOT_00' + str(serial))

                      row_data.append(cell_value)
                      hl_obj = sheet1.cell(row=row_index, column=i).hyperlink
                      if hl_obj:
                          sheet_obj['code'] = row_data[0]
                          sheet_obj['sheet'] = str(sheet1.cell(row=row_index, column=i).hyperlink.location).split('!')[0]
                          sheet_obj['sheet_name'] = f"{row_data[0]}_{cell_value}".replace(
                              '/', ' ')
                          is_hl_obj = True
                  if i == 7:
                      row_data.append(cell_value)
                  if i == 11:
                      row_data.append(cell_value)
                  if i == 13:
                      row_data.append(cell_value)
                  if i == 19:
                      row_data.append(cell_value)

              if len(row_data) > 0:
                  data_list.append(row_data)
              if is_hl_obj:
                  sheet_code.append(sheet_obj)
      # for idx in range(0, len(data_list)):
      #     if idx > 8:
      #         data_list[idx].insert(0, 'IF_IOT_0' + str(idx + 1))
      #     else:
      #         data_list[idx].insert(0, 'IF_IOT_00' + str(idx + 1))
      return data_list


  def save_to_sheet1():
      global row_data
      api_sheet.append(header)
      for row in row_data:
          api_sheet.append(row)
      for row in range(0, len(row_data)):
          cell = api_sheet.cell(row=row + 2, column=1)
          sheet_name = f"{api_sheet.cell(row=row + 2, column=1).value}_{api_sheet.cell(row=row + 2, column=2).value}".replace(
              '/', ' ')
          link = f"{to_name}#{sheet_name}!A1"
          if cell is not None:
              cell.hyperlink = (link)
              cell.style = 'Hyperlink'
      # set link


  def generate():
      for f_name in file_list:
          wb1 = openpyxl.load_workbook(f_name)
          file_idx = file_list.index(f_name)
          sheets = get_sheet(file_idx)
          for sheet_obj in sheets:
              rows = get_row(sheet_obj['code'])
              sheet = wb.create_sheet(sheet_obj['sheet_name'])
              sheet.column_dimensions['K'].width = 120
              sheet.column_dimensions['L'].width = 50
              sheet.column_dimensions['M'].width = 50
              sheet.column_dimensions['E'].width = 80

              sheet['a1'] = '接口代码'
              sheet['a2'] = '接口名称'
              sheet['a1'].font = Font(bold=True)
              sheet['a2'].font = Font(bold=True)
              sheet['b1'] = rows[0]
              sheet['b2'] = rows[1]
              sheet['b1'].font = Font(bold=True)
              sheet['b2'].font = Font(bold=True)

              sheet['a3'] = '调用方   '
              sheet['a4'] = '被调用方  '
              sheet['a5'] = '通讯方式  '
              sheet['a6'] = '请求地址  '
              sheet['a7'] = '说明     '

              sheet['b3'] = rows[3]
              sheet['b4'] = rows[4]
              sheet['b5'] = rows[5]
              sheet['b6'] = ''
              sheet['b7'] = rows[2]
              sheet['d1'] = '返回'
              link = f"{to_name}#接口目录!A1"
              sheet['d1'].hyperlink = (link)
              sheet['d1'].style = 'Hyperlink'
              api_sheet = None
              try:
                  api_sheet = wb1.get_sheet_by_name(sheet_obj['sheet'])
              except KeyError as ke:
                  pass
              if api_sheet is None:
                  pass
              else:
                  mr = api_sheet.max_row
                  mc = api_sheet.max_column
                  for i in range(5, mr + 1):
                      for j in range(1, mc + 1):

                          c = api_sheet.cell(row=i, column=j)
                          sheet.cell(row=i + 5, column=j).value = c.value
                          sheet.cell(row=i + 5, column=j).fill = copy.copy(c.fill)

                          if c.has_style:
                              sheet.cell(row=i + 5, column=j)._style = copy.copy(c._style)
                              sheet.cell(row=i + 5, column=j).font = copy.copy(c.font)
                              sheet.cell(row=i + 5, column=j).border = copy.copy(c.border)
                              sheet.cell(row=i + 5, column=j).fill = copy.copy(c.fill)
                              sheet.cell(row=i + 5, column=j).number_format = copy.copy(c.number_format)
                              sheet.cell(row=i + 5, column=j).protection = copy.copy(c.protection)
                              sheet.cell(row=i + 5, column=j).alignment = copy.copy(c.alignment)
                  # area1 = CellRange("c11:c28")  # area being copied
                  # area2 = CellRange("d12:d28")  # area being copied
                  # area3 = CellRange("c24:c28")  # area being copied
                  # area4 = CellRange("d24:d28")  # area being copied

                  sheet.merge_cells(range_string='c11:c28')
                  sheet.merge_cells(range_string='d11:d14')
                  sheet.merge_cells(range_string='d15:d28')
                  sheet.merge_cells(range_string='c29:c33')
                  sheet.merge_cells(range_string='d29:d33')


  if __name__ == '__main__':
      row_data = get_all_work()
      print(row_data)
      save_to_sheet1()
      print(sheet_code)
      # print(len(sheet_code))
      generate()
      wb.save(to_name)

  ```


title: Vue 延时执行Vue 延时执行
created_time: 2023-06-21 02:37:09.317709
intro:
  Vue 项目订阅RabbitMQ，之前的做法是在每个需要订阅的业务页面进行连接和订阅操作。 时间一长发现了问题，RabbitmMQ会有很多重复连接，在新项目中尝试解决这个问题： 在App.vue中进行连接，全局只有一个连接，在不同的业务页面进行订阅，能保证页面不会重复连接。

html_text:
  <h5 id="h5-u9700u6C42"><a name="需求" class="reference-link"></a><span class="header-link octicon octicon-link"></span>需求</h5><p>Vue 项目订阅RabbitMQ，之前的做法是在每个需要订阅的业务页面进行连接和订阅操作。<br>时间一长发现了问题，RabbitmMQ会有很多重复连接，在新项目中尝试解决这个问题：<br>在App.vue中进行连接，全局只有一个连接，在不同的业务页面进行订阅，能保证页面不会重复连接。<br>接下来又遇到一个问题，App.vue中连接成功，在业务页面订阅出错，原因是连接是需要时间的，而业务页面加载完成连接可能还没连上。<br>解决：
  <pre><code class="lang-javascript">  __delay__(timer) {
      return new Promise(resolve =&gt; {
        timer = timer || 2000
        setTimeout(function() {
          resolve()
        }, timer)
      })
    },
     subscribe: async function(url, callback) {
      while (!this.stompClient.serverState)
        await this.__delay__(1000)
      return this.stompClient.subscribe('/topic/' + url, function(message) {
        callback(message)
      })
    }
  </code></pre>
  <p>业务页面订阅:</p>
  <pre><code class="lang-javascript"> this.subscribeObj = this.$stomp.subscribe(this.$store.getters.getWorkStation.Code + '.ASIS.WorkStationShelfBin', function(message) {
        const quote = JSON.parse(message.body)
        console.log(quote)
      })
  </code></pre>
  <p>通过<strong>delay</strong>来实现阻塞等待。</p>

markdown_text:
  ##### 需求
  Vue 项目订阅RabbitMQ，之前的做法是在每个需要订阅的业务页面进行连接和订阅操作。
  时间一长发现了问题，RabbitmMQ会有很多重复连接，在新项目中尝试解决这个问题：
  在App.vue中进行连接，全局只有一个连接，在不同的业务页面进行订阅，能保证页面不会重复连接。
  接下来又遇到一个问题，App.vue中连接成功，在业务页面订阅出错，原因是连接是需要时间的，而业务页面加载完成连接可能还没连上。
  解决：
  ```javascript
    __delay__(timer) {
      return new Promise(resolve => {
        timer = timer || 2000
        setTimeout(function() {
          resolve()
        }, timer)
      })
    },
     subscribe: async function(url, callback) {
      while (!this.stompClient.serverState)
        await this.__delay__(1000)
      return this.stompClient.subscribe('/topic/' + url, function(message) {
        callback(message)
      })
    }
  ```
  业务页面订阅:
  ```javascript
   this.subscribeObj = this.$stomp.subscribe(this.$store.getters.getWorkStation.Code + '.ASIS.WorkStationShelfBin', function(message) {
        const quote = JSON.parse(message.body)
        console.log(quote)
      })
  ```
  通过__delay__来实现阻塞等待。


title: 2023
created_time: 2023-07-19 06:54:41.666655
html_text:
  <p><a data-pswp-width="240" data-pswp-height="240" href="/upload/files/jpeg/1046f1172afb8c4f97d68a2a8f9a0c25.jpeg"><img data-magnify="gallery" data-src="/upload/files/jpeg/1046f1172afb8c4f97d68a2a8f9a0c25.jpeg"  src="/upload/files/jpeg/1046f1172afb8c4f97d68a2a8f9a0c25.jpeg"  data-href="/upload/files/jpeg/1046f1172afb8c4f97d68a2a8f9a0c25.jpeg" "/></a></p>


