Openpyxl 在单个单元格中写入

Openpyxl to write in a single cell

我正在使用 openpyxl 通过附加函数将数据写入特定单元格而不是行。 方法是什么?

我已经尝试使用以下代码段:

variable = wb2s1.append(row = 4, column = 2)

variable = wb2s1.cell(row = 4, column = 2)

variable = wb2s1.cell(row = 4, column = 2).value

但没有任何效果。感谢任何帮助。

尝试:

wb2s1.append({'A' : 'This is A1', 'C' : 'This is C1'})

来自源代码(http://openpyxl.readthedocs.org/en/latest/api/openpyxl.worksheet.html#openpyxl.worksheet.worksheet.Worksheet.append):

def append(self, list_or_dict):
    """Appends a group of values at the bottom of the current sheet.

    * If it's a list: all values are added in order, starting from the first column
    * If it's a dict: values are assigned to the columns indicated by the keys (numbers or letters)

    :param list_or_dict: list or dict containing values to append
    :type list_or_dict: list/tuple or dict

    Usage:

    * append(['This is A1', 'This is B1', 'This is C1'])
    * **or** append({'A' : 'This is A1', 'C' : 'This is C1'})
    * **or** append({0 : 'This is A1', 2 : 'This is C1'})

编辑:使用官方文档站点

difference = (cost_with - cost_without)/100

if b == 1:
    max_difference = difference
    currentRow = ['PV Size' + ' ' + str(size), difference]
else:
    currentRow.append(difference)

if max_difference > difference:
    max_difference = difference

if b==6:
   wb2s1.append(currentRow)

差异 = (cost_with - cost_without)/100

        if b ==1:
            max_difference = difference

        if max_difference > difference:
            max_difference = difference

        wb2s1.append(['PV Size' + ' ' + str(size), difference])
        data = {difference}

        if b==6:
           wb2s1.append([data])