How to protect individual cell using phpspreadsheet - phpspreadsheet

I want to protect particular cell content from being amended. When I tried to protect whole sheet, no problem.
$sheet->getProtection()->setSheet(true)->setDeleteRows(true);
But, could not set protection for individual cell. I tried the following codes.
1
$sheet->protectCellsByColumnAndRow(0, 1, 100, 100, 'asdf');
2
$sheet->protectCells('A1','password',false);
Thanks in advance.

Here is the solution. First, enable the worksheet protection. Then, unlock all the cell by change the default style of spreadsheet's protection. After that, lock the cell you want by specify the cell's coordinate. The worksheet protection applied to locked cell only. So, the cell that you locked could not be edited anymore when you open that worksheet.
$spreadsheet->getActiveSheet()->getProtection()->setSheet(true);
$spreadsheet->getDefaultStyle()->getProtection()->setLocked(false);
$sheet->getStyle('A1')->getProtection()->setLocked(\PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED);
link-unlock all cells and link-lock individual cell had helped me.

Related

UITableView trigger when cell is reused

I'm having some issues with reusable cells in a UITableView. I have several types of cells, that I declare in the constructor.
My issue is that I have one particular type of cell that contains a UITextView and I have an issue when I scroll the table, the text within is lost. I need to save this text to the models that accompany the cells and then put the text back when the cell is used again.
How do I know that the cell is being moved away from? I have other types of cells, so I need a way to invoke some code to do the saving part on the scroll of the UITableView.
I hope that makes sense, if more is required, let me know.
Thanks.
Just save the text once it is changed to the model, check if any text is present and use that in tableView(_:cellForRowAt:)
For more help you will have to show us your code.
You can inherit UITextViewDelegate and in the textViewDidEndEditing(_:) check if the text view is edited, then you will be able to store the text in a variable or somewhere else and restore it whenever you are about to show that cell again.
If there is more than one text view, you might want to set an accessibility identifier for each kind, so you will find out which one did end editing.

Test dequeueReusableCellWithIdentifier:forIndexPath

I read a lot about reusing table cells in different questions here.
I implemented a subclass of UITableview (in Swift)
Registered this class in ViewDidLoad() of my ViewController (I'm not using storyboard)
and use dequeueReusableCellWithIdentifier:forIndexpath in tableView's
cellForRowAtIndexPath
As far as i know this should reuse the cells.
However is there a way to test if the cells are actually reused?
For example in Instruments or by printing in the debugger.
Thank you for your help!
There is a number of ways to do it.
First of all, you can just write something to log in the initWithStyle:reuseIdentifier:. You'll see as much log entries as there are cells on the screen at the same time.
Second: you can mark your cells somehow in cellForRowAtIndexPath. For instance, cells have tags which are set to 0 by default. So when you get a cell from dequeueReusableCell..., if it has a tag, which is equal to 0, you set it to something else. Otherwise, you've just received a reused cell. You can also set the tag of the first cell to 1, then 2 for the second cell, etc. This way you'll also find out the number of cells that you use. You just need to keep track of the largest tag so far.
You can also add some custom property and use it the same way as the tag.
Another option is to print cells in the debugger. as #RichTolley suggested in a comment above. But to my mind it is not very convenient (manually comparing pointers to every cell).
The eayest way is to set a tag in cell for cell.tag = indexPath.row+1 (add one prevent from set default 0 value) and set breakpoint condition as on the picture. If tag will be different than 0 breakpoint stops and print tag on console. How to set condition breakepoint

Use last value from a specific Cell

I've looked everywhere for a solution with no joy and with no experience with Spreadsheet functions to figure this out myself, I've turned to asking it here.
Basically i need to display the previous value of a cell in another: I.E.
If cell B3 changes from 50 to 60, i need cell G3 to show 50.
I've tried:
=INDEX(B3:B; COUNT(B3:B))
with no joy.
we cant save data permanent when you delete your data in your sheet it wont save another place or it won't display anywhere

How can I make the uicollectionview not dequeue the cells?

I don't want cells to have to be generated when they come on screen for the first time. I also don't want cells that have gone off screen to have to be regenerated when they come back on the screen.
How can I have all the cells generated on loading the UICollectionView and stay that way as I scroll up and down?
You could manage your own list of cells (pre-create them based on the datasource, create any new ones as the datasource updates, and return the appropriate cell for the indexPath desired instead of dequeuing a cell inside cellForItemAtIndexPath) but as a general rule, that's a bad idea. You may have some specific case where cell configuration performance is poor, but the answer is usually "improve cell configuration" and rarely "keep everything in memory".
Speculating: If you're thinking of doing this in order to preserve state or cache some information in the cell, that's the wrong place to put it. The cell is presentation; keep that info in the datasource element so that whatever needs to be represented can be applied to whatever cell is being used right now.

Is there a option to add a new row in shinobi grids?

First of all i am using shinobicontrols for developing interactive UI controls (Grids) for iOS using Objective c and please don't suggest me some other controls as an answer because i need to use only this.
I am half way stuck while using this control. i have downloaded demo code for grids provided by shinobicontrols (trial for 30 days). from : http://www.shinobicontrols.com/shinobigrids/product-tour/get-started-quickly-and-easily/
I was able to reorder rows and columns, edit contents of cell, re size column width by pinch gesture and much more.
But i couldn't add a new row or column to the existing grid. Just wanted to know whether this can be achieved.
Thanks in advance.
Edit the datasource (add/remove) item and just do [grid reload];
I think this should do.
The above answer seems to be correct. Adding my views Shinobi grids can be considered as UITableView cells, If you simply change the data source array of the tableview and call [tableview reloadData], number of cells displaying on the view will also change. There is no option to add a row still.
Look at this one. It is in alfa stage, but it will be quite a powerful in month or two, I would say. Any suggestions are welcome and it's free, of course. Number of rows and row content is fully controlled from delegate, so it is dynamic.

Resources