How to write formulas in openpyxl in german excel version

I have the following german formula in Excel which works perfectly fine:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>=WENN(UND(SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$C; 3; FALSCH) = 0,01; SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$D; 4; FALSCH) = DATUM(9999; 12; 31); XODER(RECHTS(LINKS(SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "150"; RECHTS(LINKS(SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "020")); "Muss neuen Preis bekommen!"; "")
</code>
<code>=WENN(UND(SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$C; 3; FALSCH) = 0,01; SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$D; 4; FALSCH) = DATUM(9999; 12; 31); XODER(RECHTS(LINKS(SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "150"; RECHTS(LINKS(SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "020")); "Muss neuen Preis bekommen!"; "") </code>
=WENN(UND(SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$C; 3; FALSCH) = 0,01; SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$D; 4; FALSCH) = DATUM(9999; 12; 31); XODER(RECHTS(LINKS(SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "150"; RECHTS(LINKS(SVERWEIS(B2; '\pathpathpathpath[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "020")); "Muss neuen Preis bekommen!"; "")

Now I tried to automate the process for all the data I have with python and my englisch formula looks like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>formula = (
f'=IF(AND(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$C, 3, FALSE) = 0.01, '
f'VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$D, 4, FALSE) = DATE(9999, 12, 31), '
f'XOR(RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "150", '
f'RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "020")), '
'"Muss neuen Preis bekommen!", "")'
)
</code>
<code>formula = ( f'=IF(AND(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$C, 3, FALSE) = 0.01, ' f'VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$D, 4, FALSE) = DATE(9999, 12, 31), ' f'XOR(RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "150", ' f'RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "020")), ' '"Muss neuen Preis bekommen!", "")' ) </code>
formula = (
   f'=IF(AND(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$C, 3, FALSE) = 0.01, '
   f'VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$D, 4, FALSE) = DATE(9999, 12, 31), '
   f'XOR(RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "150", '
   f'RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "020")), '
   '"Muss neuen Preis bekommen!", "")'
)

When writing the formula in the cells it translates everything correctly except the XOR-Condition. After that I tried to simply write the german command for XOR (XODER) in my python code which resulted in me getting the “#VALUE” error in excel. I just need to go into the cell and press enter and the formula gets calculated correctly.I tried to force excel to recalculate all formulas in my worksheet with win32 or changing how i write the the formula in my excel sheet. For example I tried this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>formulager1 = (
f'=WENN(UND('
f'SVERWEIS(B{row_num}; '
f''\\path\path\path\path\[filename.xlsx]sheetname'!$A:$C; 3; FALSCH) = 0,01; '
f'SVERWEIS(B{row_num}; '
f''\\path\path\path\path\[filename.xlsx]sheetname'!$A:$D; 4; FALSCH) = DATUM(9999; 12; 31); '
f'XODER('
f'RECHTS(LINKS(SVERWEIS(B{row_num}; '
f'\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "150"; '
f'RECHTS(LINKS(SVERWEIS(B{row_num}; '
f''\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "020"'
f')); "Muss neuen Preis bekommen!"; "")'
)
</code>
<code>formulager1 = ( f'=WENN(UND(' f'SVERWEIS(B{row_num}; ' f''\\path\path\path\path\[filename.xlsx]sheetname'!$A:$C; 3; FALSCH) = 0,01; ' f'SVERWEIS(B{row_num}; ' f''\\path\path\path\path\[filename.xlsx]sheetname'!$A:$D; 4; FALSCH) = DATUM(9999; 12; 31); ' f'XODER(' f'RECHTS(LINKS(SVERWEIS(B{row_num}; ' f'\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "150"; ' f'RECHTS(LINKS(SVERWEIS(B{row_num}; ' f''\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "020"' f')); "Muss neuen Preis bekommen!"; "")' ) </code>
formulager1 = (
     f'=WENN(UND('
     f'SVERWEIS(B{row_num}; '
     f''\\path\path\path\path\[filename.xlsx]sheetname'!$A:$C; 3; FALSCH) = 0,01; '
     f'SVERWEIS(B{row_num}; '
     f''\\path\path\path\path\[filename.xlsx]sheetname'!$A:$D; 4; FALSCH) = DATUM(9999; 12; 31); '
     f'XODER('
     f'RECHTS(LINKS(SVERWEIS(B{row_num}; '
     f'\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "150"; '
     f'RECHTS(LINKS(SVERWEIS(B{row_num}; '
     f''\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E; 5; FALSCH); 8); 3) = "020"'
     f')); "Muss neuen Preis bekommen!"; "")'
)

I also tried adding the “_xlfn.” prefix which is mentioned in this question:

Nothing I tried seems to work so my question is:

Does anyone of you have an idea how i could correctly write my formula in my excel ? Whether it is changing how I write the formula through the python script or adjusting the code so that all formulas get recalculated or even a way that excel translates the XOR condition correctly, which would be the easiest solution in my estimation.

1

For anyone wondering: I found the solution. I used the _xlfn. prefix at the wrong spot.

I tried adding it at the front of the whole formula, but it needed to be added in front of the XOR which wouldnt be translated correctly.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>formula = (
f'=IF(AND(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$C, 3, FALSE) = 0.01, '
f'VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$D, 4, FALSE) = DATE(9999, 12, 31), '
f'_xlfn.XOR(RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "150", '
f'RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "020")), '
'"Muss neuen Preis bekommen!", "")'
)
</code>
<code>formula = ( f'=IF(AND(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$C, 3, FALSE) = 0.01, ' f'VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$D, 4, FALSE) = DATE(9999, 12, 31), ' f'_xlfn.XOR(RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "150", ' f'RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "020")), ' '"Muss neuen Preis bekommen!", "")' ) </code>
formula = (
f'=IF(AND(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$C, 3, FALSE) = 0.01, '
f'VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$D, 4, FALSE) = DATE(9999, 12, 31), '
f'_xlfn.XOR(RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "150", '
f'RIGHT(LEFT(VLOOKUP(B{row_num}, '\\path\path\path\path\[filename.xlsx]sheetname'!$A:$E, 5, FALSE), 8), 3) = "020")), '
'"Muss neuen Preis bekommen!", "")'
)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật