newbieintown
newbieintown

Reputation: 33

Hiding unused/remaining rows and specific amount of columns excel python

So i successfully wrote my first excel file using python and xlwt. Now, i would like to add to my code. I would like for the remaining rows (the unused rows, or a range that i could enter) to be hidden and the same for columns. Is it at all possible to do this with xlwt? If not, is it possible to do it with using xlsxwriter after creating the file with xlwt in the same script? I'm lost as to how to do this. One line that i have that is giving me problems right now:

    My_Sheet = wb.add_sheet(All_Sheets[0,count],cell_overwrite_ok=True)    
    My_Sheet.set_default_row(hide_unused_rows=True)

This gives me the following error: "AttributeError: 'Worksheet' object has no attribute 'set_default_row' "

Upvotes: 1

Views: 2968

Answers (1)

Barmaley
Barmaley

Reputation: 316

Now, you have an error because xlsxwriter and xlwt worksheet objects haven't set_default_row method. You can read more about woksheet classes by link reference for each-library.

So, you can look into google group, and xlwt examples from this site for more information.

You can hide cells in xlsxwriter by this way:

import xlsxwriter

workbook   = xlsxwriter.Workbook('filename.xlsx')

worksheet = workbook.add_worksheet()
worksheet.write('C3', "Abracadabra!")
worksheet.set_row(2, 2,[], {'hidden': True})

workbook.close()

or in xlwt:

import xlwt

workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('Sheet')

worksheet.write(4, 0, "Abracadabra!")
worksheet.row(4).hidden = 1

workbook.save('filename.xlsx')

In xlwt you also can hid Column objects by this way, but i'm not sure about Cells objects.

Upvotes: 2

Related Questions