For example, how does php export excel so that 0 in front of the table number value is not removed, for example, how does php export excel so that 0 in front of the table number value is not removed
Reply content:
For example, how to export an excel file in php so that the 0 value in front of the table number is not removed
I don't know PHP. I can use Excel. I just need to add "'" before 0 (in the digit State. That is to say: in a simple way, adding "'" To convert numbers in Excel to text, OK ?!
1. Set the format
CellStyle csnumber = wb.createCellStyle();csnumber.setDataFormat(df.getFormat("#,##0.00"));
2. Use a string
cellValue = rs.getObject(xxxxx).toString();
3. Set
C. setCellStyle (csnumber); // format: c. setCellValue (cellValue );
I have never tried exporting Excel using PHP. Maybe you can try to convert the numeric value with a front 0 to a string and hand it to excel.
Excel always removes the front 0 of the number, but if the first character is a string of 0, there will be no such problem.
PHPExcel is used for value assignment.CellDataType: TYPE_STRING Parameter
$objActSheet->setCellValueExplicit($key, $value, PHPExcel_Cell_DataType::TYPE_STRING);
Convert it into a string.
Connect the null block to the variable. ''. $ Number;
"First, let's take a look at how excel exports from a Web page. When we send the data to the client, we want the Client Program (browser) to read it in excel format, so we set the mime type to application/vnd. ms-excel: When an excel file is read, data is displayed in the format of each cell. If the cell does not have a specified format, excel displays the data of the cell in the default format. This provides us with a space for custom data formats. Of course, we must use the formats supported by excel. Common formats are listed below:
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.00%
You can also customize these formats. For example, you can define the year and month as yy-mm. So how can I add these formats to cells when I know these formats? It is very simple. We only need to add the style to the corresponding tag pair (that is, to close the tag. For example
, To the tag pairAdd a style as follows:
410522198402161833