input is a text table - some columns are numbers and some text. I have python script to convert this text file to xlsx. After open in Excel or Libre all fields are text. Is there any option to convert some columns to number?
cat script.py:
import csv
import sys
from xlsxwriter.workbook import Workbook
# Add some command-line logic to read the file names.
tsv_file = sys.argv[1]
xlsx_file = sys.argv[2]
# Create an XlsxWriter workbook object and add a worksheet.
workbook = Workbook(xlsx_file)
worksheet = workbook.add_worksheet()
# Create a TSV file reader.
tsv_reader = csv.reader(open(tsv_file, 'rb'), delimiter='\t')
# Read the row data from the TSV file and write it to the XLSX file.
for row, data in enumerate(tsv_reader):
worksheet.write_row(row, 0, data)
# Close the XLSX file.
workbook.close()
run script:
python script.py in.txt out.xlsx
I would like to change script to convert some columns to text and some to numbers and keep xlsx format. Any idea how to do that?