[英]Excel python openpyxl methods
Python excel methods doesn't work correctly. Python excel 方法无法正常工作。
import pandas as pd
import os
from openpyxl import load_workbook
path = "C:\\My files\\Staff\\xProject\\ProjektExcelPython\\test_files\\"
spreadsheet_file = pd.read_excel(os.path.join(path, "PlikExcelDoKonwersji.xlsx"), engine='openpyxl', header = 1)
print(spreadsheet_file)
It works perfectly, but if I would like to use methods from openpyxl I have error.它工作得很好,但如果我想使用 openpyxl 中的方法,我会出错。
import pandas as pd
import os
from openpyxl import load_workbook
path = "C:\\My files\\Staff\\xProject\\ProjektExcelPython\\test_files\\"
spreadsheet_file = pd.read_excel(os.path.join(path, "PlikExcelDoKonwersji.xlsx"), engine='openpyxl', header = 1)
#sheet = spreadsheet_file.sheet_by_name('sheet')
book = load_workbook(path, "PlikExcelDoKonwersji.xlsx")
sheet = book['SendMail1']
data = []
for row in sheet.rows:
print(row[1].value)
Error:错误:
line 94, in _validate_archive
raise InvalidFileException(msg)
openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support file format, please check you can open it with Excel first. Supported formats are: .xlsx,.xlsm,.xltx,.xltm
Process finished with exit code 1
load_workbook
function only takes a single argument for file-path. load_workbook
function 只接受一个文件路径参数。 try尝试
book = load_workbook(os.path.join(path, "PlikExcelDoKonwersji.xlsx"))
Instead of making the path 2 values, make it 1. For Example, Try:不要将路径值设为 2,而是将其设为 1。例如,尝试:
book = load_workbook("C:\\My files\\Staff\\xProject\\ProjektExcelPython\\test_files\\PlikExcelDoKonwersji.xlsx")
Thanks guys it works but now another problem occurs.谢谢大家,它可以工作,但现在又出现了另一个问题。
I would like to start as before without first row, I used header = 1, but now it doesn't work I go for documentation.我想在没有第一行的情况下像以前一样开始,我使用了 header = 1,但现在它不起作用我 go 用于文档。
def load_workbook(filename, read_only=False, keep_vba=KEEP_VBA,
data_only=False, keep_links=True):
So it isn't there.所以它不存在。 How you manage it in openpyxl?
你如何在 openpyxl 中管理它?
I would like to make something like:我想做类似的东西:
Find name in column[1], the same will be in column[2] and get one of data from row[7] using column[1] and column[2].在列 [1] 中查找名称,在列 [2] 中也是如此,并使用列 [1] 和列 [2] 从行 [7] 中获取数据之一。
Thanks for any suggestions.感谢您的任何建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.