Create Xlsx Files With Hidden Rows

Posted

in

by

Hide rows of xlsx files in PhpSpreadsheet, a useful procedure to keep out of sight the not-very-important data.

Requirements:

  • Composer
  • PHP 7.2 or newer

Step 1.

Setup dependencies.

{
    "require": {
        "phpoffice/phpspreadsheet": "^1.3"
    }
}

Step 2.

Install phpspreadsheet.

$ composer install

Step 3.

Create a new PHP file, and start coding.

getActiveSheet();

/**
 * Loop through 'Column A - D'.
 */
foreach (range('A', 'D') as $letter) {
    // Set some data to 'Column A - D' of 'Row 5'
    $sheet->setCellValue($letter . '5', 'Column ' . $letter);
}

// Hide 'Row 3'.
$spreadsheet->getActiveSheet()->getRowDimension('3')->setVisible(false);

// Write a new .xlsx file
$writer = new Xlsx($spreadsheet);

// Save the new .xlsx file
$writer->save('create-xlsx-files-with-hidden-rows.xlsx');

Test.

Run the following codes.

$ php create-xlsx-files-with-hidden-rows.php

Result.

Open the generated file create-xlsx-files-with-hidden-rows.xlsx.

Check row height.

  • 1. Select the hidden row.
  • 2. Click ‘Format’.
  • 3. Click ‘Hide & Unhide’.
  • 4. Select ‘Unhide Rows’.
  • 5. ‘Row 3’ is now visible.

References:


Posted

in

by

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest Tutorials

Web Dev Tutorials