SyntaxError: invalid syntax

The code is missing a line break after "import pandas as pd". The correct code should be:

import pandas as pd from reportlab.pdfgen import canvas

读取Excel表格数据

df = pd.read_excel('.\data\technique\technique.xlsx', usecols=['tactic_name', 'technique_id','test_name', 'AttackCommand','CleanupCommand', 'CheckPrereqCommand','GetPrereqCommand'], nrows=5,dtype=str)

选择要提取的行和列

rows = df.index.tolist() # 选取所有行 cols = df.columns.tolist() # 选取所有列

text = '' for i in rows: for j in cols: text += str(df.loc[i, j]) + '\n' # 将选取的文本内容按行拼接起来 #print(text)

file = open("text.txt", "w") file.write(text) file.close()

创建canvas对象

c = canvas.Canvas('example.ps')

写入文本内容

c.drawString(100, 100, text)

保存文件

c.save()

import pandas as pd from reportlabpdfgen import canvas # 读取Excel表格数据 df = pdread_exceldatatechniquetechniquexlsx usecols=tactic_name technique_idtest_name AttackCommandCleanupCommand CheckPrereqComman

原文地址: https://www.cveoy.top/t/topic/buqI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录