In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to set up unit formatting for php. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Php sets the method of formatting the cell: 1, setting the cell as text through "PHPExcel_Style_NumberFormat::FORMAT_TEXT"; 2, specifying the data type through setCellValueExplicit setting, and so on.
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
How does php format the unit?
Php excel format cells to text format
Solve the problem that PHPExcel long digit string is displayed as scientific count
In excel, if you enter or copy an extra-long numeric string in a default box, it will be displayed as a scientific calculation, such as an ID number, and the solution is to format the table in text or put a single quotation mark before typing.
You will encounter the same problem when using PHPExcel to generate excel, and there are three ways to solve it:
1. Set the cell to text
$objPHPExcel = new PHPExcel (); $objPHPExcel- > setActiveSheetIndex (0); $objPHPExcel- > getActiveSheet ()-> setTitle ('Simple'); / / set A3 cell to text $objPHPExcel- > getActiveSheet ()-> getStyle (' A3')-> getNumberFormat ()-> setFormatCode (PHPExcel_Style_NumberFormat::FORMAT_TEXT); / / you can also set full row or column style/*//E list text $objPHPExcel- > getActiveSheet ()-> getStyle ('E')-> getNumberFormat ()-> setFormatCode (PHPExcel_Style_NumberFormat::FORMAT_TEXT) / / third behavior text $objPHPExcel- > getActiveSheet ()-> getStyle ('3')-> getNumberFormat ()-> setFormatCode (PHPExcel_Style_NumberFormat::FORMAT_TEXT); * /
More formats can be found in PHPExcel/Style/NumberFormat.php. Note: the above setting displays the results of scientific counting for long numeric strings or text, which may be due to the scientific counting method used by php when dealing with large numbers.
2. The specified data type displayed when setting the value
$objPHPExcel = new PHPExcel (); $objPHPExcel- > setActiveSheetIndex (0); $objPHPExcel- > getActiveSheet ()-> setTitle ('Simple'); $objPHPExcel- > getActiveSheet ()-> setCellValueExplicit.
3. Add a space before the numeric string to make it a string
$objPHPExcel = new PHPExcel (); $objPHPExcel- > setActiveSheetIndex (0); $objPHPExcel- > getActiveSheet ()-> setTitle ('Simple'); $objPHPExcel- > getActiveSheet ()-> setCellValue (' D1icing,''. 123456789033)
The second and third are recommended, and the first does not fundamentally solve the problem.
This is the end of this article on "how to format units in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 265
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.