Example #1
0
def convert(wb_name, sheet_name, start_row):
    text = ''
    wb = open_workbook(wb_name)
    
    for s in wb.sheets():
        if s.name == sheet_name:
            for row in range(s.nrows):
                if row >= start_row - 1:
                    values = []
                    for col in range(s.ncols):
                        data_type = cell_display(s.cell(row, col)).split(" ")[0]
                        if data_type == 'date':
                            # Convert Excel date (looks like a float)
                            the_date = xldate_as_tuple(s.cell(row,col).value, wb.datemode)
                            values.append(date.strftime(date(*the_date[:3]), "%m/%d/%Y"))
                        elif data_type == 'number':
                            values.append(str(int(s.cell(row,col).value)))
                        elif data_type == 'logical':
                            # 0 is false, 1 is true
                            if int(s.cell(row,col).value) == 0:
                                values.append('False')
                            else:
                                values.append('True')
                        else:
                            # Replace CR/LF within cells with a space
                            values.append(str(s.cell(row,col).value).replace("\n", " "))
                    text += SEP_CHAR.join(values) + '\n'
                
    sys.stdout.write(text)
Example #2
0
 def cell(self,rdrowx,rdcolx,wtrowx,wtcolx):
     cell = self.rdsheet.cell(rdrowx,rdcolx)
     if cell.ctype == xlrd.XL_CELL_EMPTY:
         return
     if cell.ctype == xlrd.XL_CELL_ERROR:
         logger.error("Cell %s of sheet %r contains a bad value: %s" % (
                     xlrd.cellname(rdrowx, rdcolx),
                     quoted_sheet_name(self.rdsheet.name),
                     cell_display(cell,self.rdbook.datemode),
                     ))
         return
     BaseWriter.cell(self,rdrowx,rdcolx,wtrowx,wtcolx)
Example #3
0
 def cell(self, rdrowx, rdcolx, wtrowx, wtcolx):
     cell = self.rdsheet.cell(rdrowx, rdcolx)
     if cell.ctype == xlrd.XL_CELL_EMPTY:
         return
     if cell.ctype == xlrd.XL_CELL_ERROR:
         logger.error("Cell %s of sheet %r contains a bad value: %s" % (
             xlrd.cellname(rdrowx, rdcolx),
             quoted_sheet_name(self.rdsheet.name),
             cell_display(cell, self.rdbook.datemode),
         ))
         return
     BaseWriter.cell(self, rdrowx, rdcolx, wtrowx, wtcolx)
Example #4
0
from xlrd import open_workbook
from xlutils.display import quoted_sheet_name
from xlutils.display import cell_display

wb = open_workbook('source.xls')

print quoted_sheet_name(wb.sheet_names()[0])
print repr(quoted_sheet_name(u'Price(\xa3)', 'utf-8'))
print quoted_sheet_name(u'My Sheet')
print quoted_sheet_name(u"John's Sheet")

sheet = wb.sheet_by_index(0)
print cell_display(sheet.cell(1, 1))
print cell_display(sheet.cell(1, 3), wb.datemode)
from xlrd import open_workbook
from xlutils.display import quoted_sheet_name
from xlutils.display import cell_display

wb = open_workbook('source.xls')

print quoted_sheet_name(wb.sheet_names()[0])
print repr(quoted_sheet_name(u'Price(\xa3)','utf-8'))
print quoted_sheet_name(u'My Sheet')
print quoted_sheet_name(u"John's Sheet")

sheet = wb.sheet_by_index(0)
print cell_display(sheet.cell(1,1))
print cell_display(sheet.cell(1,3),wb.datemode)