Excel validate a phone number

321 views Asked by At

I use phpspreadsheet to write a xlsx file for use to type in. And use validation to validation the datetime.

// set the default style
$default_style = array(
    "alignment"=>array(
        "horizontal"=>\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT,
        "wrapText"=>true
    ),
    "numberFormat"=>array(
        "formatCode"=>'s'
    )
);
$spreadsheet->getDefaultStyle()->applyFromArray($default_style);
$phone_number_validation = new DataValidation();
$phone_number_validation->setShowErrorMessage(true);
$phone_number_validation->setErrorTitle("number not matched");
$phone_number_validation->setError("please enter the number with 11 digital number chars");
$phone_number_validation->setAllowBlank(false);
$phone_number_validation->setType("decimal");
$phone_number_validation->setOperator("between");
$phone_number_validation->setFormula1("10000000000");
$phone_number_validation->setFormula2("99999999999");

This can validate the phone number with 11 digital number chars, but the excel shows ########.

How can it show the original original phone number directly.

0

There are 0 answers