473,513 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pyExcelerator - Protecting Cells

I'm sitting with a bit of an issue with pyExcelerator and creating an
Excel file with certain cells protected while the rest of the
spreadsheet is password protected.

The Protection class under Formatting has 2 variables for cell_locked
and formula_hidden, tbh I only need to alter cell_locked to 0 to make
those cells writable but changing that on a global scale ends up with
everything I write being "writeable" if you re-open the file after it
has been produced.

I decided to import Formatting into the Worksheet module like this:
import Formatting
self.Formatting = Formatting.Protection

self.__cell_protect = 1
self.__formula_hidden = 0

which is the defaults in the Protection class anyway but now when I do
my create file routine when I try to change the cell_protect variable
to 0 it makes absolutely no effect. The code has been written as
such:

if protection:
work_sheet.set_protect(protection)
work_sheet.set_password(password)
else:
pass

for each_heading in each_work_sheet[1]:
work_sheet.write(7, heading_cnt, str(each_heading),
header_style)
heading_cnt += 1

vert_cnt = 8

for each_set in each_work_sheet[2]:
horiz_cnt = 0

for data_set in each_set:
work_sheet.cell_protect = 1
work_sheet.formula_hidden = 1

if len(str(data_set)) < 1:
work_sheet.cell_protect = 0
work_sheet.formula_hidden = 0
work_sheet.write(vert_cnt, horiz_cnt, ' ')
horiz_cnt += 1
else:
work_sheet.write(vert_cnt, horiz_cnt,
str(data_set), data_style)
horiz_cnt += 1

vert_cnt += 1

As you can see I only want to be able to write to cells that have a
string '' which is parsed correctly through to data which was
originally extracted from a database. The problem is that I can only
seem to set it to protect all written cells or not.

Any advice or help would be most appreciated. :)
Chris

Feb 9 '07 #1
1 1751
On 9/02/2007 6:36 PM, Chris wrote:
I'm sitting with a bit of an issue with pyExcelerator and creating an
Excel file with certain cells protected while the rest of the
spreadsheet is password protected.

The Protection class under Formatting has 2 variables for cell_locked
and formula_hidden, tbh I only need to alter cell_locked to 0 to make
those cells writable but changing that on a global scale ends up with
everything I write being "writeable" if you re-open the file after it
has been produced.
"tbh" means what?
"changing that on a global scale" means what??

Please write a small *test* script (along the lines of those in
pyExcelerator's examples directory, without
irrelevant/private/otherwise_inappropriate code from your app) which
tries to set some cells to locked and some to unlocked. If you can't get
it to work:
(1) ensure that you have checked the bug register on Sourceforge and
applied any patch that seems relevant to your problem
(2) come back here with a copy/paste of the actual code that you have run.
I decided to import Formatting into the Worksheet module like this:
Why? What made you think that this would achieve your goal?
import Formatting
self.Formatting = Formatting.Protection

self.__cell_protect = 1
self.__formula_hidden = 0

which is the defaults in the Protection class anyway but now when I do
my create file routine when I try to change the cell_protect variable
to 0 it makes absolutely no effect.
Of course it would have no effect. You appear to have given Worksheet
objects a gratuitous __cell_protect attribute -- but no code to use it.

Protection is like a pattern or a font -- you have to cram it into an
XFStyle object which you use as the style arg of the Worksheet.write()
method. You will need of course at least 2 different XFStyle objects:
one locked, another unlocked.
The code has been written as
such:

if protection:
work_sheet.set_protect(protection)
work_sheet.set_password(password)
else:
pass
What induced you to write the above two statements?
>
for each_heading in each_work_sheet[1]:
work_sheet.write(7, heading_cnt, str(each_heading),
header_style)
heading_cnt += 1

vert_cnt = 8

for each_set in each_work_sheet[2]:
horiz_cnt = 0

for data_set in each_set:
work_sheet.cell_protect = 1
Now the Worksheet object has *TWO* useless attributes, one named
__cell_protect and one named cell_protect ...
work_sheet.formula_hidden = 1

if len(str(data_set)) < 1:
work_sheet.cell_protect = 0
work_sheet.formula_hidden = 0
work_sheet.write(vert_cnt, horiz_cnt, ' ')
horiz_cnt += 1
else:
work_sheet.write(vert_cnt, horiz_cnt,
str(data_set), data_style)
horiz_cnt += 1

vert_cnt += 1

As you can see I only want to be able to write to cells that have a
string '' which is parsed correctly through to data which was
originally extracted from a database. The problem is that I can only
seem to set it to protect all written cells or not.
HTH,
John
Feb 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3625
by: Marco Aschwanden | last post by:
Hi, Yesterday I placed a bug report on PyExcelerators-Sourceforge-page... but I am not so sure anymore, whether this is really a bug - I could imagine that I missed something, but I don't see...
2
10384
by: tkpmep | last post by:
I have just installed PyExcelerator, and now want to use it to read Excel spreadsheets with a variable number of rows and columns and with multiple sheets. Unfortunately, no documentation seems to...
1
3228
by: tkpmep | last post by:
I write data to Excel files using PyExcelerator 0.6.3.a and have done so successfully for small files (10-15 cells). I'm experiencing an error when writing a big chunk of data (10,000 cells) to...
3
13564
by: implicate_order | last post by:
Greetings, I'm new to python and am in the process of writing a script to parse some CSV data, spread it across multiple Excel worksheets and then generate charts. I searched the internet to...
2
1838
by: Gerry | last post by:
I'd like to word wrap some cells, but not others, in an Excel spreadsheet, using pyExcelerator and Excel 2003, SP1, under XP. The code below creates the spreadsheet, but both cells are...
5
8066
by: susan | last post by:
Hi, I'm new of Python, and this problem stucked me whole day but can't be solved. I use python 2.4.3, which is download from cygwin packages. Then I downloaded pyexcelerator-0.5.3a, unzip it, ...
3
1757
by: tkpmep | last post by:
My program creates three lists: the first has dates expressed as strings, the second has floats that are strictly positive, and the third has floats that are strictly negative. I have no trouble...
0
897
by: Fonix | last post by:
Does any one know is there method to unmerge cells and how it named in pyExcelerator ?
1
1270
by: A_H | last post by:
Hi, I'm using PyExcelerator, and it's great, but I can't figure out a few things: (1) I set the cell style to '0.00%' but the style does not work. (2) I want to place a border around the...
0
7259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.