예제 #1
0
def get_biff_records(data):
    outfile = StringIO()
    bk = Book()
    bk.biff2_8_load(
        file_contents=data,
        logfile=outfile,
    )
    biff_dump(bk.mem, bk.base, bk.stream_len, 0, outfile, unnumbered=True)
    return outfile.getvalue()
예제 #2
0
 def __init__(self,
              formatting_info=0,
              ragged_rows=False,
              ):
     Book.__init__(self)
     self.ragged_rows = ragged_rows
     self.formatting_info=formatting_info
     self.initialise_format_info()
     if formatting_info:
         f = Font()
         self.font_list.append(f)
         self.format_map[0]= Format(0,FUN,u'General')
         xf = XF()
         xf.alignment = XFAlignment()
         xf.border = XFBorder()
         xf.background = XFBackground()
         xf.protection = XFProtection()
         self.xf_list.append(xf)
예제 #3
0
 def __init__(self,
              formatting_info=0,
              ragged_rows=False,
              ):
     Book.__init__(self)
     self.ragged_rows = ragged_rows
     self.formatting_info=formatting_info
     self.initialise_format_info()
     if formatting_info:
         f = Font()
         self.font_list.append(f)
         self.format_map[0]= Format(0,FUN,u'General')
         xf = XF()
         xf.alignment = XFAlignment()
         xf.border = XFBorder()
         xf.background = XFBackground()
         xf.protection = XFProtection()
         self.xf_list.append(xf)
예제 #4
0
파일: wb.py 프로젝트: jigstar/tutti
def iterate_rows(wb: Book):
    """Iterates all rows in all workbook sheets, using first row as header.

    Yields:
        Each non-header row, as a dictionary of header key to value.
    """
    for s in wb.sheets():
        col_names = s.row(0)
        for row_nr in range(1, s.nrows):
            row = {}
            for name, col_nr in zip(col_names, range(s.ncols)):
                value = s.cell(row_nr, col_nr).value
                row[name.value] = value
            yield row
예제 #5
0
    def _parse_survey(workbook: xlrd.Book) -> Survey:
        """Parse the survey for the ODK form.

        Args:
            workbook: The xlrd book object

        Returns:
            A Survey object
        """
        try:
            sheet = workbook.sheet_by_name('survey')
            return Survey(sheet, workbook.datemode)
        except xlrd.biffh.XLRDError:
            msg = 'XlsForm file does not have required "survey" tab!'
            raise OdkFormError(msg)
예제 #6
0
    def _parse_settings(path: str, workbook: xlrd.Book) -> Settings:
        """Parse the settings for the ODK form.

        Args:
            path: The path to where the XlsForm is stored
            workbook: The xlrd book object

        Returns:
            A Settings object
        """
        sheet = None
        try:
            sheet = workbook.sheet_by_name('settings')
        except xlrd.biffh.XLRDError:
            pass
        return Settings(path, sheet, workbook.datemode)
예제 #7
0
    def parse_choices_from_sheet(workbook: xlrd.Book, sheet_name: str) -> ChoiceListTab:
        """Parse choices from a choice sheet.

        Args:
            workbook: The xlrd book object
            sheet_name: The sheet name to parse as a choice sheet

        Returns:
            A ChoiceListTab representing the specified sheet
        """
        sheet = None
        try:
            sheet = workbook.sheet_by_name(sheet_name)
        except xlrd.biffh.XLRDError:
            pass
        return ChoiceListTab(sheet, workbook.datemode)
예제 #8
0
def get_biff_records(data):
    outfile = StringIO()
    bk = Book()
    bk.biff2_8_load(file_contents=data, logfile=outfile, )
    biff_dump(bk.mem, bk.base, bk.stream_len, 0, outfile, unnumbered=True)
    return outfile.getvalue()
예제 #9
0
 def get_sheet_by_index_or_name(workbook: xlrd.Book, sheet_name_or_index):
     if type(sheet_name_or_index) == int:
         sheet = workbook.sheet_by_index(sheet_name_or_index)
     else:
         sheet = workbook.sheet_by_name(sheet_name_or_index)
     return sheet
예제 #10
0
 def get_sheet_by_index(workbook: xlrd.Book, sheet_index: int):
     return workbook.sheet_by_index(sheet_index)
예제 #11
0
 def get_sheet_by_name(workbook: xlrd.Book, sheet_name: str):
     sheets = ExcelHandler.get_sheet_by_index_or_name(workbook, sheet_name)
     sheet = workbook.sheet_by_name(sheet_name)
     return sheet
예제 #12
0
 def close(workbook: Book) -> None:
     workbook.release_resources()