473,657 Members | 2,680 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.Prot ection

self.__cell_pro tect = 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(protect ion)
work_sheet.set_ password(passwo rd)
else:
pass

for each_heading in each_work_sheet[1]:
work_sheet.writ e(7, heading_cnt, str(each_headin g),
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.form ula_hidden = 1

if len(str(data_se t)) < 1:
work_sheet.cell _protect = 0
work_sheet.form ula_hidden = 0
work_sheet.writ e(vert_cnt, horiz_cnt, ' ')
horiz_cnt += 1
else:
work_sheet.writ e(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 1756
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_inapp ropriate 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.Prot ection

self.__cell_pro tect = 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(protect ion)
work_sheet.set_ password(passwo rd)
else:
pass
What induced you to write the above two statements?
>
for each_heading in each_work_sheet[1]:
work_sheet.writ e(7, heading_cnt, str(each_headin g),
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.form ula_hidden = 1

if len(str(data_se t)) < 1:
work_sheet.cell _protect = 0
work_sheet.form ula_hidden = 0
work_sheet.writ e(vert_cnt, horiz_cnt, ' ')
horiz_cnt += 1
else:
work_sheet.writ e(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
3637
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 what. Please confirm that my bug is due to mishandling and I will gladly retreat my bug report. In a formula, I would like to point to a field on another worksheet. pyExcelerator chokes on these references!
2
10393
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 accompany PyExcelerator. Does anyone know of a good source of documentations and/or examples? The author provides some examples, but these tend to involve writing data into spreadsheets one cell at a time. Thanks in advance Thomas Philips
1
3253
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 Excel. By way of comparison, the same data writes perfectly well to a csv file using Python's built in csv module. I run the program in PyScripter, and the traceback shows the following sequence of calls: main (my routine)...
3
13596
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 find some place where I could look up a HOWTO doc/recipe to do that using either pyExcelerator or win32com.client. Could someone point me in the right direction? I'm at the stage where the spreadsheet and associated data worksheets
2
1842
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 word-wrapped. As far as I can tell, the second call to XFStyle() overwrites a GLOBAL wrap setting, and affects even cells written before the call to XFStyle.
5
8074
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, $ python ./pyExcelerator/setup.py install running install running build
3
1765
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 writing the data in these lists to a .csv file using the csv module using the following code. outfile = file(fn + '.csv','wb') writer = csv.writer(outfile) for i in range(len(dateList)): writer.writerow(, posVals, negVals])
0
903
by: Fonix | last post by:
Does any one know is there method to unmerge cells and how it named in pyExcelerator ?
1
1279
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 cells( x1, y1, x2, y2 ) but I can't find any example of doing that. Well I do see ONE example, but it erases the cells if I do it after, or when I write to the cells that erases the outline.
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7347
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.