简体   繁体   中英

How to get from numeric cell address to Excell format python in xlsxWriter

import xlsxwriter

I have cell like

Ex1: form1 = worksheet.write(0, 0, 'Foo', format)

The actual address like this 'A1'.

Like Ex2: form2 = worksheet.write(8, 27 'Foo', format)

The cell address is AB8

How to get the values like 'A1' and 'AB8' from numeric. Is there any function in xlsxwriter or any logic have to written.

Because if we are giving

worksheet. write_formula (row_Number, Col_Num+1,'{=SUM(row_number,Col_Num-len(issueList)+1,row_Number,Col_Num)}')/

Instead doing the summation '{=SUM(row_number,Col_Num-len(issueList)+1,row_Number,Col_Num)}' .only text it is printing.

Thanks in advance.

XlsxWriter has several utility functions for converting to and from A1 notation. See the Working with Cell Notation section of the docs. For example:

from xlsxwriter.utility import xl_rowcol_to_cell

cell = xl_rowcol_to_cell(1, 2)  # C2

For your case you could use something like the following:

import xlsxwriter
from xlsxwriter.utility import xl_rowcol_to_cell

workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()

row_num = 5
col_num = 3

print xl_rowcol_to_cell(row_num, col_num)  # D6

worksheet.write_formula(0, 0,
                        '{=SUM(%s, %s)}' % (xl_rowcol_to_cell(row_num, col_num),
                                            xl_rowcol_to_cell(row_num, col_num + 1)))

workbook.close()

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM