Esempio n. 1
0
 def __all_links_rec(self):
     pieces = []
     temp = [(idx, tag) for tag, idx in list(self._supbook_xref.items())]
     temp.sort()
     for idx, tag in temp:
         stype, snum = tag
         if stype == 'ownbook':
             rec = BIFFRecords.InternalReferenceSupBookRecord(len(self.__worksheets)).get()
             pieces.append(rec)
         elif stype == 'xcall':
             rec = BIFFRecords.XcallSupBookRecord().get()
             pieces.append(rec)
             temp = [(idx, name) for name, idx in list(self._xcall_xref.items())]
             temp.sort()
             for idx, name in temp:
                 rec = BIFFRecords.ExternnameRecord(
                     options=0, index=0, name=name, fmla='\x02\x00\x1c\x17').get()
                 pieces.append(rec)
         else:
             raise Exception('unknown supbook stype %r' % stype)
     if len(self.__sheet_refs) > 0:
         # get references in index order
         temp = [(idx, ref) for ref, idx in list(self.__sheet_refs.items())]
         temp.sort()
         temp = [ref for idx, ref in temp]
         externsheet_record = BIFFRecords.ExternSheetRecord(temp).get()
         pieces.append(externsheet_record)
     return b''.join(pieces)
Esempio n. 2
0
 def __protection_rec(self):
     result = b''
     result += BIFFRecords.ProtectRecord(self.__protect).get()
     result += BIFFRecords.ScenProtectRecord(self.__scen_protect).get()
     result += BIFFRecords.WindowProtectRecord(self.__wnd_protect).get()
     result += BIFFRecords.ObjectProtectRecord(self.__obj_protect).get()
     result += BIFFRecords.PasswordRecord(self.__password).get()
     return result
Esempio n. 3
0
    def get_biff_record(self):
        height = self.height

        options = 0x00
        if self.bold:
            options |= 0x01
            self._weight = 0x02BC
        if self.italic:
            options |= 0x02
        if self.underline != self.UNDERLINE_NONE:
            options |= 0x04
        if self.struck_out:
            options |= 0x08
        if self.outline:
            options |= 0x010
        if self.shadow:
            options |= 0x020

        colour_index = self.colour_index
        weight = self._weight
        escapement = self.escapement
        underline = self.underline
        family = self.family
        charset = self.charset
        name = self.name

        return BIFFRecords.FontRecord(height, options, colour_index, weight,
                                      escapement, underline, family, charset,
                                      name)
Esempio n. 4
0
 def __guts_rec(self):
     self.__update_row_visible_levels()
     col_visible_levels = 0
     if len(self.__cols) != 0:
         col_visible_levels = max([self.__cols[c].level for c in self.__cols]) + 1
     return BIFFRecords.GutsRecord(
         self.__row_gut_width, self.__col_gut_height, self.__row_visible_levels, col_visible_levels).get()
Esempio n. 5
0
 def __defaultrowheight_rec(self):
     options = 0x0000
     options |= (self.row_default_height_mismatch & 1) << 0
     options |= (self.row_default_hidden & 1) << 1
     options |= (self.row_default_space_above & 1) << 2
     options |= (self.row_default_space_below & 1) << 3
     defht = self.__row_default_height
     return BIFFRecords.DefaultRowHeightRecord(options, defht).get()
Esempio n. 6
0
    def __window1_rec(self):
        flags = 0
        flags |= (self.__wnd_hidden) << 0
        flags |= (self.__wnd_mini) << 1
        flags |= (self.__hscroll_visible) << 3
        flags |= (self.__vscroll_visible) << 4
        flags |= (self.__tabs_visible) << 5

        return BIFFRecords.Window1Record(self.__hpos_twips, self.__vpos_twips,
                                self.__width_twips, self.__height_twips,
                                flags,
                                self.__active_sheet, self.__first_tab_index,
                                self.__selected_tabs, self.__tab_width_twips).get()
