How PHP exports Excel processing so that the 0 before the table numeric value is not removed

Source: Internet
Author: User
Tags closing tag
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
  • 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.