Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The way to Protect only a particular cell is not working. How do i lock a particular row or column #4032

Open
8 tasks
prakhar217 opened this issue May 17, 2024 · 1 comment

Comments

@prakhar217
Copy link

This is:

- [>] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

There should be a function which can lock a particular cell in a sheet

What is the current behavior?

//This is my code -->

  1. where I am trying to first lock the whole sheet
    2.Unlocking and only locking the needed cell
  2. But all it does lock whole sheet thats it
    $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
    $spreadsheet->getActiveSheet()->getProtection()->setSheet(true);
    $spreadsheet->getDefaultStyle()->getProtection()->setLocked(false);
    $spreadsheet->getActiveSheet()->getStyle('A1')->getProtection()->setLocked(
    \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED
    );

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
//This is my code --> 1. where I am trying to first lock the whole sheet 
2.Unlocking and only  locking the needed cell
3. But all it does lock whole sheet thats it
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
       $spreadsheet->getActiveSheet()->getProtection()->setSheet(true);
                        $spreadsheet->getDefaultStyle()->getProtection()->setLocked(false);
                        $spreadsheet->getActiveSheet()->getStyle('A1')->getProtection()->setLocked(
                        \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED
                        );
// add code that show the issue here...

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Which versions of PhpSpreadsheet and PHP are affected?

almost the lastest

@oleibman
Copy link
Collaborator

Unable to duplicate, or I don't understand the problem you're reporting. I run your code, and save the spreadsheet. When I open it in Excel, I can change the value of every cell on the sheet except for A1. When I try to change A1, I get a message that the sheet needs to be unprotected first. Is that not what you intended? Do you see something different? If so, please let me know PhpSpreadsheet version, Php version, and your environment (e.g. Windows command line). You might also want to upload the file which is not working correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants