Save output to excel sheet

Hi,

I have an output that is generated by a function. It is in a form of an array. The output looks like

data [[‘NC7WZ16P6X’, ‘U115’, ‘I011308’]]
data [[‘NC7WZ16P6X’, ‘U116’, ‘I011308’]]
data [[‘NC7WZ16P6X’, ‘U117’, ‘I011308’]]
data [[‘NC7WZ16P6X’, ‘U118’, ‘I011308’]]
data [[‘NC7WZ16P6X’, ‘U122’, ‘I011308’]]
data [[‘ICL3224IA’, ‘U34’, ‘I011388’]]
data [[‘XC4VSX55-11FF1148’, ‘U90’, ‘I011405’]]
data [[‘LTC3729EUH’, ‘U56’, ‘I090381’]]
data [[‘LTC3729EUH’, ‘U59’, ‘I090381’]]
data [[‘LTC3729EUH’, ‘U60’, ‘I090381’]]
data [[‘LTC3729EUH’, ‘U62’, ‘I090381’]]
data [[‘SY89832UMI’, ‘U85’, ‘I090467’]]

I am trying to get this output into the excel sheet. The code for that function is

def output(self,headers,values):

    mydoc=xl.Workbook()
    mysheet=mydoc.add_sheet("test")
    header_font=xl.Font() #make a font object
    header_font.bold=True
    header_font.underline=True
    header_style = xl.XFStyle()

    header_style.font = header_font
   
    for col,value in enumerate(headers):
        mysheet.write(0,col,value,header_style)
        #print ' %d, %d, %s, %s ' % (0,col,value,header_style)
      
    for row_num,row_values in enumerate(values):
        row_num+=1
        print'row_num %d'% row_num
        print'row_values %s' % values

   for col,value in enumerate(row_values):
        mysheet.write(row_num,col,value)
        #print '%d %d %s' % (row_num,col,value)
    
   mydoc.save(r'C:testpyexel2.xlt')

The don’t have problem writing the headers. When I write the row values, its is overwriting all the values and I can get only the last row values. I don’t understand where I am doing the mistake.

Thanks

Prasoona

What does this have to do with wxPython? This is a friendly and helpful list, but that still doesn’t make posting off-topic questions all right.

Perhaps try posting this to comp.lang.python
(you can use google-groups for this). While you’re at it, you might want to explain the context of your question, e.g. which module you are using to read/write excel files.

  • Tal
···

On 6/12/07, Thippana, Prasoonadevi pthippan@mc.com wrote:

Hi,

I have an output that is generated by a function. It is in a form of an array. The output looks like

data [[‘NC7WZ16P6X’, ‘U115’, ‘I011308’]]
data [[‘NC7WZ16P6X’, ‘U116’, ‘I011308’]]
data [[‘NC7WZ16P6X’, ‘U117’, ‘I011308’]]
data [[‘NC7WZ16P6X’, ‘U118’, ‘I011308’]]
data [[‘NC7WZ16P6X’, ‘U122’, ‘I011308’]]
data [[‘ICL3224IA’, ‘U34’, ‘I011388’]]
data [[‘XC4VSX55-11FF1148’, ‘U90’, ‘I011405’]]
data [[‘LTC3729EUH’, ‘U56’, ‘I090381’]]
data [[‘LTC3729EUH’, ‘U59’, ‘I090381’]]
data [[‘LTC3729EUH’, ‘U60’, ‘I090381’]]
data [[‘LTC3729EUH’, ‘U62’, ‘I090381’]]
data [[‘SY89832UMI’, ‘U85’, ‘I090467’]]

I am trying to get this output into the excel sheet. The code for that function is

def output(self,headers,values):

    mydoc=xl.Workbook()
    mysheet=mydoc.add_sheet("test")
    header_font=xl.Font() #make a font object
    header_font.bold=True
    header_font.underline=True
    header_style = xl.XFStyle()
    header_style.font = header_font
   
    for col,value in enumerate(headers):
        mysheet.write(0,col,value,header_style)
        #print ' %d, %d, %s, %s ' % (0,col,value,header_style)
      
    for row_num,row_values in enumerate(values):
        row_num+=1
        print'row_num %d'% row_num
        print'row_values %s' % values
   for col,value in enumerate(row_values):
        mysheet.write(row_num,col,value)
        #print '%d %d %s' % (row_num,col,value)
    
   mydoc.save(r'C:testpyexel2.xlt')

The don’t have problem writing the headers. When I write the row values, its is overwriting all the values and I can get only the last row values. I don’t understand where I am doing the mistake.

Thanks

Prasoona

    for col,value in enumerate(row_values):
        mysheet.write(row_num,col,value)

        #print '%d %d %s' % (row_num,col,value)
    ...

Maybe, the last for loop should be indented and inside the one above. Like

        ...
    for row_num,row_values in enumerate(values):
        row_num+=1

        print'row_num %d'% row_num
        print'row_values %s' % values

··· On 6/12/07, **Thippana, Prasoonadevi** wrote: > Hi, > I have an output that is generated by a function. It is in a form of an array. The output looks like > data [['NC7WZ16P6X', 'U115', 'I011308']] > data [['NC7WZ16P6X', 'U116', 'I011308']] > data [['NC7WZ16P6X', 'U117', 'I011308']] > data [['NC7WZ16P6X', 'U118', 'I011308']] > data [['NC7WZ16P6X', 'U122', 'I011308']] > data [['ICL3224IA', 'U34', 'I011388']] > data [['XC4VSX55-11FF1148', 'U90', 'I011405']] > data [['LTC3729EUH', 'U56', 'I090381']] > data [['LTC3729EUH', 'U59', 'I090381']] > data [['LTC3729EUH', 'U60', 'I090381']] > data [['LTC3729EUH', 'U62', 'I090381']] > data [['SY89832UMI', 'U85', 'I090467']] > I am trying to get this output into the excel sheet. The code for that function is > > def output(self,headers,values): > > mydoc=xl.Workbook() > mysheet=mydoc.add_sheet("test") > header_font=xl.Font() #make a font object > header_font.bold=True > header_font.underline=True > header_style = xl.XFStyle() > header_style.font = header_font > > for col,value in enumerate(headers): > mysheet.write(0,col,value,header_style) > #print ' %d, %d, %s, %s ' % (0,col,value,header_style) > > for row_num,row_values in enumerate(values): > row_num+=1 > print'row_num %d'% row_num > print'row_values %s' % values > > for col,value in enumerate(row_values): > mysheet.write(row_num,col,value) > #print '%d %d %s' % (row_num,col,value) > > mydoc.save(r'C:testpyexel2.xlt') > The don't have problem writing the headers. When I write the row values, its is overwriting all the values and I can get only the last row values. I don't understand where I am doing the mistake. > Thanks > Prasoona