Can python read the value of a cell in a spreadsheet?
Asked Answered
P

3

5

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

Pratfall answered 28/1, 2013 at 19:16 Comment(2)
wiki.openoffice.org/wiki/Python Will give you some links to read up on pyuno and OpenOfficeTiemroth
Check out xlrd and xlwt: python-excel.orgGrubbs
U
1

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

Unlock answered 28/1, 2013 at 21:12 Comment(0)
A
3

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)
Aliform answered 22/11, 2014 at 21:11 Comment(0)
U
1

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

Unlock answered 28/1, 2013 at 21:12 Comment(0)
M
0

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.

Mcalister answered 24/10, 2017 at 19:40 Comment(2)
I ran into the same problem. This mailing thread might help you: mail-archive.com/[email protected]/msg78948.html.Angulation
I eventually 'solved' the problem by running import sys; sys.path.append('/usr/lib/python3/dist-packages')Angulation

© 2022 - 2024 — McMap. All rights reserved.