'Assign already assigned excel cell format to a cell insert with xlwings

I have a partly encrypted excel sheet in my hands in that i want to insert certain values with xlwings on python. Its working great but:

How can I format a cell inserted with xlwings to have the same format as the default excel sheet?

Please see the picture. In both rows i enter date by 03.03.2022 But in row 8 entered with xlwings and row 9 entered by hand and pressed enter.

#Code for row 8
sheet.range('B8').value = "02.03.2022"

enter image description here

However, when i click on the xlwings row 8 and press enter, it will change to the correct format like row 9.

Is there a way that the row can automatically adapt the correct format from the excel sheet?



Solution 1:[1]

Found solution in:

sheet.range('B8').value = dt.datetime(2022,3,2)

Which then formated the date correctly!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Core_Dev