Esempio n. 1
0
 def write_row_col(sheet:Worksheet, row:int, col:int, dataL:list, cellFormat, writeRow:bool):
     # if cellFormat is a list, assign cellFormat to the corresponding data, 
     # else assign the same cellFormat to all data
     broadcast = (not isinstance(cellFormat, list))
     if not broadcast:
         if len(dataL) != len(cellFormat):
             raise ValueError("The length of data and formats should be the same")
             
     for i in range(len(dataL)):
         if writeRow:
             # row not changed, col increases with i
             tmpRow = row
             tmpCol = col+i
         else:
             # row increases with i, col not changed
             tmpRow = row+i
             tmpCol = col
             
         # write as number in default, otherwise as string
         try:
             sheet.write_number(tmpRow, tmpCol, float(dataL[i]), cellFormat if broadcast else cellFormat[i])
         except (TypeError, ValueError):
             sheet.write_string(tmpRow, tmpCol, dataL[i], cellFormat if broadcast else cellFormat[i])
Esempio n. 2
0
    async def _store_hotel(self,
                           sheet: Worksheet,
                           row: int,
                           parsed_columns: List[HotelField],
                           hotel: HotelContentRow) -> None:

        parsed_header: HotelField
        # 由 Columns 尋訪,並找出資料欄位
        for col, header in enumerate(parsed_columns):
            if header is HotelField.Url:
                url = hotel[header]
                url = self._normializa_url(url)
                link_style = {"color": "blue", "underline": 1, "font_size": 12}
                link_format = self._workbook.add_format(link_style)
                sheet.write_url(row, col, url, link_format)
            elif header is HotelField.Rooms:
                number_style = {"font_size": 12}
                number_format = self._workbook.add_format(number_style)
                sheet.write_number(row, col, int(hotel[header]), number_format)
            else:
                # 如果資料為 None 改成空字串
                field_data = hotel[header] if hotel[header] else ""
                sheet.write_string(row, col, field_data)