How to export excel in php so that 0 in front of the table numeric value is not removed

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.