def run(json_in): # carrega stdin xson = json.loads(json_in) # inicializa ods planilha = odslib.ODS() # escreva dias planilha.content.getCell(0, 0).stringValue(u"MatrUFSC").setBold(True) planilha.content.getCell(1, 0).stringValue(u"Segunda") planilha.content.getCell(2, 0).stringValue(u"Terça") planilha.content.getCell(3, 0).stringValue(u"Quarta") planilha.content.getCell(4, 0).stringValue(u"Quinta") planilha.content.getCell(5, 0).stringValue(u"Sexta") planilha.content.getCell(6, 0).stringValue(u"Sábado") # escreve horas planilha.content.getCell(0, 1).stringValue(u"07:30 - 08:20") planilha.content.getCell(0, 2).stringValue(u"08:20 - 09:10") planilha.content.getCell(0, 3).stringValue(u"09:10 - 10:00") planilha.content.getCell(0, 4).stringValue(u"10:10 - 11:00") planilha.content.getCell(0, 5).stringValue(u"11:00 - 11:50") planilha.content.getCell(0, 6).stringValue(u"13:30 - 14:20") planilha.content.getCell(0, 7).stringValue(u"14:20 - 15:10") planilha.content.getCell(0, 8).stringValue(u"15:10 - 16:00") planilha.content.getCell(0, 9).stringValue(u"16:20 - 17:10") planilha.content.getCell(0, 10).stringValue(u"17:10 - 18:00") planilha.content.getCell(0, 11).stringValue(u"18:30 - 19:20") planilha.content.getCell(0, 12).stringValue(u"19:20 - 20:10") planilha.content.getCell(0, 13).stringValue(u"20:20 - 21:10") planilha.content.getCell(0, 14).stringValue(u"21:10 - 22:00") # escreve aulas for i, dia in enumerate(xson['horarios']): for j, aula in enumerate(dia): if aula: planilha.content.getCell(i + 1, j + 1).stringValue( aula['codigo']).setCellColor(aula['cor']) # cabeçalho das turmas planilha.content.getCell(0, 15).stringValue(u"Código") planilha.content.getCell(1, 15).stringValue(u"Turma") planilha.content.getCell(2, 15).stringValue(u"Nome") # escreve turmas e cria estilos for i, turma in enumerate(xson['turmas']): planilha.content.getCell(0, i + 16).stringValue( turma['codigo']).setCellColor(turma['cor']) planilha.content.getCell(1, i + 16).stringValue( turma['turma']).setCellColor(turma['cor']) planilha.content.getCell(2, i + 16).stringValue( turma['nome']).setCellColor(turma['cor']) planilha.content.mergeCells(2, i + 16, 5, 1) output = StringIO.StringIO() planilha.save(output) return output.getvalue()
def run(json_in): data = json.loads(json_in) sheet = odslib.ODS() sheet.content.getCell(0, 0).stringValue('MatrUFSC').setBold(True) sheet.content.getCell(1, 0).stringValue('Segunda') sheet.content.getCell(2, 0).stringValue('Terça') sheet.content.getCell(3, 0).stringValue('Quarta') sheet.content.getCell(4, 0).stringValue('Quinta') sheet.content.getCell(5, 0).stringValue('Sexta') sheet.content.getCell(6, 0).stringValue('Sábado') sheet.content.getCell(0, 1).stringValue('07:30 - 08:20') sheet.content.getCell(0, 2).stringValue('08:20 - 09:10') sheet.content.getCell(0, 3).stringValue('09:10 - 10:00') sheet.content.getCell(0, 4).stringValue('10:10 - 11:00') sheet.content.getCell(0, 5).stringValue('11:00 - 11:50') sheet.content.getCell(0, 6).stringValue('13:30 - 14:20') sheet.content.getCell(0, 7).stringValue('14:20 - 15:10') sheet.content.getCell(0, 8).stringValue('15:10 - 16:00') sheet.content.getCell(0, 9).stringValue('16:20 - 17:10') sheet.content.getCell(0, 10).stringValue('17:10 - 18:00') sheet.content.getCell(0, 11).stringValue('18:30 - 19:20') sheet.content.getCell(0, 12).stringValue('19:20 - 20:10') sheet.content.getCell(0, 13).stringValue('20:20 - 21:10') sheet.content.getCell(0, 14).stringValue('21:10 - 22:00') for i, day in enumerate(data['horarios']): for j, credit in enumerate(day): if credit: cell = sheet.content.getCell(i + 1, j + 1) cell.stringValue(credit['codigo']).setCellColor(credit['cor']) sheet.content.getCell(0, 15).stringValue('Código') sheet.content.getCell(1, 15).stringValue('Turma') sheet.content.getCell(2, 15).stringValue('Nome') for i, class_ in enumerate(data['turmas'], start=16): for j, info in enumerate(['codigo', 'class_', 'nome']): cell = sheet.content.getCell(j, i) cell.stringValue(info).setCellColor(class_['cor']) sheet.content.mergeCells(2, i, 5, 1) output = StringIO.StringIO() sheet.save(output) return output.getvalue()
#!/usr/bin/python import sys sys.path.insert(0, '..') import odslib # Create your document. In all examples I will call the object doc. doc = odslib.ODS() # Before we can put data into the cell, we need to get the cell object. # The getCell(col, row) method can be used for this. The columns and # rows both start from 0. Column A is represented as "0" and Row 1 is # represented as "0". # Now we are going to insert values into cells. There are two methods # that are used for normal data. floatValue() is used for number data # and stringValue() is used for strings. for row in range(1, 9): for col in range(1, 9): # Because the getCell(col, row) method returns an object, we # can immediately tack the floatValue() method on the end with # the value we want put into the cell. doc.content.getCell(col, row).floatValue(col * row).setBorder() # The floatValue() method also returns a copy of the cell object # so we could comtinue to tack cell modifiers on the end. Some # of the later examples will do this, so be prepared. # Save the document to the file you want to create doc.save("calc-example01.ods")