Excel中的时间(HH:MM:SS)在openpyxl中转换为十进制值
Time (HH:MM:SS) in Excel is converted to decimal value in openpyxl
我正在尝试 运行 以下代码 :
import openpyxl
wb = openpyxl.load_workbook("/Users/kakkar/Downloads/TRADEBOOK ALL-EQ 01-01-2016 TO 04-02-2017.xlsx")
sheet = wb.get_sheet_by_name('TRADEBOOK')
print(sheet.cell(row=15, column=3).value)
print(sheet.cell(row=15, column=3).internal_value)
在输入 Excel 文件中,第 3 列包含时间值 10:47:49
。这在 openpyxl 中被视为浮点值 0.449872685185185
.
如何获取 HH:MM:SS
形式的时间值?
10:47:49 的 .internal_value (HH:MM:SS) IS 0.449872685185185,所以没问题。
请给出如下输出:
cell = sheet['C15']
print('cell=\t%s\n\ttype=%s\n\t.number_format=%s;\n\t.value=%s;\n\t.internal_value=%s;' % (cell,str(type(cell.value)),cell.number_format,cell.value,cell.internal_value) )
测试 Python:3.4.2 - openpyxl:2.4.1 - LibreOffice:4.3.3.2
Excel 将时间(和日期)值存储为 floating-point 数字。整数是自纪元(1970 年 1 月 1 日)以来的天数,而余数是一天中的一部分。
Here is an answer that can help you get the hours, minutes, and seconds out of the value, but this answer 可能更适合在不编写代码的情况下获得答案(它使用 xlrd 库)。
我正在尝试 运行 以下代码 :
import openpyxl
wb = openpyxl.load_workbook("/Users/kakkar/Downloads/TRADEBOOK ALL-EQ 01-01-2016 TO 04-02-2017.xlsx")
sheet = wb.get_sheet_by_name('TRADEBOOK')
print(sheet.cell(row=15, column=3).value)
print(sheet.cell(row=15, column=3).internal_value)
在输入 Excel 文件中,第 3 列包含时间值 10:47:49
。这在 openpyxl 中被视为浮点值 0.449872685185185
.
如何获取 HH:MM:SS
形式的时间值?
10:47:49 的 .internal_value (HH:MM:SS) IS 0.449872685185185,所以没问题。
请给出如下输出:
cell = sheet['C15']
print('cell=\t%s\n\ttype=%s\n\t.number_format=%s;\n\t.value=%s;\n\t.internal_value=%s;' % (cell,str(type(cell.value)),cell.number_format,cell.value,cell.internal_value) )
测试 Python:3.4.2 - openpyxl:2.4.1 - LibreOffice:4.3.3.2
Excel 将时间(和日期)值存储为 floating-point 数字。整数是自纪元(1970 年 1 月 1 日)以来的天数,而余数是一天中的一部分。
Here is an answer that can help you get the hours, minutes, and seconds out of the value, but this answer 可能更适合在不编写代码的情况下获得答案(它使用 xlrd 库)。