Showing Grid Lines

577 views
Skip to first unread message

bonnie.el...@gmail.com

unread,
Jul 8, 2013, 5:07:46 PM7/8/13
to python...@googlegroups.com
I am using Python to create an excel spreadsheet. What is the easiest way to make the grid lines appear on the spreadsheet? I have other formatting styles applied to certain rows and columns already. The only way I know how to do it is with borders (and this is quite complex, for I have to go around the styles already applied...) Thank you in advance!

Bonnie

Adrian Klaver

unread,
Jul 8, 2013, 7:06:31 PM7/8/13
to python...@googlegroups.com, bonnie.el...@gmail.com
Something along lines of:

wb = xlwt.Workbook()
ws = wb.add_sheet(sheet_name)
ws.print_grid = True

>
> Bonnie



--
Adrian Klaver
adrian...@gmail.com

bonnie.el...@gmail.com

unread,
Jul 9, 2013, 8:14:53 AM7/9/13
to python...@googlegroups.com, bonnie.el...@gmail.com
That does not work. I think that the styles I have applied already override the grid...Any other ideas?

John Machin

unread,
Jul 9, 2013, 6:19:10 PM7/9/13
to python...@googlegroups.com, bonnie.el...@gmail.com
It does depend on WHERE you want the grid lines to appear:

screen: Worksheet.show_grid # default is ON
printer: Worksheet.print_grid # default is OFF

but as the "show" variety defaults to "on", I guess this doesn't help.

What would help is a SMALL print_grid_defect.py which contains no proprietary/private information and which reproduces your problem.
Message has been deleted

bonnie.el...@gmail.com

unread,
Jul 10, 2013, 2:59:05 PM7/10/13
to python...@googlegroups.com, bonnie.el...@gmail.com
Please ignore the previous example as I have cut down the code. Use the attachment 'revised.py' instead. My apologies for any confusion. Thanks again!

-Bonnie

On Wednesday, July 10, 2013 1:19:46 PM UTC-4, bonnie.el...@gmail.com wrote:
I have attached my code ('example,py'). Thanks so much for your time!

-Bonnie
revised.py

John Yeung

unread,
Jul 10, 2013, 3:46:49 PM7/10/13
to python-excel, bonnie.el...@gmail.com
John Machin pointed out earlier:

>> On Tuesday, July 9, 2013 6:19:10 PM UTC-4, John Machin wrote:
>>>
>>> It does depend on WHERE you want the grid lines to appear:
>>>
>>> screen: Worksheet.show_grid # default is ON
>>> printer: Worksheet.print_grid # default is OFF
>>>
>>> but as the "show" variety defaults to "on", I guess this doesn't help.

Notice the difference between show_grid and print_grid.

Are you trying to make a grid appear on the printed (paper) output?
Or do you want a grid to appear on the screen?

John Y.

bonnie.el...@gmail.com

unread,
Jul 10, 2013, 3:50:57 PM7/10/13
to python...@googlegroups.com, bonnie.el...@gmail.com
I would like the grid to appear both on the screen and when printed.

Bonnie

John Machin

unread,
Jul 10, 2013, 6:14:43 PM7/10/13
to python...@googlegroups.com, bonnie.el...@gmail.com


On Thursday, July 11, 2013 5:50:57 AM UTC+10, bonnie.el...@gmail.com wrote:
I would like the grid to appear both on the screen and when printed.

 So why don't you include
    sheet1.print_grid = True
in your code
????
 

bonnie.el...@gmail.com

unread,
Jul 10, 2013, 7:06:55 PM7/10/13
to python...@googlegroups.com, bonnie.el...@gmail.com
I am focusing on having the grid show on the screen, which is not happening with print nor show grid. Is that not the case with you?

Bonnie 

Adrian Klaver

