Пример #1
0
 def __all_links_rec(self):
     supbook_records = ''
     #~ supbook_records += BIFFRecords.AddInFunctionSupBookRecord(len(self.__worksheets)).get()
     supbook_records += BIFFRecords.InternalReferenceSupBookRecord(
         len(self.__worksheets)).get()
     #~ supbook_records += BIFFRecords.ExternalReferenceSupBookRecord(len(self.__worksheets)).get()
     externsheet_record = BIFFRecords.ExternSheetRecord(self.__refs).get()
     return supbook_records + externsheet_record
Пример #2
0
 def __protection_rec(self):
     result = ''
     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
Пример #3
0
 def __hyperlink_table_rec(self):
     result = ''
     for (x, y), (url, target, description) in self.__links.items():
         result += BIFFRecords.HyperlinkRecord(
             x, x, y, y, url, target=target, description=description).get()
         if description is not None:
             result += BIFFRecords.QuicktipRecord(x, x, y, y,
                                                  description).get()
     return result
Пример #4
0
 def get_biff_data(self):
     frmla_block_data = BIFFRecords.FormulaRecord(self.__parent.get_index(),
                                                  self.__idx, self.__xf_idx,
                                                  self.__result,
                                                  self.__opts,
                                                  self.__frmla.rpn()).get()
     if self.__str:
         frmla_block_data += BIFFRecords.StringRecord(self.__str).get()
     return frmla_block_data
Пример #5
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(0x00L, sheet.visibility,
                                             sheet.name, self.encoding).get())

        start = data_len_before + boundsheets_len + data_len_after

        result = ''
        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
Пример #6
0
 def __window2_rec(self):
     # Appends SCL record if required
     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_empty_as_zero   & 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
         if not scl_magn:
             scl_magn = 60 # Excel seems to need an SCL record in this case.
     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()
Пример #7
0
    def __init__(self):
        self.__owner = 'None'
        self.__country_code = 0x07
        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()

        self.__dates_1904 = 0
        self.__use_cell_values = 1

        self.__sst = BIFFRecords.SharedStringTable()

        self.__worksheets = []
        self.__names = []
        self.__refs = []
Пример #8
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()
Пример #9
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)
Пример #10
0
    def __panes_rec(self):
        if self.__vert_split_pos is None and self.__horz_split_pos is None:
            return ""

        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
            if not self.split_position_units_are_twips:
                # inspired by pyXLWriter
                if self.__horz_split_pos > 0:
                    self.__horz_split_pos = 20 * self.__horz_split_pos + 255
                if self.__vert_split_pos > 0:
                    self.__vert_split_pos = 113.879 * self.__vert_split_pos + 390

        result = BIFFRecords.PanesRecord(
            *map(int, (self.__vert_split_pos, self.__horz_split_pos,
                       self.__horz_split_first_visible,
                       self.__vert_split_first_visible,
                       self.active_pane))).get()

        return result
Пример #11
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()
Пример #12
0
 def __default_row_height_rec(self):
     options = 0x00
     options = (0x00 & 0x01) << 0
     options = (self.__default_row_hidden & 0x01) << 1
     options = (self.__default_row_space_above & 0x01) << 2
     options = (self.__default_row_space_below & 0x01) << 3
     return BIFFRecords.DefaultRowHeight(options,
                                         self.__row_default_height).get()
Пример #13
0
    def get_biff_data(self):
        rk_encoded = 0

        packed = struct.pack('<d', self.__number)

        #print self.__number
        w0, w1, w2, w3 = struct.unpack('<4H', packed)
        if w0 == 0 and w1 == 0 and w2 & 0xFFFC == w2:
            # 34 lsb are 0
            #print "float RK"
            rk_encoded = (w3 << 16) | w2
            return BIFFRecords.RKRecord(self.__parent.get_index(), self.__idx,
                                        self.__xf_idx, rk_encoded).get()

        if abs(self.__number) < 0x20000000 and int(
                self.__number) == self.__number:
            #print "30-bit integer RK"
            rk_encoded = (2 | (int(self.__number) << 2)) & 0xffffffffL
            return BIFFRecords.RKRecord(self.__parent.get_index(), self.__idx,
                                        self.__xf_idx, rk_encoded).get()

        temp = self.__number * 100
        packed100 = struct.pack('<d', temp)
        w0, w1, w2, w3 = struct.unpack('<4H', packed100)
        if w0 == 0 and w1 == 0 and w2 & 0xFFFC == w2:
            # 34 lsb are 0
            #print "float RK*100"
            rk_encoded = 1 | (w3 << 16) | w2
            return BIFFRecords.RKRecord(self.__parent.get_index(), self.__idx,
                                        self.__xf_idx, rk_encoded).get()

        if abs(temp) < 0x20000000 and int(temp) == temp:
            #print "30-bit integer RK*100"
            rk_encoded = (3 | (int(temp) << 2)) & 0xffffffffL
            return BIFFRecords.RKRecord(self.__parent.get_index(), self.__idx,
                                        self.__xf_idx, rk_encoded).get()

        #print "Number"
        #print
        return BIFFRecords.NumberRecord(self.__parent.get_index(), self.__idx,
                                        self.__xf_idx, self.__number).get()
