CSV2Excel in Python

sziasztok

csvbol kellene kinyernem adatokat es egy leteo .xlsx file-t update-elni
az adatok megvannak, szepen tudok olvasni az xlsx-bol illetve a csv-bol is, de valamiert nem megy az iras/frissites funkcio

esetleg otlet valakinek?


import xlwt
import xlrd
from xlutils.copy import copy

rb = xlrd.open_workbook('ICPCopy.xlsx')

wb = copy(rb)

w_sheet = wb.get_sheet(0)

w_sheet.write(0,0,'modification')

wb.save('ICPCopy.xlsx')

Error:


Traceback (most recent call last):

File "C:\workspace\test\src\writer.py", line 16, in
wb.save('ICPCopy.xlsx')

File "C:...\AppData\Local\Programs\Python\Python35\lib\site-packages\xlwt\Workbook.py", line 696, in save
doc.save(filename_or_stream, self.get_biff_data())

File "C:\...\AppData\Local\Programs\Python\Python35\lib\site-packages\xlwt\CompoundDoc.py", line 262, in save
f = open(file_name_or_filelike_obj, 'w+b')

PermissionError: [Errno 13] Permission denied: 'ICPCopy.xlsx

Hozzászólások

xlwt 1.1.2
Library to create spreadsheet files compatible with MS Excel 97/2000/XP/2003 XLS files, on any platform, with Python 2.6, 2.6, 3.3+[...]

The xlwt module doesn't support the xlsx format. The xlsx file format is completely different from the xls format supported by xlwt.[...]

okes, szoval xlsxwriter... bocsi beneztem
viszont az iras tovabbra sem megy:


import xlrd
import xlsxwriter

sheet = 'EDI Template RACK 1'

workbook = xlsxwriter.Workbook('ICPCopy.xlsx')

sheetal = workbook.get_worksheet_by_name(sheet)

#define the style x:x:x:x:x

#adjust column width

#write in the sheet
data = "test"
sheetal.write('J18', data) # worksheet.write_string (18, 10,data) <- ezzel sem mukodik

workbook.close()

Error:

Traceback (most recent call last):
File "C:\workspace\test\src\writer.py", line 17, in
sheetal.write('J18', data,bold)
AttributeError: 'NoneType' object has no attribute 'write'

Exception ignored in: >
Traceback (most recent call last):
File "C:\...\Local\Programs\Python\Python35\lib\site-packages\xlsxwriter\workbook.py", line 148, in __del__
Exception: Exception caught in workbook destructor. Explicit close() may be required for workbook.

na most egy tipp?

ha valakit erdekel a megoldas:


import openpyxl
write_book = openpyxl.load_workbook('filename')
write_sheet = write_book.get_sheet_by_name(sheet) # vagy get_by_index
write_sheet.cell('A2').value = str(row[SLOT21])