【发布时间】:2015-11-10 17:25:03
【问题描述】:
第 1 步。从 excel 文件中获取输入。
第 2 步。创建 WB 对象。
第 3 步。从该 WB 对象中获取数据并创建一个字典列表。
第 4 步。操作、格式化、设置数据样式。
第 5 步。现在需要输出数据并将其附加到现有 Excel 工作簿中。 这意味着现有 Excel 工作簿将附加来自 第 1 步不断。
我已经完成了第 1 - 4 步,并且可以将我的数据输出到一个新的工作簿。我来了 第 5 步为空。
任何指导或方向将不胜感激。
### Python 3.X ###
import sys
import time
import openpyxl
from openpyxl.styles import Alignment, Font, Style
from openpyxl.cell import get_column_letter
from pathlib import Path
###Double Click a Batch file, CMD opens, Client drags and drops excel File
###to be Formatted
try:
path = sys.argv[1]
except IndexError:
path = Path(input('Input file to read: ').strip("'").strip('"'))
output_string = str(Path(path.parent, path.stem + '.NewFormatted.xlsx'))
wb = openpyxl.load_workbook(str(path))
sheet1 = wb.worksheet[0]
###Do the Python Dance on Data###
###Style, Font, Alignment applied to sheets###
###Currently Saves output as a NEW excel File in the Directory the original
###file was drag and dropped from
wb.save(output_string)
###Need the output to be appended to an existing Excel file already present
###in a target directory
###Note Formatted Workbook (output) has multiple sheets###
【问题讨论】:
标签: python excel append openpyxl