Пример #14
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()
Пример #15
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()
Пример #16
0
 def __calc_settings_rec(self):
     result = ''
     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
Пример #17
0
    def __panes_rec(self):
        if self.__vert_split_pos is None and self.__horz_split_pos is None:
            return ""

        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

            # when frozen, the active pane has to be specifically set:
            if self.__vert_split_pos > 0 and self.__horz_split_pos > 0:
                active_pane = 0
            elif self.__vert_split_pos > 0 and self.__horz_split_pos == 0:
                active_pane = 1
            elif self.__vert_split_pos == 0 and self.__horz_split_pos > 0:
                active_pane = 2
            else:
                active_pane = 3
        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
            if not self.split_position_units_are_twips:
                # inspired by pyXLWriter
                if self.__horz_split_pos > 0:
                    self.__horz_split_pos = 20 * self.__horz_split_pos + 255
                if self.__vert_split_pos > 0:
                    self.__vert_split_pos = 113.879 * self.__vert_split_pos + 390

            # when split, the active pain can be set as required:
            active_pane = self.active_pane

        result = BIFFRecords.PanesRecord(*map(int, (
            self.__vert_split_pos,
            self.__horz_split_pos,
            self.__horz_split_first_visible,
            self.__vert_split_first_visible,
            active_pane
            ))).get()

        return result
Пример #18
0
    def print_area(self, sheetnum, rstart, rend, cstart, cend):
        import ExcelFormula
        from struct import pack
        if type(sheetnum) != int:
            for i, ws in enumerate(self.__worksheets):
                if ws.name == sheetnum: sheetnum = i + 1

        options = 0x0020  # see Options Flags for Name record

        # FIXME: this is just a bad hack, need to use Formula to make the rpn
        #~ rpn = ExcelFormula.Formula('').rpn()[2:] # minus the size field
        rpn = pack('<BHHHHH', 0x3B, 0x0000, rstart, rend, cstart, cend)

        return self.__names.append(
            BIFFRecords.NameRecord(options, 0x00, self.macros['Print_Area'],
                                   sheetnum, rpn))
Пример #19
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()
Пример #20
0
    def __window2_rec(self):
        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_empty_as_zero   & 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.__hidden               & 0x01) << 10
        options |= (self.__page_preview         & 0x01) << 11

        return BIFFRecords.Window2Record(options, self.__first_visible_row, self.__first_visible_col,
                                        self.__grid_colour,
                                        self.__preview_magn, self.__normal_magn).get()
Пример #21
0
    def __dimensions_rec(self):
        first_used_row = 0
        last_used_row = 0
        first_used_col = 0
        last_used_col = 0
        if len(self.__rows) > 0:
            first_used_row = min(self.__rows)
            last_used_row = max(self.__rows)
            first_used_col = 0xFFFFFFFF
            last_used_col = 0
            for r in self.__rows:
                _min = self.__rows[r].get_min_col()
                _max = self.__rows[r].get_max_col()
                if _min < first_used_col:
                    first_used_col = _min
                if _max > last_used_col:
                    last_used_col = _max

        return BIFFRecords.DimensionsRecord(first_used_row, last_used_row, first_used_col, last_used_col).get()
Пример #22
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.__custom_palette_b8 = None

        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
Пример #23
0
    def __panes_rec(self):
        if self.__vert_split_pos is None and self.__horz_split_pos is None:
            return ""

        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 = 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
Пример #24
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.explicit_magn_setting:
         # Experimentation: caller can set the scl magn.
         # None -> no SCL record written
         # Otherwise 10 <= scl_magn <= 400 or scl_magn == 0
         # Note: value 0 means use 100 for normal view, 60 for page break preview
         # BREAKING NEWS: Excel interprets scl_magn = 0 very literally, your
         # sheet appears like a tiny dot on the screen
         scl_magn = self.__scl_magn
     else:
         if self.__page_preview:
             scl_magn = self.__preview_magn
             magn_default = 60
         else:
             scl_magn = self.__normal_magn
             magn_default = 100
         if scl_magn == magn_default or scl_magn == 0:
             # Emulate what we think MS does
             scl_magn = None  # don't write an SCL record
     return BIFFRecords.Window2Record(options, self.__first_visible_row,
                                      self.__first_visible_col,
                                      self.__grid_colour,
                                      self.__preview_magn,
                                      self.__normal_magn, scl_magn).get()
Пример #25
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()
Пример #26
0
 def __useselfs_rec(self):
     return BIFFRecords.UseSelfsRecord().get()
Пример #27
0
 def __palette_rec(self):
     if self.__custom_palette_b8 is None: 
         return ''
     info = BIFFRecords.PaletteRecord(self.__custom_palette_b8).get()
     return info
Пример #28
0
 def __bookbool_rec(self):
     return BIFFRecords.BookBoolRecord().get()
Пример #29
0
 def __refresh_all_rec(self):
     return BIFFRecords.RefreshAllRecord().get()
Пример #30
0
 def __precision_rec(self):
     return BIFFRecords.PrecisionRecord(self.__use_cell_values).get()