如何选择 xlsx 文件中的特定单元格?
How to pick specifics cells in a xlsx file?
我有一些 excel 文件看起来像这样:
我以前从未在 Python 中阅读过这样的文件,所以我有点迷路了。
所以当我导入其中之一时,它看起来像这样:
我无法使用它。
您知道正确导入这些数据的一些技巧吗?
我的目标是对所有文件求和,比如在 E16 -> 文件 1 的 E16 + 文件 2 的 E16 +...+ 文件 n 的 E16 中得到一个最终文件。
对于包含数字的每个单元格依此类推。
但我不能用这个烂摊子来总结......有什么想法可以更有效地做到这一点吗?
我认为这可能对您有所帮助:
# import openpyxl module
import openpyxl
# Call a Workbook() function of openpyxl
# to create a new blank Workbook object
wb = openpyxl.Workbook()
# Get workbook active sheet
# from the active attribute.
sheet = wb.active
# writing to the cell of an excel sheet
sheet['A1'] = 200
sheet['A2'] = 300
sheet['A3'] = 400
sheet['A4'] = 500
sheet['A5'] = 600
# The value in cell A7 is set to a formula
# that sums the values in A1, A2, A3, A4, A5 .
sheet['A7'] = '= SUM(A1:A5)'
# save the file
wb.save("sum.xlsx")
我有一些 excel 文件看起来像这样:
我以前从未在 Python 中阅读过这样的文件,所以我有点迷路了。
所以当我导入其中之一时,它看起来像这样:
我无法使用它。
您知道正确导入这些数据的一些技巧吗?
我的目标是对所有文件求和,比如在 E16 -> 文件 1 的 E16 + 文件 2 的 E16 +...+ 文件 n 的 E16 中得到一个最终文件。
对于包含数字的每个单元格依此类推。
但我不能用这个烂摊子来总结......有什么想法可以更有效地做到这一点吗?
我认为这可能对您有所帮助:
# import openpyxl module
import openpyxl
# Call a Workbook() function of openpyxl
# to create a new blank Workbook object
wb = openpyxl.Workbook()
# Get workbook active sheet
# from the active attribute.
sheet = wb.active
# writing to the cell of an excel sheet
sheet['A1'] = 200
sheet['A2'] = 300
sheet['A3'] = 400
sheet['A4'] = 500
sheet['A5'] = 600
# The value in cell A7 is set to a formula
# that sums the values in A1, A2, A3, A4, A5 .
sheet['A7'] = '= SUM(A1:A5)'
# save the file
wb.save("sum.xlsx")