question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set column(s) as 'text' data type?

See original GitHub issue

Currently, I am using this codes to write data into an excel file.

        .....
        workbook = Workbook(filename + '.xlsx', {'strings_to_numbers': True})
        worksheet = workbook.add_worksheet('Results')
        .....
        worksheet.write(r, c, col)
        .....

In the Excel that is created the data type for the columns are always ‘General’.

data_type_excel

Can I programmatically set it as ‘Text’ through xlsxwriter?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
jagandecapricommented, Aug 19, 2015

Found the solution. I added format class object to on write. The format class sets number formats to text. Snippet of my code is as such:

        format1 = workbook.add_format()
        format1.set_num_format('@') # @ - This is text format in excel
        .....
        worksheet.write(r, c, col, format1)
0reactions
victorioTrebolcommented, May 23, 2022

hi all, I hope my code helps someone…


  data_changes = {
        'sheet1': 'column_letter',
        'sheet2': 'column_letter',
        ...
    }

    wb = openpyxl.load_workbook("{fileName}.xlsx".format(fileName=fileName))

    for sheet in data_changes:
        ws = wb[sheet]

        for row in range(2, ws.max_row + 1):
            ws["{}{}".format(data_changes[sheet], row)].number_format = '#,##0.00€'
    wb.save("Resumen_{retailer}.xlsx".format(retailer=retailer))

in my chase I used to put format contability, anyway, you can go excel -> format-> more format, and copy and paste formats :

https://cdn.exceltotal.com/wp-content/uploads/2012/01/formatos-personalizados-de-numeros-en-excel-01.png

good luck community!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set the data type of a column in Power Pivot - Microsoft Support
In the Power Pivot window, select the column for which you want to change the data type. On the Home tab, in the...
Read more >
SQL queries to change the column type
This article will show the way to change the data type of the columns in SQL Server 2019, MySQL Server, and PostgreSQL.
Read more >
The Basics Of MySQL TEXT Data Type By Examples
This tutorial shows you how to use various MySQL TEXT data type such as TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT to store text data....
Read more >
Set a Cell Format as Text in Excel
Open the Excel workbook · Click on the column heading to select entire column · Click Format > Cells · Click the Number...
Read more >
TEXT data type - IBM
A TEXT column has a theoretical limit of 2 31 bytes (two gigabytes) and a practical limit that your available disk storage determines....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found