我有一个python脚本,可以读取csv文件并将此数据写入PDF文件,我在eviroment conda Unix上执行了该脚本
当我执行脚本时,每列仅获得第一个字符,我尝试以二进制模式smsInfo = csv.reader(open(data_file, "rb"))
打开csv文件
但我无法在此二进制模式下打开。谁能指出我正确的方向。
#将数据解析为.csv之后生成PDF报告的脚本 文件
# import statements
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import portrait
import csv
def import_Data(data_file):
smsInfo = csv.reader(open(data_file, "r"))
for row in smsInfo:
ID = row[0]
Incoming_Number = row[1]
Date_And_Time = row[2]
Read = row[3]
Sent_Replied = row[4]
Body = row[5]
Seen = [6]
pdf_filename = 'SMS Data Report.pdf'
generate_report(ID, Incoming_Number, Date_And_Time, Read,
Sent_Replied, Body, Seen)
def generate_report(ID, Date_And_Time, Read, Sent_Replied, Body, Seen,
pdf_filename):
#c = canvas.Canvas(pdf_filename, pagesize=portrait(letter))
import_Data(data_file)
canvas.save()