Esempio n. 7
0
    def __wsbool_rec(self):
        options = 0x00
        options |= (self.__show_auto_page_breaks & 0x01) << 0
        options |= (self.__dialogue_sheet & 0x01) << 4
        options |= (self.__auto_style_outline & 0x01) << 5
        options |= (self.__outline_below & 0x01) << 6
        options |= (self.__outline_right & 0x01) << 7
        options |= (self.__fit_num_pages & 0x01) << 8
        options |= (self.__show_row_outline & 0x01) << 10
        options |= (self.__show_col_outline & 0x01) << 11
        options |= (self.__alt_expr_eval & 0x01) << 14
        options |= (self.__alt_formula_entries & 0x01) << 15

        return BIFFRecords.WSBoolRecord(options).get()
Esempio n. 8
0
 def __calc_settings_rec(self):
     result = b''
     result += BIFFRecords.CalcModeRecord(self.__calc_mode & 0x01).get()
     result += BIFFRecords.CalcCountRecord(self.__calc_count & 0xFFFF).get()
     result += BIFFRecords.RefModeRecord(self.__RC_ref_mode & 0x01).get()
     result += BIFFRecords.IterationRecord(self.__iterations_on & 0x01).get()
     result += BIFFRecords.DeltaRecord(self.__delta).get()
     result += BIFFRecords.SaveRecalcRecord(self.__save_recalc & 0x01).get()
     return result
Esempio n. 9
0
    def __boundsheets_rec(self, data_len_before, data_len_after, sheet_biff_lens):
        #  .................................
        # BOUNDSEHEET0
        # BOUNDSEHEET1
        # BOUNDSEHEET2
        # ..................................
        # WORKSHEET0
        # WORKSHEET1
        # WORKSHEET2
        boundsheets_len = 0
        for sheet in self.__worksheets:
            boundsheets_len += len(BIFFRecords.BoundSheetRecord(
                0x00, sheet.visibility, sheet.name, self.encoding
                ).get())

        start = data_len_before + boundsheets_len + data_len_after

        result = b''
        for sheet_biff_len,  sheet in zip(sheet_biff_lens, self.__worksheets):
            result += BIFFRecords.BoundSheetRecord(
                start, sheet.visibility, sheet.name, self.encoding
                ).get()
            start += sheet_biff_len
        return result
Esempio n. 10
0
    def get_row_biff_data(self):
        height_options = (self.height & 0x07FFF)
        height_options |= (self.has_default_height & 0x01) << 15

        options = (self.level & 0x07) << 0
        options |= (self.collapse & 0x01) << 4
        options |= (self.hidden & 0x01) << 5
        options |= (self.height_mismatch & 0x01) << 6
        options |= (self.__has_default_xf_index & 0x01) << 7
        options |= (0x01 & 0x01) << 8
        options |= (self.__xf_index & 0x0FFF) << 16
        options |= (self.space_above & 1) << 28
        options |= (self.space_below & 1) << 29

        return BIFFRecords.RowRecord(self.__idx, self.__min_col_idx,
                                     self.__max_col_idx, height_options,
                                     options).get()
Esempio n. 11
0
    def __init__(self, encoding='ascii', style_compression=0):
        self.encoding = encoding
        self.__owner = 'None'
        self.__country_code = None # 0x07 is Russia :-)
        self.__wnd_protect = 0
        self.__obj_protect = 0
        self.__protect = 0
        self.__backup_on_save = 0
        # for WINDOW1 record
        self.__hpos_twips = 0x01E0
        self.__vpos_twips = 0x005A
        self.__width_twips = 0x3FCF
        self.__height_twips = 0x2A4E

        self.__active_sheet = 0
        self.__first_tab_index = 0
        self.__selected_tabs = 0x01
        self.__tab_width_twips = 0x0258

        self.__wnd_hidden = 0
        self.__wnd_mini = 0
        self.__hscroll_visible = 1
        self.__vscroll_visible = 1
        self.__tabs_visible = 1

        self.__styles = Style.StyleCollection(style_compression)

        self.__dates_1904 = 0
        self.__use_cell_values = 1

        self.__sst = BIFFRecords.SharedStringTable(self.encoding)

        self.__worksheets = []
        self.__worksheet_idx_from_name = {}
        self.__sheet_refs = {}
        self._supbook_xref = {}
        self._xcall_xref = {}
        self._ownbook_supbookx = None
        self._ownbook_supbook_ref = None
        self._xcall_supbookx = None
        self._xcall_supbook_ref = None
