Writing to an Excel spreadsheet

后端 未结 12 1868
不知归路
不知归路 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:28

    If your need is to modify an existing workbook, the safest way would be to use pyoo. You need to have some libraries installed and it takes a few hoops to jump through but once its set up, this would be bulletproof as you are leveraging the wide and solid API's of LibreOffice / OpenOffice.

    Please see my Gist on how to set up a linux system and do some basic coding using pyoo.

    Here is an example of the code:

    #!/usr/local/bin/python3
    import pyoo
    # Connect to LibreOffice using a named pipe 
    # (named in the soffice process startup)
    desktop = pyoo.Desktop(pipe='oo_pyuno')
    wkbk = desktop.open_spreadsheet("")
    sheet = wkbk.sheets['Sheet1']
    # Write value 'foo' to cell E5 on Sheet1
    sheet[4,4].value='foo'
    wkbk.save()
    wkbk.close()
    

提交回复
热议问题