I am importing text files into excel using xlwt module. But it allows only 256 columns to be stored. Are there any ways to solve this problem?
xlwt
supports creation of XLS files of the kind created by Excel 97-2003 and read by Excel 97 onwards. The file format is limited to 256 columns and 65536 rows. No amount of changing 256 to some other number in the xlwt
source code will change that.
You have 3 options, in increasing order of complexity:
(1) as suggested by another, write a CSV file.
(2) openpyxl ... Excel 2007+ xlsx/xlsm format
(3) win32 COM (Windows only)
Line 8 in the file Column.py
in the xlwt
package sets the column limit to 256:
raise ValueError("column index (%r) not an int in range(256)" % colx)
You could change this number in the xlwt
source to allow more columns, but this will break compatibility with older (edit: ALL) versions of excel.
EDIT The xlwt maintainer says that this will not work, so don't try to do it (I'll leave this answer here as I think it's useful to have the warning).
use xlsxwriter and pandas.
import xlsxwriter, pandas
writer = pandas.ExcelWriter(file, engine='xlsxwriter')
pandas.to_excel(writer, sheet_name='Sheet1')
writer.save()
Is that a statement of fact or should xlwt support more than 256 columns? What error do you get? What does your code look like?
If it truly does have a 256 column limit, just write your data in a csv-file using the appropriate python module and import the file into Excel.
import pandas as pd
writer = pd.ExcelWriter('..\output\The file.xlsx',engine='xlsxwriter')
file.to_excel(writer,'output_sheet')
writer.save()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With