i have a np.array which i want to save in a specific excel cell (for example in B14). The input in B14 should look like this: [[ 0, 540, 1920, 540]]. But i got this ERROR:
TypeError: only size-1 arrays can be converted to Python scalars. Unsupported type <class 'numpy.ndarray'> in write()
import xlsxwriter
self.outputs['redlines']=np.array([[0, HEIGHT/2, WIDTH, HEIGHT/2]])
outWorkbook = xlsxwriter.Workbook('parameter.xlsx')
outSheet=outWorkbook.add_worksheet('Tabelle1')
outSheet.write('A13','dts:')
outSheet.write('A14','outputs Redlines:')
outSheet.write('B14', self.dts)
outSheet.write('B14', self.outputs['redlines'])
outWorkbook.close()
Thank You all!
CodePudding user response:
I'm not sure if you want to write the data in the list or a string representation of the array. I'll address the first option.
To write a list with xlsxwriter you can use the worksheet write_row()
or write_column()
methods (depending on which direction you want to write the data).
However, your np.array is actually a list of lists so you will either need to handle that in a loop (and use write_row()
for each sub-list) or just pick out the one you want. Like this:
outSheet.write_row('B14', self.outputs['redlines'][0])