Hi,
Anyone can help I am just converting the excel file to csv using python, I can get the conversion output but the date not display exactly.
test.xlsx date format
167 1588 risks/SCS JP CAMPANA & CIE.pdf SCS JP CAMPANA & CIE 2 1 1 0 2015-03-16 16:56:25
167 1146 risks/AirBNB Inc..pdf AirBNB Inc. 2 1 1 0 2014-10-03 17:03:58
167 1134 risks/Deere & Company (1).pdf Deere & Company 2 3 1 0 2014-10-03 17:01:13
test.csv date format output from python
"167","1588","","risks/SCS JP CAMPANA & CIE.pdf","SCS JP CAMPANA & CIE","","2","","1","1","0","42079.7058449"
"167","1146","","risks/AirBNB Inc..pdf","AirBNB Inc.","","2","","1","1","0","41915.711088"
"167","1134","","risks/Deere & Company (1).pdf","Deere & Company","","2","","3","1","0","41915.7091782"
===========
The python code :
===========
import logging
import time
import traceback
import xlrd
import csv
import sys
import re
import datetime
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
def csv_from_excel():
xls = sys.argv[1]
target = sys.argv[2]
logging.info("Start converting: From '" + xls + "' to '" + target + "'. ")
try:
start_time = time.time()
wb = xlrd.open_workbook(xls)
sh = wb.sheet_by_index(0)
csvFile = open(target, 'wb')
wr = csv.writer(csvFile, quoting=csv.QUOTE_ALL)
for row in xrange(sh.nrows):
rowValues = sh.row_values(row)
newValues = []
for s in rowValues:
if isinstance(s, unicode):
strValue = (str(s.encode("utf-8")))
else:
strValue = (str(s))
isInt = bool(re.match("^([0-9]+)\.0$", strValue))
if isInt:
strValue = int(float(strValue))
else:
isFloat = bool(re.match("^([0-9]+)\.([0-9]+)$", strValue))
isLong = bool(re.match("^([0-9]+)\.([0-9]+)e\+([0-9]+)$", strValue))
if isFloat:
strValue = float(strValue)
if isLong:
strValue = int(float(strValue))
newValues.append(strValue)
wr.writerow(newValues)
csvFile.close()
logging.info("Finished in %s seconds", time.time() - start_time)
except Exception as e:
print (str(e) + " " + traceback.format_exc())
csv_from_excel()
Thanks in advance.
Regards,
FSPalero