How to use the pygsheets.utils.format_addr function in pygsheets

To help you get started, we’ve selected a few pygsheets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nithinmurali / pygsheets / pygsheets / worksheet.py View on Github external
estimate_size = False
        if type(crange) == str:
            if crange.find(':') == -1:
                estimate_size = True
        elif type(crange) == tuple:
            estimate_size = True
        else:
            raise InvalidArgumentValue('crange')

        if estimate_size:
            start_r_tuple = format_addr(crange, output='tuple')
            if majordim == 'ROWS':
                end_r_tuple = (start_r_tuple[0]+len(values), start_r_tuple[1]+len(values[0]))
            else:
                end_r_tuple = (start_r_tuple[0] + len(values[0]), start_r_tuple[1] + len(values))
            body['range'] = self._get_range(crange, format_addr(end_r_tuple))
        else:
            body['range'] = self._get_range(*crange.split(':'))
        body['majorDimension'] = majordim
        body['values'] = values
        self.client.sh_update_range(self.spreadsheet.id, body, self.spreadsheet.batch_mode)
github nithinmurali / pygsheets / pygsheets / worksheet.py View on Github external
# @TODO fit the minimum rectangle than whole array
            values = [[None for x in range(self.cols)] for y in range(self.rows)]
            for cell in cell_list:
                values[cell.col-1][cell.row-1] = cell.value
        body = dict()
        estimate_size = False
        if type(crange) == str:
            if crange.find(':') == -1:
                estimate_size = True
        elif type(crange) == tuple:
            estimate_size = True
        else:
            raise InvalidArgumentValue('crange')

        if estimate_size:
            start_r_tuple = format_addr(crange, output='tuple')
            if majordim == 'ROWS':
                end_r_tuple = (start_r_tuple[0]+len(values), start_r_tuple[1]+len(values[0]))
            else:
                end_r_tuple = (start_r_tuple[0] + len(values[0]), start_r_tuple[1] + len(values))
            body['range'] = self._get_range(crange, format_addr(end_r_tuple))
        else:
            body['range'] = self._get_range(*crange.split(':'))
        body['majorDimension'] = majordim
        body['values'] = values
        self.client.sh_update_range(self.spreadsheet.id, body, self.spreadsheet.batch_mode)
github nithinmurali / pygsheets / pygsheets / charts.py View on Github external
def get_anchor_cell(self):
		if self._anchor_cell is None:
			return {
				"columnIndex": self._domain[1][1]-1,
				"rowIndex": self._domain[1][0],"sheetId": self._worksheet.id}
		else:
			cell = format_addr(self._anchor_cell)
			return {
				"columnIndex": cell[1],
				"rowIndex": cell[0]+1,"sheetId": self._worksheet.id}
github nithinmurali / pygsheets / pygsheets / chart.py View on Github external
def _get_anchor_cell(self):
        if self._anchor_cell is None:
            return {
                "columnIndex": self._domain[1][1]-1,
                "rowIndex": self._domain[1][0], "sheetId": self._worksheet.id}
        else:
            if type(self._anchor_cell) is Cell:
                return {
                        "columnIndex": self._anchor_cell.col-1,
                        "rowIndex": self._anchor_cell.row-1, "sheetId": self._worksheet.id}
            else:
                cell = format_addr(self._anchor_cell, 'tuple')
                return {
                    "columnIndex": cell[1]-1,
                    "rowIndex": cell[0]-1, "sheetId": self._worksheet.id}
github nithinmurali / pygsheets / pygsheets / worksheet.py View on Github external
def update_cells(self, crange=None, values=None, cell_list=None, majordim='ROWS'):
        """Updates cells in batch, it can take either a cell list or a range and values

        :param cell_list: List of a :class:`Cell` objects to update with their values
        :param crange: range in format A1:A2 or just 'A1' or even (1,2) end cell will be infered from values
        :param values: matrix of values if range given, if a value is None its unchanged
        :param majordim: major dimension of given data


        """
        if cell_list:
            crange = 'A1:' + str(format_addr((self.rows, self.cols)))
            # @TODO fit the minimum rectangle than whole array
            values = [[None for x in range(self.cols)] for y in range(self.rows)]
            for cell in cell_list:
                values[cell.col-1][cell.row-1] = cell.value
        body = dict()
        estimate_size = False
        if type(crange) == str:
            if crange.find(':') == -1:
                estimate_size = True
        elif type(crange) == tuple:
            estimate_size = True
        else:
            raise InvalidArgumentValue('crange')

        if estimate_size:
            start_r_tuple = format_addr(crange, output='tuple')
github nithinmurali / pygsheets / pygsheets / chart.py View on Github external
def ranges(self, new_ranges):
        if type(new_ranges) is tuple:
            new_ranges = [new_ranges]

        for i in range(len(new_ranges)):
            new_ranges[i] = (format_addr(new_ranges[i][0], 'tuple'), format_addr(new_ranges[i][1], 'tuple'))

        temp = self._ranges
        self._ranges = new_ranges
        try:
            self.update_chart()
        except:
            self._ranges = temp
github nithinmurali / pygsheets / pygsheets / worksheet.py View on Github external
def _get_range(self, start_label, end_label=None):
        """get range in A1 notation, given start and end labels

        """
        if not end_label:
            end_label = start_label
        return self.title + '!' + ('%s:%s' % (format_addr(start_label, 'label'),
                                              format_addr(end_label, 'label')))
github nithinmurali / pygsheets / pygsheets / worksheet.py View on Github external
def _get_range(self, start_label, end_label=None):
        """get range in A1 notation, given start and end labels

        """
        if not end_label:
            end_label = start_label
        return self.title + '!' + ('%s:%s' % (format_addr(start_label, 'label'),
                                              format_addr(end_label, 'label')))
github nithinmurali / pygsheets / pygsheets / worksheet.py View on Github external
def set_dataframe(self, df, start, copy_index=False, copy_head=True, fit=False, escape_formulae=False):
        """
        set the values of a pandas dataframe at cell 

        :param df: pandas dataframe
        :param start: top right cell address from where values are inserted
        :param copy_index: if index should be copied
        :param copy_head: if headers should be copied
        :param fit: should the worksheet should be resized to fit the dataframe
        :param escape_formulae: If any value starts with an equals sign =, it will be
               prefixed with a apostrophe ', to avoid being interpreted as a formula.

        """
        start = format_addr(start, 'tuple')
        values = df.values.tolist()
        end = format_addr(tuple([start[0]+len(values), start[1]+len(values[0])]))
        if copy_index:
            for i in range(values):
                values[i].insert(0, i)
        if copy_head:
            head = df.columns.tolist()
            if copy_index:
                head.insert(0, '')
            values.insert(0, head)
        if fit:
            self.rows = start[0] - 1 + len(values[0])
            self.cols = start[1] - 1 + len(values)
        # @TODO optimize this
        if escape_formulae:
            for row in values:
github nithinmurali / pygsheets / pygsheets / chart.py View on Github external
def domain(self, new_domain):
        new_domain = (format_addr(new_domain[0], 'tuple'), format_addr(new_domain[1], 'tuple'))
        temp = self._domain
        self._domain = new_domain
        try:
            self.update_chart()
        except:
            self._domain = temp