Esempio n. 12
0
    def __panes_rec(self):
        if self.__vert_split_pos is None and self.__horz_split_pos is None:
            return b""

        if self.__vert_split_pos is None:
            self.__vert_split_pos = 0
        if self.__horz_split_pos is None:
            self.__horz_split_pos = 0

        if self.__panes_frozen:
            if self.__vert_split_first_visible is None:
                self.__vert_split_first_visible = self.__vert_split_pos
            if self.__horz_split_first_visible is None:
                self.__horz_split_first_visible = self.__horz_split_pos
        else:
            if self.__vert_split_first_visible is None:
                self.__vert_split_first_visible = 0
            if self.__horz_split_first_visible is None:
                self.__horz_split_first_visible = 0
            # inspired by pyXLWriter
            self.__horz_split_pos = 20*self.__horz_split_pos + 255
            self.__vert_split_pos = int(113.879*self.__vert_split_pos + 390)

        if self.__vert_split_pos > 0 and self.__horz_split_pos > 0:
            self.__split_active_pane = 0
        elif self.__vert_split_pos > 0 and self.__horz_split_pos == 0:
            self.__split_active_pane = 1
        elif self.__vert_split_pos == 0 and self.__horz_split_pos > 0:
            self.__split_active_pane = 2
        else:
            self.__split_active_pane = 3

        result = BIFFRecords.PanesRecord(self.__vert_split_pos,
                                         self.__horz_split_pos,
                                         self.__horz_split_first_visible,
                                         self.__vert_split_first_visible,
                                         self.__split_active_pane).get()
        return result
Esempio n. 13
0
 def __window2_rec(self):
     # Appends SCL record.
     options = 0
     options |= (self.__show_formulas        & 0x01) << 0
     options |= (self.__show_grid            & 0x01) << 1
     options |= (self.__show_headers         & 0x01) << 2
     options |= (self.__panes_frozen         & 0x01) << 3
     options |= (self.show_zero_values       & 0x01) << 4
     options |= (self.__auto_colour_grid     & 0x01) << 5
     options |= (self.__cols_right_to_left   & 0x01) << 6
     options |= (self.__show_outline         & 0x01) << 7
     options |= (self.__remove_splits        & 0x01) << 8
     options |= (self.__selected             & 0x01) << 9
     options |= (self.__sheet_visible        & 0x01) << 10
     options |= (self.__page_preview         & 0x01) << 11
     if self.__page_preview:
         scl_magn = self.__preview_magn
     else:
         scl_magn = self.__normal_magn
     return BIFFRecords.Window2Record(
         options, self.__first_visible_row, self.__first_visible_col,
         self.__grid_colour,
         self.__preview_magn, self.__normal_magn, scl_magn).get()
Esempio n. 14
0
 def __merged_rec(self):
     return BIFFRecords.MergedCellsRecord(self.__merged_ranges).get()
Esempio n. 15
0
 def __dimensions_rec(self):
     return BIFFRecords.DimensionsRecord(
         self.first_used_row, self.last_used_row,
         self.first_used_col, self.last_used_col
         ).get()
Esempio n. 16
0
 def __eof_rec(self):
     return BIFFRecords.EOFRecord().get()
Esempio n. 17
0
 def __tabid_rec(self):
     return BIFFRecords.TabIDRecord(len(self.__worksheets)).get()
Esempio n. 18
0
 def __fngroupcount_rec(self):
     return BIFFRecords.FnGroupCountRecord().get()
