python - 在转换第三列时将 excel 转换为 pdf 问题
问题描述
我想将我的 excel 文件转换为 pdf,但在转换第三列第三列时出现问题,请帮我解决这个问题
预期结果
索引列名姓氏性别
1个
2 dd gg 米
实际的
索引名字姓氏
1 性别
2```dd gg
将熊猫导入为 pd
从 fpdf 导入 FPDF
df_2 = pd.read_excel('exceltopdf.xlsx')
pdf = FPDF()
pdf.add_page()
pdf.set_xy(0, 0)
pdf.set_font('arial', 'B', 14)
pdf.cell(60)
pdf.cell(70, 10, '从 python 编写 PDF', 0, 4, 'C')
pdf.cell(-40)
pdf.cell(50, 10, '索引列', 1, 0, 'C')
pdf.cell(40, 10, '名字', 1, 0, 'C')
pdf.cell(40, 10, '姓氏', 1, 2, 'C')
pdf.cell(40, 10, '性别', 1, 3, 'C')
pdf.cell(-90)
pdf.set_font('arial', '', 12)
对于范围内的我(0,len(df_2)-1):
col_ind = str(i)
col_a = str(df_2['First Name'].ix[i])
col_b = str(df_2['Last Name'].ix[i])
col_c = str(df_2['Gender'].ix[i])
pdf.cell(50, 10, '%s' % (col_ind), 1, 0, 'C')
pdf.cell(40, 10, '%s' % (col_a), 0, 0, 'C')
pdf.cell(40, 10, '%s' % (col_b), 0, 2, 'C')
pdf.cell(40, 10, '%s' % (col_c), 0, 4, 'C')
pdf.cell(-90)
pdf.output('test.pdf', 'F')
解决方案
推荐阅读
- sql-server - EF Core 外键不适用于现有数据库
- laravel - 如何在 debian 中配置 2 个 api laravel 5.6 和一个“正常”
- php - 将 NULL 传递给 php mysql where 子句
- android - 何时完成 Intent
- php - 结合 3 个表生成配置文件列表 (HTML/PHP/MySQL)
- android-studio - 尝试使活动按钮 onclick 触发片段按钮也Android Studio
- javascript - JavaScript npm install Heroku,参考错误未定义
- android-theme - 无法解析符号“ThemeOverlay”。验证 Android XML 文件中的资源引用
- terminal - 如果在启动终端模拟器时没有会话,如何附加到现有的 byobu 会话或启动新的会话?
- android - Android光标根据ID移动到位置