Laravel-excel: [PERTANYAAN] Bagaimana cara menambahkan perlindungan ke berbagai sel

Dibuat pada 6 Sep 2017  ·  3Komentar  ·  Sumber: Maatwebsite/Laravel-Excel

Versi paket, versi Laravel

Versi terbaru, Laravel 5.4

Saya tidak tahu apakah itu bug, saya tidak melakukannya dengan benar, atau ada sesuatu yang belum saya lakukan.

Saya dapat menggunakan metode dasar dan lanjutan yang ditemukan di situs web maat untuk dokumentasi excel.

Metode yang saya gunakan adalah
$sheet->protect() , dan ini adalah metode lanjutan.

Metode ini dapat melindungi seluruh lembar, tetapi saya hanya perlu melindungi sejumlah sel.

Saya melihat metode lembar kerja:
$sheet->protectCells(A1); tapi ini tidak bekerja untuk saya. Tolong bantu dengan metode yang bisa saya gunakan untuk mencapai ini. Terima kasih..

Komentar yang paling membantu

Akhirnya saya menemukan cara yang tepat untuk melakukannya..

$objPHPExcel = PHPExcel baru;
$objSheet = $objPHPExcel->getActiveSheet();

//LINDUNGI JANGKAUAN SEL
$objSheet->protectCells('A1:B1', 'PHP');

// LINDUNGI JANGKAUAN SEL
$objSheet->getStyle('A2:B2')->getProtection()
->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);

// MELINDUNGI LEMBAR KERJA
$objSheet->getProtection()->setSheet(true);

Ini bekerja dengan sempurna!
SUMBER: https://stackoverflow.com/questions/17046207/phpexcel-lock-particular-cell

Di Laravel saya menggunakan:

// LINDUNGI dengan kata sandi Anda
$sheet->protect('kata sandi');

// UNPROTECT rentang sel
$sheet->getStyle('F2:F1000')->getProtection()->setLocked(\PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);

// MELINDUNGI lembar kerja
$sheet->getProtection()->setSheet(true);

Semua 3 komentar

Hai @GreenWhiteDev

Saya memeriksa ketergantungan yang mendasarinya dengan pencarian di:
https://github.com/PHPOffice/PHPExcel/search?utf8=%E2%9C%93&q=protectCells&type=

Anda akan melihat hasilnya:
https://github.com/PHPOffice/PHPExcel/blob/1c8c2379ccf5ab9dd7cb46be965821d22173bcf4/Examples/05featuredemo.inc.php#L136 -L139

Itu mungkin cukup untuk membuat Anda pergi, saya kira.
Sesuatu seperti ini:

$sheet->getActiveSheet()->getProtection()->setSheet(true);  // Needs to be set to true in order to enable any worksheet protection!
$sheet->getActiveSheet()->protectCells('A3:E13', 'PHPExcel');

Sunting: menambahkan referensi ini:
JUGA lihat

https://github.com/PHPOffice/PHPExcel/blob/1c8c2379ccf5ab9dd7cb46be965821d22173bcf4/Classes/PHPExcel/Worksheet.php#L1793 -L1814

    /**
     * Set protection on a cell range
     *
     * <strong i="22">@param</strong>    string            $pRange                Cell (e.g. A1) or cell range (e.g. A1:E1)
     * <strong i="23">@param</strong>    string            $pPassword            Password to unlock the protection
     * <strong i="24">@param</strong>    boolean        $pAlreadyHashed    If the password has already been hashed, set this to true
     * <strong i="25">@throws</strong>    PHPExcel_Exception
     * <strong i="26">@return</strong> PHPExcel_Worksheet
     */
    public function protectCells($pRange = 'A1', $pPassword = '', $pAlreadyHashed = false)

Tiga parameter untuk dimainkan pada metode itu!

Beri tahu saya bagaimana Anda melanjutkan?

Akhirnya saya menemukan cara yang tepat untuk melakukannya..

$objPHPExcel = PHPExcel baru;
$objSheet = $objPHPExcel->getActiveSheet();

//LINDUNGI JANGKAUAN SEL
$objSheet->protectCells('A1:B1', 'PHP');

// LINDUNGI JANGKAUAN SEL
$objSheet->getStyle('A2:B2')->getProtection()
->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);

// MELINDUNGI LEMBAR KERJA
$objSheet->getProtection()->setSheet(true);

Ini bekerja dengan sempurna!
SUMBER: https://stackoverflow.com/questions/17046207/phpexcel-lock-particular-cell

Di Laravel saya menggunakan:

// LINDUNGI dengan kata sandi Anda
$sheet->protect('kata sandi');

// UNPROTECT rentang sel
$sheet->getStyle('F2:F1000')->getProtection()->setLocked(\PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);

// MELINDUNGI lembar kerja
$sheet->getProtection()->setSheet(true);

@jorgeald77 Wow! Itu bekerja sangat keren..

Saya menghentikan proyek untuk sementara waktu. Saya baru mulai beberapa hari yang lalu.

Saya tidak dapat menerapkan keamanan untuk rentang sel saat itu. Saya mencoba solusi Anda dan itu bekerja dengan sangat baik. Saya sangat menghargai ini.

Terima kasih semua atas kontribusinya..

Apakah halaman ini membantu?
0 / 5 - 0 peringkat

Masalah terkait

muhghazaliakbar picture muhghazaliakbar  ·  3Komentar

alejandri picture alejandri  ·  3Komentar

vandolphreyes picture vandolphreyes  ·  3Komentar

amine8ghandi8amine picture amine8ghandi8amine  ·  3Komentar

ellej16 picture ellej16  ·  3Komentar