def _get_rowspan(self, el, v_merge): current_row = self.pre_processor.row_index(el) current_col = self.pre_processor.column_index(el) rowspan = 1 result = '' tbl = find_ancestor_with_tag(self.pre_processor, el, 'tbl') # We only want table cells that have a higher row_index that is greater # than the current_row and that are on the current_col if tbl is None: return '' tcs = [ tc for tc in find_all(tbl, 'tc') if self.pre_processor.row_index(tc) >= current_row and self.pre_processor.column_index(tc) == current_col ] restart_in_v_merge = False if v_merge is not None and 'val' in v_merge.attrib: restart_in_v_merge = 'restart' in v_merge.attrib['val'] def increment_rowspan(tc): if not restart_in_v_merge: return False if not self.pre_processor.vmerge_continue(tc): return False return True for tc in tcs: if increment_rowspan(tc): rowspan += 1 else: rowspan = 1 if rowspan > 1: result = rowspan return str(result)
def parse_r(self, el, parsed): """ Parse the running text. """ text = parsed if not text: return '' run_properties = {} # Get the rPr for the current style, they are the defaults. p = find_ancestor_with_tag(self.pre_processor, el, 'p') paragraph_style = self.memod_tree_op('find_first', p, 'pStyle') if paragraph_style is not None: style = paragraph_style.get('val') style_defaults = self.styles_dict.get(style, {}) run_properties.update( style_defaults.get('default_run_properties', {}), ) # Get the rPr for the current r tag, they are overrides. run_properties_element = el.find('rPr') if run_properties_element: local_run_properties = self._parse_run_properties( run_properties_element, ) run_properties.update(local_run_properties) inline_tag_handlers = { 'b': self.bold, 'i': self.italics, 'u': self.underline, 'caps': self.caps, 'smallCaps': self.small_caps, 'strike': self.strike, 'dstrike': self.strike, 'vanish': self.hide, 'webHidden': self.hide, } styles_needing_application = [] for property_name, property_value in run_properties.items(): # These tags are a little different, handle them separately # from the rest. # This could be a superscript or a subscript if property_name == 'vertAlign': if property_value == 'superscript': styles_needing_application.append(self.superscript) elif property_value == 'subscript': styles_needing_application.append(self.subscript) else: if (property_name in inline_tag_handlers and self._is_style_on(property_value)): styles_needing_application.append( inline_tag_handlers[property_name], ) # Apply all the handlers. for func in styles_needing_application: text = func(text) return text
def parse_r(self, el, parsed): """ Parse the running text. """ text = parsed if not text: return "" run_properties = {} # Get the rPr for the current style, they are the defaults. p = find_ancestor_with_tag(self.pre_processor, el, "p") paragraph_style = self.memod_tree_op("find_first", p, "pStyle") if paragraph_style is not None: style = paragraph_style.get("val") style_defaults = self.styles_dict.get(style, {}) run_properties.update(style_defaults.get("default_run_properties", {})) # Get the rPr for the current r tag, they are overrides. run_properties_element = el.find("rPr") if run_properties_element: local_run_properties = self._parse_run_properties(run_properties_element) run_properties.update(local_run_properties) inline_tag_handlers = { "b": self.bold, "i": self.italics, "u": self.underline, "caps": self.caps, "smallCaps": self.small_caps, "strike": self.strike, "dstrike": self.strike, "vanish": self.hide, "webHidden": self.hide, } styles_needing_application = [] for property_name, property_value in run_properties.items(): # These tags are a little different, handle them separately # from the rest. # This could be a superscript or a subscript if property_name == "vertAlign": if property_value == "superscript": styles_needing_application.append(self.superscript) elif property_value == "subscript": styles_needing_application.append(self.subscript) else: if property_name in inline_tag_handlers and self._is_style_on(property_value): styles_needing_application.append(inline_tag_handlers[property_name]) # Apply all the handlers. for func in styles_needing_application: text = func(text) return text
def _get_rowspan(self, el, v_merge): restart_in_v_merge = False if v_merge is not None and 'val' in v_merge.attrib: restart_in_v_merge = 'restart' in v_merge.attrib['val'] if not restart_in_v_merge: return -1 current_row = self.pre_processor.row_index(el) current_col = self.pre_processor.column_index(el) rowspan = 1 result = -1 tbl = find_ancestor_with_tag(self.pre_processor, el, 'tbl') # We only want table cells that have a higher row_index that is greater # than the current_row and that are on the current_col if tbl is None: return -1 tcs = [ tc for tc in self.memod_tree_op( '_get_tcs_in_column', tbl, current_col, ) if self.pre_processor.row_index(tc) >= current_row ] def should_increment_rowspan(tc): if not self.pre_processor.vmerge_continue(tc): return False return True for tc in tcs: if should_increment_rowspan(tc): rowspan += 1 else: rowspan = 1 if rowspan > 1: result = rowspan return result
def parse_r(self, el, parsed): """ Parse the running text. """ text = parsed if not text: return '' run_properties = {} # Get the rPr for the current style, they are the defaults. p = find_ancestor_with_tag(self.pre_processor, el, 'p') paragraph_style = self.memod_tree_op('find_first', p, 'pStyle') if paragraph_style is not None: style = paragraph_style.get('val') style_defaults = self.styles_dict.get(style, {}) run_properties.update( style_defaults.get('default_run_properties', {}), ) # Get the rPr for the current r tag, they are overrides. run_properties_element = el.find('rPr') if run_properties_element: local_run_properties = self._parse_run_properties( run_properties_element, ) run_properties.update(local_run_properties) inline_tag_types = { 'b': types.OnOff, 'i': types.OnOff, 'u': types.Underline, 'caps': types.OnOff, 'smallCaps': types.OnOff, 'strike': types.OnOff, 'dstrike': types.OnOff, 'vanish': types.OnOff, 'webHidden': types.OnOff, } inline_tag_handlers = { 'b': self.bold, 'i': self.italics, 'u': self.underline, 'caps': self.caps, 'smallCaps': self.small_caps, 'strike': self.strike, 'dstrike': self.strike, 'vanish': self.hide, 'webHidden': self.hide, } styles_needing_application = [] for property_name, property_value in run_properties.items(): # These tags are a little different, handle them separately # from the rest. # This could be a superscript or a subscript if property_name == 'vertAlign': if property_value == 'superscript': styles_needing_application.append(self.superscript) elif property_value == 'subscript': styles_needing_application.append(self.subscript) else: if ( property_name in inline_tag_handlers and inline_tag_types.get(property_name)(property_value) ): styles_needing_application.append( inline_tag_handlers[property_name], ) # Apply all the handlers. for func in styles_needing_application: text = func(text) return text