Last active
April 29, 2025 05:37
-
-
Save lakshmanok/3321e16a266b24be1428dc59a8f94c9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib.backends.backend_pdf import PdfPages | |
def _draw_as_table(df, pagesize): | |
alternating_colors = [['white'] * len(df.columns), ['lightgray'] * len(df.columns)] * len(df) | |
alternating_colors = alternating_colors[:len(df)] | |
fig, ax = plt.subplots(figsize=pagesize) | |
ax.axis('tight') | |
ax.axis('off') | |
the_table = ax.table(cellText=df.values, | |
rowLabels=df.index, | |
colLabels=df.columns, | |
rowColours=['lightblue']*len(df), | |
colColours=['lightblue']*len(df.columns), | |
cellColours=alternating_colors, | |
loc='center') | |
return fig | |
def dataframe_to_pdf(df, filename, numpages=(1, 1), pagesize=(11, 8.5)): | |
with PdfPages(filename) as pdf: | |
nh, nv = numpages | |
rows_per_page = len(df) // nh | |
cols_per_page = len(df.columns) // nv | |
for i in range(0, nh): | |
for j in range(0, nv): | |
page = df.iloc[(i*rows_per_page):min((i+1)*rows_per_page, len(df)), | |
(j*cols_per_page):min((j+1)*cols_per_page, len(df.columns))] | |
fig = _draw_as_table(page, pagesize) | |
if nh > 1 or nv > 1: | |
# Add a part/page number at bottom-center of page | |
fig.text(0.5, 0.5/pagesize[0], | |
"Part-{}x{}: Page-{}".format(i+1, j+1, i*nv + j + 1), | |
ha='center', fontsize=8) | |
pdf.savefig(fig, bbox_inches='tight') | |
plt.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import pandas as pd
创建一个数据表
plan_data = {
"阶段": [
"准备阶段",
"公司注册成立",
"办理经营许可",
"产品分类与注册",
"外资注入与股权调整",
"启动进口与销售",
"定期评估与扩展"
],
"时间": [
"第1-2周",
"第3-4周",
"第4-6周",
"第6-10周",
"第8-12周",
"第12周后",
"6-12个月后"
],
"主要任务": [
"确定合作方案与出资比例,签署初步协议(MOU),准备公司注册资料",
"提交公司注册申请,获取营业执照并办理公章、税务登记等",
"向卫生局提交医疗器械经营条件备案,补充仓库和人员资料",
"完成产品分类,提交产品注册请诉资料",
"成立合资公司,办理外资入股手续",
"执行首批进口,完成报关、进仓、运输和货物分发",
"总结评估,推进新产品线或扩大投资"
]
}
转换为DataFrame
plan_df = pd.DataFrame(plan_data)
导出成Excel
plan_df.to_excel("/mnt/data/Vietnam_Medical_Project_Plan.xlsx", index=False)
"""我现在将经过转换的Excel文件上传给你,并继续帮你做英文和越南语版本!"""