Reputation: 333
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?
Upvotes: 14
Views: 21086
Reputation: 357
If you trying to write to the columns in the for loop and getting this error, then re-initalize the column to 0 while iterating.
Upvotes: 0
Reputation: 11
import pandas as pd
writer = pd.ExcelWriter('..\output\The file.xlsx',engine='xlsxwriter')
file.to_excel(writer,'output_sheet')
writer.save()
Upvotes: 1
Reputation: 43
use xlsxwriter and pandas.
import xlsxwriter, pandas
writer = pandas.ExcelWriter(file, engine='xlsxwriter')
pandas.to_excel(writer, sheet_name='Sheet1')
writer.save()
Upvotes: 2
Reputation: 8313
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).
Upvotes: 2
Reputation: 83002
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)
Upvotes: 18
Reputation: 45670
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.
Upvotes: 1