Title, how PHP exports Excel processing so that the 0 before the table number value is not removed
Reply content:
Title, how PHP exports Excel processing so that the 0 before the table number value is not removed
I will not PHP, through Excel, as long as 0 before adding a small "'" (the number of States) on the European. In other words: In a simple way, excel in the number of text is added "'", understand?!
1. Formatting
CellStyle csnumber = wb.createCellStyle();csnumber.setDataFormat(df.getFormat("#,##0.00"));
2. Using strings
cellValue = rs.getObject(xxxxx).toString();
3. Settings
c.setCellStyle(csnumber); // 格式c.setCellValue(cellValue);
If you have not tried to export excel in PHP, you might try to convert the numeric value with the front 0 to a string to Excel
Excel always removes the number from the front 0, but if the first character is a 0 string, there is no problem.
With Phpexcel, use PhpexcelCelldatatype::type_string parameter when assigning values
$objActSheet->setCellValueExplicit($key, $value, PHPExcel_Cell_DataType::TYPE_STRING);
Turn it into a string.
It's OK to connect the empty compartment to the variable. ".;
"First, let's look at how Excel exports from Web pages." When we send this data to the client, we want to have the client program (the browser) read it in Excel format, so we set the MIME type to: application/ Vnd.ms-excel, when Excel reads a file, it renders the data in the format of each cell, and if the cell does not have a specified format, Excel renders the cell's data in the default format. This gives us the space to customize the data format, and of course we must use the format supported by Excel. Here's a list of some commonly used formats:
1) Text: vnd.ms-excel.numberformat:@
2) Date: VND.MS-EXCEL.NUMBERFORMAT:YYYY/MM/DD
3) Number: vnd.ms-excel.numberformat:#,# #0.00
4) Currency: vnd.ms-excel.numberformat:¥#,# #0.00
5) Percentage: Vnd.ms-excel.numberformat: #0.0%
These formats you can also customize, such as the year you can be defined as: yy-mm and so on. So what do you know about these formats and how do you add them to the cell? Very simply, we just need to add the style to the corresponding label pair (that is, the closing tag). Such as
, give the label toAdd a style as follows:
410522198402161833