I want change this python script to save not a csv file but a xlsx file.
I have differents problems with conversion str and int.
Can you see my code and tell me why the problem please.
Thanks
with open(fileuri, 'w', ) as workbook:
workbook = xlsxwriter.Workbook(fileuri)
worksheet = workbook.add_worksheet()
index = 0
Convoyeur = getProperty('Paramètre BOM::Présence convoyeur')
if Convoyeur.Value == 'Oui':
my_dict = {'[Reference]': [],
'[Quantity]': [],
'[Task ID]': [],
'[Database Path]': [],
'[Database Source]': [],
'ConveyorLength': [],
'ConveyorHeight': [],
'ConveyorWidth': [],
'[ConveyorType]': []}
col_num = 0
includeProp = getProperty('Paramètre BOM::Include')
if includeProp.Value == 'All':
components = app.Components
else:
components = [x for x in app.Components if x.BOM]
for c in components:
index += 1
value = ''
for key, value in my_dict.items():
if col_num == 0:
if c.VCID == '1d7491e5-225c-47a4-aab5-c04a89badff8':
worksheet.write(0, col_num, key)
a += 1
value = 'Conveyor''%i' % a
worksheet.write_column(1, col_num, value)
col_num += 1
if c.VCID != '1d7491e5-225c-47a4-aab5-c04a89badff8':
worksheet.write(0, col_num, key)
a += 1
value = c.Name
worksheet.write_column(1, col_num, value)
if col_num == 1:
worksheet.write(0, col_num, key)
value = '1'
worksheet.write_column(1, col_num, value)
if col_num == 2:
worksheet.write(0, col_num, key)
value = 'A.1'
worksheet.write_column(1, col_num, value)
if col_num == 3:
worksheet.write(0, col_num, key)
value = '1'
worksheet.write_column(1, col_num, value)
if col_num == 4:
worksheet.write(0, col_num, key)
value = 'Visual Components.qdb'
worksheet.write_column(1, col_num, value)
if col_num == 5 or 6 or 7:
worksheet.write(0, col_num, key)
value = c.Material.Name if c.Material else '*NULL*'
worksheet.write_column(1, col_num, value)
if col_num == 8:
worksheet.write(0, col_num, key)
value = c.getProperty(col_num)
worksheet.write_column(1, col_num, value)
if not col_num:
col_num = c.getProperty('Presets')
if col_num:
value = str(col_num)
worksheet.write_column(1, col_num, value)
else:
col_num = c.getProperty(col_num)
if col_num:
if type(col_num.Value) == type(some_material):
value = col_num.Value.Name if col_num.Value else '*NULL*'
worksheet.write_column(1, col_num, value)
elif col_num.Type == VC_BOOLEAN:
value = 'True' if col_num.Value else 'False'
worksheet.write_column(1, col_num, value)
elif col_num.Type == VC_REAL:
value = ('%.3f' % (col_num.Value)).replace('.', ',')
worksheet.write_column(1, col_num, value)
elif col_num.Type in [VC_INTEGER, VC_STRING]:
value = str(col_num.Value)
worksheet.write_column(1, col_num, value)
else:
print('Non supported property "%s" at component "%s"' % (col_num, c.Name))
workbook.close()
I modify the part with open because the format csv is created here.