Question: I have a grid from research tools saved as shapefile. I want to display the center coordinate of each grid square in the attribute table.

Answer: 
EDIT: I first thought that your squares were polygons. If they are lines, you need to convert the lines to polygons (vector > geometry tools > Lines to polygon) , then you can apply the method below (for polygons)

In the attribute table, you can compute the X and Y coordinates of the centroid (=the point at the center of the grid square) using the field calculator. The explicit (for X, but of course it also works fo Y) syntax is

```
x(centroid($geometry))

```

but in fact you can use the shortcut

```
x($geometry)

```

[![enter image description here](https://i.stack.imgur.com/bmJOO.png)](https://i.stack.imgur.com/bmJOO.png)
I polygonized the grid, then used centroid. 

Strangely lines to polygon did not work, but polygonize did.