b_wordop.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # import docx
  2. # from flask import flash, render_template, url_for
  3. # from flask import current_app as app
  4. #from docx2pdf import convert
  5. # @app.route('/shownoteInfo')
  6. # def showdoc():
  7. # doc=docx.Document('upload/docx/TNIS.docx')
  8. #
  9. # #读取文本内容
  10. # paragraphs = [para.text for para in doc.paragraphs]
  11. #
  12. # # 读取表格内容
  13. # table = []
  14. # for tbl in doc.tables:
  15. # for row in tbl.rows:
  16. # table.append([cell.text for cell in row.cells])
  17. # # 读取公式
  18. # formulas = []
  19. # for para in doc.paragraphs:
  20. # for run in para.runs:
  21. # if run.element.xml.startswith('<w:fldchar w:fldcharType="begin">'):
  22. # formulas.append(run.text)
  23. #
  24. # # 读取图片
  25. # images =[]
  26. # # for i, image in enumerate(doc.inline_shapes):
  27. # # image_name = f'image_{i}.png'
  28. # # image_url = url_for ('static', filename=image_name)
  29. # # image.width, image.height = image.width // 6, image.height // 6 # 缩小图片
  30. # # image.inline.graphic.graphicData.pic.nvPicPr.cNvPr.name = image_name # 修改图片名称
  31. # # image.inline.graphic.graphicData.pic.blipfil1.blip.embed =None # 删除原有的图片内容
  32. # # image.inline.graphic.graphicData.pic.blipfill.blip = doc.part.add_image(image.blob, image.part.content_type) # 添加新image.blob =None #删除图片内容
  33. # # images.append({'filename': image_name, 'width': image.width, 'height': image.height, 'alt': image.alt})
  34. # return render_template('web/showword.html',doc =doc, paragraphs=paragraphs, table=table, formulas=formulas, images=images)
  35. #
  36. #
  37. # @app.route('/shownoteInfo2')
  38. # def adminlogin2():
  39. # return render_template('admin/a_adminlogin.html')