简体   繁体   中英

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.

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:

Excel 中显示的提示信息

Here's how you do it:

$validation = $spreadsheet->getActiveSheet()->getCell('B3')
    ->getDataValidation();
$validation->setShowInputMessage(true);
$validation->setPromptTitle('Prompt title');
$validation->setPrompt('Prompt message');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM