# Getting the content of a spreadSheet in python list with pvpython

**URL:** https://discourse.paraview.org/t/getting-the-content-of-a-spreadsheet-in-python-list-with-pvpython/3926
**Category:** ParaView Support
**Tags:** python
**Created:** [March 31, 2020, 1:02pm UTC](https://discourse.paraview.org/t/getting-the-content-of-a-spreadsheet-in-python-list-with-pvpython/3926 "2020-03-31T13:02:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Lorenzo\_Cozzi](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lorenzo_cozzi/32/3171_2.png) [@Lorenzo\_Cozzi](https://discourse.paraview.org/u/Lorenzo_Cozzi)
#### Post date: [March 31, 2020, 1:02pm UTC](https://discourse.paraview.org/t/getting-the-content-of-a-spreadsheet-in-python-list-with-pvpython/3926/1 "2020-03-31T13:02:05Z")

</div>

Dear all,  
I’m trying to compute area average distributions of flow quantities with a pvpython script. To perform the computations I need to get in my python script some quantities that are present in a spreadsheet that I managed to create. The problem is that the only way I figured out to get the quantities I need is to export the spreadsheet content in a csv file and then read it in my python script, which is definitely not an effective strategy…

Once created the spreadsheet with the commands:

> spreadSheetView1 = CreateView(‘SpreadSheetView’)  
> extractBlock1Display\_1 = Show(extractBlock1, spreadSheetView1, ‘SpreadSheetRepresentation’)  
> spreadSheetView1.FieldAssociation = ‘Point Data’

What should I do to get its content in a python list?

Thanks in advance!!

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [April 1, 2020, 2:02am UTC](https://discourse.paraview.org/t/getting-the-content-of-a-spreadsheet-in-python-list-with-pvpython/3926/2 "2020-04-01T02:02:39Z")

</div>

You can’t recover the spreadsheet content directly, and in any case, that’s not what you want to do as the spreadsheet does not contain all your data but only what is currently visible.

But, this is of course a solution :

1. Simple but costly solution : Fetch

`data = servermanager.Fetch(extractBlock1)` give you access to the vtk object containing your data. You can then work with it as if you were in vtkPython. It is costly as it requires to transmit the dataset from the server to the client, which is a non-issue if you are working with a built-in server.

1. Complex but more paraview-style solution : ProgrammableFilter

You can write your average distribution computation in a Programmable Filter, trigger the computation and then do what you want with the results. It is more efficient as the data stays on the server. Also, you may want to make sure that the computation you are looking to do can’t be done with already existing filters in ParaView.

hth.

---

<div class="post-metadata">

### Author: ![Lorenzo\_Cozzi](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lorenzo_cozzi/32/3171_2.png) [@Lorenzo\_Cozzi](https://discourse.paraview.org/u/Lorenzo_Cozzi)
#### Post date: [April 1, 2020, 9:33am UTC](https://discourse.paraview.org/t/getting-the-content-of-a-spreadsheet-in-python-list-with-pvpython/3926/3 "2020-04-01T09:33:35Z")

</div>

I tried with the Fetch option but still couldn’t manage to totally solve the problem. I used as example case the output of an extractBlock filter. This is the way I managed to get the points coordinates in a list of tuples:

> data = paraview.servermanager.Fetch(extractBlock1,0)  
> blockData = data.GetBlock(0)  
> npoints = blockData.GetNumberOfPoints()
> 
> points =   
> for i in range(npoints):  
> points.append(blockData.GetPoint(i))

blockData is a vtkUnstructuredGrid object, I could not find a way to assign directly these coordinates to a list without adopting the shown for loop. Furthermore, I was not able to get the data stored in this grid file (e.g. the Pressure stored in “Array 0 name” in Point Data within the Unstructured grid). I had a look at “vtkUnstructuredGrid Class Reference”, but did not find examples of the case I’m dealing with.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [April 2, 2020, 3:11am UTC](https://discourse.paraview.org/t/getting-the-content-of-a-spreadsheet-in-python-list-with-pvpython/3926/4 "2020-04-02T03:11:10Z")

</div>

`blockData.GetPoints().GetData()`

Then use the numpy interface.

> **[Improved VTK - numpy integration - Kitware Blog](https://blog.kitware.com/improved-vtk-numpy-integration/)**
>
> Recently, we introduced a new Python module called numpy\_interface to VTK. The main objective of this module is to make it easier to interface VTK ... Read More

---

<div class="post-metadata">

### Author: ![Lorenzo\_Cozzi](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lorenzo_cozzi/32/3171_2.png) [@Lorenzo\_Cozzi](https://discourse.paraview.org/u/Lorenzo_Cozzi)
#### Post date: [April 2, 2020, 7:28am UTC](https://discourse.paraview.org/t/getting-the-content-of-a-spreadsheet-in-python-list-with-pvpython/3926/5 "2020-04-02T07:28:30Z")

</div>

Thanks!
