当我保存openpyxl时,它会更改所有行/列/tex的颜色

2024-06-07 15:23:15 发布

您现在位置:Python中文网/ 问答频道 /正文

本质上,我正在尝试为我的同事制作一个小应用程序,自动填写我们的每周时间表。它会询问你的姓名,你工作的天数,多长时间(包括加班),并将这些数据填充到我们工作的各个公司预先制作的excel电子表格中。在

首先,我只是学习如何使用用户的输入编辑单元格。在

快速测试期间的问题-运行时在空白excel文档中wb.保存(测试.xlsx)它会更新我的改变,但它使所有的颜色变得时髦,因为某些原因(图片附后)

Table issues

我不太清楚它为什么要这样做-我试着在谷歌上搜索,但我能找到的只是如何改变行的颜色的信息,与我的问题无关。这可能是很明显的事情,但我想我还是会问的。在

非常感谢你的帮助!在

编辑-附加代码-

# Timesheet Bot v1.0
import os
import sys
import openpyxl

from openpyxl.styles import colors
from openpyxl.styles import Font, Color
from openpyxl import Workbook

path = ('/Users/namehere/Desktop/Test')
os.chdir(path)
wb = openpyxl.load_workbook('example.xlsx')
sheet = wb['Sheet 1']


print ('')
print ('')
print ('')
print ('')
print ('Hello and Welcome to Timesheet Bot 1.0 - I am Roger')
print ('I will sort out your Timesheet(s). Lets get started!')
print ('')
print ('\033[91m' + "I now will ask you a few questions about your work week." + '\033[0m')
print ('')
print ('')
print ('')
name = str(input('What is your full name? '))
sheet['C4'] = name

weekending = str(input('What is the week ending date ? (Sunday and must be DD/MM/YY) '))
sheet['C5'] = weekending

start = int(input('What was the start time for the week?'))
sheet['C7'] = start
sheet['C8'] = start
sheet['C8'] = start
sheet['C9'] = start
sheet['C10'] = start
sheet['C11'] = start



end = int(input('What was the end time for the week?'))
sheet['D7'] = end
sheet['D8'] = end
sheet['D8'] = end
sheet['D9'] = end
sheet['D10'] = end
sheet['D11'] = end


wb.save('example.xlsx')

Tags: thefromimportinputyourtimesheetxlsxwhat
1条回答
网友
1楼 · 发布于 2024-06-07 15:23:15

我想你现在已经找到了一个解决方法,但是我遇到了同样的问题,找到了潜在的问题。在

这种情况特别适用于使用苹果数字创建的文件。如果在数字中使用任何颜色,则颜色信息将保存到全局调色板中。不幸的是,在openpyxl中将数据保存到新文件时,调色板信息会丢失,因此您的电子表格软件将返回到默认调色板。在

我打开了一个pull request,可以解决这个问题。在

相关问题 更多 >

    热门问题