Esempio n. 19
0
 def __dsf_rec(self):
     return BIFFRecords.DSFRecord().get()
Esempio n. 20
0
 def __datemode_rec(self):
     return BIFFRecords.DateModeRecord(self.__dates_1904).get()
Esempio n. 21
0
 def __precision_rec(self):
     return BIFFRecords.PrecisionRecord(self.__use_cell_values).get()
Esempio n. 22
0
 def __useselfs_rec(self):
     return BIFFRecords.UseSelfsRecord().get()
Esempio n. 23
0
 def __bookbool_rec(self):
     return BIFFRecords.BookBoolRecord().get()
Esempio n. 24
0
 def __refresh_all_rec(self):
     return BIFFRecords.RefreshAllRecord().get()
Esempio n. 25
0
    def __print_settings_rec(self):
        result = b''
        result += BIFFRecords.PrintHeadersRecord(self.__print_headers).get()
        result += BIFFRecords.PrintGridLinesRecord(self.__print_grid).get()
        result += BIFFRecords.GridSetRecord(self.__grid_set).get()
        result += BIFFRecords.HorizontalPageBreaksRecord(self.__horz_page_breaks).get()
        result += BIFFRecords.VerticalPageBreaksRecord(self.__vert_page_breaks).get()
        result += BIFFRecords.HeaderRecord(self.__header_str).get()
        result += BIFFRecords.FooterRecord(self.__footer_str).get()
        result += BIFFRecords.HCenterRecord(self.__print_centered_horz).get()
        result += BIFFRecords.VCenterRecord(self.__print_centered_vert).get()
        result += BIFFRecords.LeftMarginRecord(self.__left_margin).get()
        result += BIFFRecords.RightMarginRecord(self.__right_margin).get()
        result += BIFFRecords.TopMarginRecord(self.__top_margin).get()
        result += BIFFRecords.BottomMarginRecord(self.__bottom_margin).get()

        setup_page_options =  (self.__print_in_rows & 0x01) << 0
        setup_page_options |=  (self.__portrait & 0x01) << 1
        setup_page_options |=  (0x00 & 0x01) << 2
        setup_page_options |=  (self.__print_not_colour & 0x01) << 3
        setup_page_options |=  (self.__print_draft & 0x01) << 4
        setup_page_options |=  (self.__print_notes & 0x01) << 5
        setup_page_options |=  (0x00 & 0x01) << 6
        setup_page_options |=  (0x01 & 0x01) << 7
        setup_page_options |=  (self.__print_notes_at_end & 0x01) << 9
        setup_page_options |=  (self.__print_omit_errors & 0x03) << 10

        result += BIFFRecords.SetupPageRecord(self.__paper_size_code,
                                self.__print_scaling,
                                self.__start_page_number,
                                self.__fit_width_to_pages,
                                self.__fit_height_to_pages,
                                setup_page_options,
                                self.__print_hres,
                                self.__print_vres,
                                self.__header_margin,
                                self.__footer_margin,
                                self.__copies_num).get()
        return result
Esempio n. 26
0
 def get_biff_data(self):
     return BIFFRecords.FormulaRecord(self.rowx, self.colx, self.xf_idx,
                                      self.frmla.rpn(),
                                      self.calc_flags).get()
Esempio n. 27
0
 def get_biff_data(self):
     return BIFFRecords.BoolErrRecord(self.rowx, self.colx, self.xf_idx,
                                      self.number, 1).get()
Esempio n. 28
0
 def __country_rec(self):
     if not self.__country_code:
         return b''
     return BIFFRecords.CountryRecord(self.__country_code, self.__country_code).get()
Esempio n. 29
0
 def get_biff_data(self):
     return BIFFRecords.MulBlankRecord(self.rowx, self.colx1, self.colx2,
                                       self.xf_idx).get()
Esempio n. 30
0
 def __bof_rec(self):
     return BIFFRecords.Biff8BOFRecord(BIFFRecords.Biff8BOFRecord.WORKSHEET).get()