Skip to content
Advertisement

Add a placeholder text using PhpSpreadsheet

Is there a way to add a placeholder text to a cell using PhpSpreadsheet?

I want a piece of text to be placeholder, so clients can instantly type in that cell instead of first needing to remove the text in that cell.

Advertisement

Answer

There is no built-in way in Excel to have a “placeholder” text that is visible in the cell when it is empty (see this Super User answer).

However, you can add a prompt message that will look like this in Excel:

A prompt message showing in Excel

Here’s how you do it:

$validation = $spreadsheet->getActiveSheet()->getCell('B3')
    ->getDataValidation();
$validation->setShowInputMessage(true);
$validation->setPromptTitle('Prompt title');
$validation->setPrompt('Prompt message');
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement