Forum Discussion

orangebloss's avatar
orangebloss
Copper Contributor
Jul 16, 2025

Setting Cell type format as V or L

I have an XLS that's been produced using python and two columns with dates in. Although the cell format is set to Date my upload to another system fails, investigation has found that this is because the cell 'type' is set to 'l' rather than 'v'.

 

I've found a work around using the Text to Columns function but without using cell("type",A1) formula I wouldn't have found this.

 

So two questions really 

  1. Is there a way to easily identify / set the cell type in excel without adding in the type formula and using Text to Columns to copy and paste
  2. Is there a python command that would force this type to value rather than label? (We'll be moving the system to Java in the future so will this likely do the same thing?)

 

1 Reply

  • You may consider one of the options which is Python:

     

    To force cell type to "v" instead of "l":

     

    • Use datetime objects instead of strings:
    from openpyxl import Workbook
    from datetime import datetime
    
    wb = Workbook()
    ws = wb.active
    ws['A1'] = datetime(2025, 7, 17)  # This will be treated as a value
    wb.save("output.xlsx")

     

    • If you write '2025-07-17' as a string, Excel sees it as a label ("l"). But if you use a datetime object, it becomes a value ("v").
    • Set number format explicitly:
    ws['A1'].number_format = 'YYYY-MM-DD'

     

Resources