Writing to an Excel spreadsheet

后端 未结 12 1857
不知归路
不知归路 2020-11-22 04:39

I am new to Python. I need to write some data from my program to a spreadsheet. I\'ve searched online and there seem to be many packages available (xlwt, XlsXcessive, openpy

12条回答
  •  有刺的猬
    2020-11-22 05:17

    OpenPyxl is quite a nice library, built to read/write Excel 2010 xlsx/xlsm files:

    https://openpyxl.readthedocs.io/en/stable

    The other answer, referring to it is using the deperciated function (get_sheet_by_name). This is how to do it without it:

    import openpyxl
    
    wbkName = 'New.xlsx'        #The file should be created before running the code.
    wbk = openpyxl.load_workbook(wbkName)
    wks = wbk['test1']
    someValue = 1337
    wks.cell(row=10, column=1).value = someValue
    wbk.save(wbkName)
    wbk.close
    

提交回复
热议问题