Hi,
The
functionality of the XlsxWriter write() method doesn't have anything to
do with the implementation language but rather the target file format.
The docs are reasonably explicit about this:
https://xlsxwriter.readthedocs.org/en/latest/worksheet.html#worksheet-write "Excel
makes a distinction between data types such as strings, numbers,
blanks, formulas and hyperlinks. To simplify the process of writing data
to an XlsxWriter file the write() method acts as a general alias for
several more specific methods":
Also, it is covered in some detail in Tutorial 3 in the docs:
https://xlsxwriter.readthedocs.org/en/latest/tutorial03.html Basically,
the write() method tries to write the type of data that Excel expects.
Take for example the case you raise of CSV files. If you created a small
csv to xlsx program to convert a file like the following to xlsx:
Foo
Bar
1
23
456.789For
example with a program like the following that uses one the XlsxWriter
type explicit functions since all of the read data will have a string
type in Python:
import csv
from xlsxwriter.workbook import Workbook
workbook = Workbook('file.xlsx')
worksheet = workbook.add_worksheet()
with open('file.csv', 'rb') as csvfile:
csvreader = csv.reader(csvfile)
for row_num, row_data in enumerate(csvreader):
for col_num, data in enumerate(row_data):
print "%d, %d, %s" % (row_num, col_num, data)
worksheet.write_string(row_num, col_num, data)The output would look like the following in Excel:
(Image above or below. It is a little hard to control).
This
probably isn't what the end user wants. In fact I have several "bug
reports" where people end up with Excel warnings like this for one
reason or another.
The write() method is just some syntactic
sugar to do what Excel wants. If the end-user wants something else then
it is easily avoided or overridden.