unread,
Jul 10, 2013, 7:15:23 PM7/10/13
to python...@googlegroups.com, bonnie.el...@gmail.com
On 07/10/2013 04:06 PM, bonnie.el...@gmail.com wrote:
> I am focusing on having the grid show on the screen, which is not
> happening with print nor show grid. Is that not the case with you?

I see the grid on the screen. What happens if you do?:
sheet1.show_grid = False

What program are you using to view the file?

Adrian Klaver

unread,
Jul 10, 2013, 7:24:41 PM7/10/13
to python...@googlegroups.com, bonnie.el...@gmail.com
On 07/10/2013 04:06 PM, bonnie.el...@gmail.com wrote:
> I am focusing on having the grid show on the screen, which is not
> happening with print nor show grid. Is that not the case with you?

I am using LibreOffice and there are options to toggle the display(or
not) of the grid lines, that override the file setting. Are you sure you
do not have something similar set?

bonnie.el...@gmail.com

unread,
Jul 11, 2013, 8:15:39 AM7/11/13
to python...@googlegroups.com, bonnie.el...@gmail.com
Nothing changes if I do: sheet1.show_grid = False.

I am using anaconda/spyder. Perhaps I do have something similar set that overrides the file setting, but I am unable to find it.

Bonnie

Adrian Klaver

unread,
Jul 11, 2013, 9:22:25 AM7/11/13
to python...@googlegroups.com, bonnie.el...@gmail.com
On 07/11/2013 05:15 AM, bonnie.el...@gmail.com wrote:
> Nothing changes if I do: sheet1.show_grid = False.
>
> I am using anaconda/spyder. Perhaps I do have something similar set that
> overrides the file setting, but I am unable to find it.

I meant what program are you using to open the spreadsheet file and view
it, i.e Excel, LibreOffice, etc?

bonnie.el...@gmail.com

unread,
Jul 11, 2013, 11:43:22 AM7/11/13
to python...@googlegroups.com, bonnie.el...@gmail.com
Oh I am using Excel to open the spreadsheet file. I found an option to view the grid lines or not in Excel. It is turned on, however the grid is very faint (not black) in unoccupied areas and does not go over background colors I have applied. For example, I created multiple rows of data, entered in the data using python, and made the backgrounds blue. The grid then disappeared as the blue background covered it.

Bonnie

bonnie.el...@gmail.com

unread,
Jul 11, 2013, 11:43:48 AM7/11/13
to python...@googlegroups.com, bonnie.el...@gmail.com
Oh I am using Excel to open the spreadsheet file. I found an option to view the grid lines or not in Excel. It is turned on, however the grid is very faint (not black) in unoccupied areas and does not go over background colors I have applied. For example, I created multiple rows of data, entered in the data using python, and made the backgrounds blue. The grid then disappeared as the blue background covered it.

Bonnie

On Thursday, July 11, 2013 9:22:25 AM UTC-4, aklaver wrote:

John Yeung

unread,
Jul 11, 2013, 12:16:22 PM7/11/13
to python-excel, bonnie.el...@gmail.com
On Thu, Jul 11, 2013 at 11:43 AM, <bonnie.el...@gmail.com> wrote:
> Oh I am using Excel to open the spreadsheet file. [...]
> the grid is very faint (not black) in unoccupied areas and
> does not go over background colors I have applied.

That's how the screen grid works in Excel. What you want is to set
borders. These will be visible on the screen and in print.

Unfortunately, the process is currently quite tedious. See the
tutorial PDF for information (not just on borders, incidentally):

http://www.simplistix.co.uk/presentations/python-excel.pdf

You will need to change any styles that you're currently using to also
include borders. Further, if there are currently cells that are not
explicitly styled (that is, they rely on the default formatting), you
will need to create styles for them, to add the borders.

John Y.

bonnie.el...@gmail.com

unread,
Jul 12, 2013, 11:31:12 AM7/12/13
to python...@googlegroups.com, bonnie.el...@gmail.com
Will do. Thanks for all the help everyone!

Bonnie
Reply all
Reply to author
Forward
0 new messages