Can python read the value of a cell in a spreadsheet?

╄→гoц情女王★ 提交于 2019-12-12 14:23:04

问题


All,

Can python read the value of a cell in a spreadsheet?

From a mapping/GIS/analysis standpoint: the simplest example would be a script that ran a buffer (proximity) tool on a given shapefile (GIS dataset).

For the buffer distance parameter, instead of just using a number like '1000' feet, the script would point to a value in a cell of a spreadsheet (libre or open office preferred).

If there was then a way to trigger the script from the spreadsheet by way of a button, that would be the next step (then the next step would be to have a map control inside the spreadsheet to see the updated results!)

Just to give some insight into where I'm going with this: I'd like to use a spreadsheet as an analysis 'dashboard' where users could run analysis with different parameters - what would proximity around parks (grocery stores, etc.) be at 1/2 mi vs 1/4 mi...then another sheet in the spreadsheet would have a breakdown of the demographics within that proximity.

Thank you!!!

(also posted here: https://gis.stackexchange.com/questions/49288/can-python-read-the-value-of-a-cell-in-a-spreadsheet)

-mb


回答1:


There are a few great Python-Excel tools available: http://www.python-excel.org




回答2:


pyoo is a simple package. Install

python-uno
python3-uno

Then install pyoo

python setup.py install
python3 setup.py install

run soffice (LibreOffice or OpenOffice)

soffice --accept="socket,host=localhost,port=2002;urp;" --norestore --nologo --nodefault # --headless

The following script shows how it works in python

desktop = pyoo.Desktop('localhost', 2002)
doc = desktop.open_spreadsheet(path)
sheet = doc.sheets[0]
for i in range(0,14):
  for j in range(0,4):
    print(sheet[i,j].value)



回答3:


It's all great but soo vague. Where do you execute the install command? And even if you somehow figure out you have to go to the pip3.6.exe excript and run it from there, it won't find python3-uno. It will fin python-uno but even then you won't run any script with import uno in the beginning because of missing elements, which are somehow impossible to get. It is stupidly hard to do even the simplest thing this way in LibreOffice.



来源:https://stackoverflow.com/questions/14569434/can-python-read-the-value-of-a-cell-in-a-spreadsheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!