How do I keep zeros in cells when exporting from PHP to Excel?

Microsoft Excel can use data produced by other computer applications that is saved in the text-based Comma-Separated Value file format. Excel knows how to convert the lines of comma-, space- or tab-separated information within CSV files into standard spreadsheet rows and columns. Excel may, however, make incorrect assumptions about the way data it imports should be formatted. For instance, Excel will strip leading zeros from numbers and dates because they are not mathematically significant. You can keep the leading zeros in CSV files by using Excel's Text Import Wizard.

  1. 1.

    Launch Excel Spreadsheet. Click the "Data" tab. Click the "From Text" option icon.

  2. 2.

    Click the "From Text" icon. Use the file manager to locate the CSV file you want import.

  3. 3.

    Select the CSV file with the mouse. Click the "Import" button.

  4. 4.

    Click the "Delimited" radio button in the Text Import Wizard. Deselect the "Tab," "Semicolon" and "Space" boxes. Click the "Next" button.

  5. 5.

    Check the box next to "Comma." Click "Next."

  6. 6.

    Select the column that contains the data with leading zeros. Click the "Text" radio button to select it. Do the same for each column with leading zeros that you want to retain.

    It is important to remember that when preparing data to be imported it must match exactly what is in Acctivate.  This includes any leading zeros for Product ID's or UPC's

    Acctivate QuickBooks Inventory Software enables users to import data into the system. The following details how to prepare that data in Excel for a seamless import.

    If you have ever tried to input numbers to an Excel spreadsheet you most likely discovered that Excel re-formats your number to something else, by removing leading zeros, changing a fraction to a date, or changing a long string of numbers or decimals to to scientific notation.   This can be frustrating and prevent your records from importing correctly.  In order to stop Microsoft Excel from changing the formatting of your data simply choose one of the methods below.

    The Apostrophe Method

    By placing an Apostrophe in the cell before the number you are telling Microsoft Excel to disregard the cell formatting, and display the number as it has been entered into the cell.  This method means that even if someone were to change the cell formatting back to General and tries to edit a cell it will continue to look the same  instead of being auto-formatted by Excel.

    • Add an Apostrophe in front of the number in the cell
      • (Example:  '001234 will display 001234 in Excel)
    • Enter the number as you want it to display and press Enter
    • Now the numbers should display and import correctly
    • This will allow you use MATCH and VLOOKUP functions in Excel  (Apostrophe will be ignored)

    Format Cell as Text

    The second most common method to simply format the entire worksheet or a group of cells as Text before you enter your data.  Formatting cells to display as text will make Excel display the data exactly as it has been entered. (Remember to format your cells Before you input your data)

    • Select the entire sheet or a group of cells
    • Next you can either ‘Right Click’ within the cells you have selected or select the cell format drop down from the Home tab.
    • Select Text as the format method for your cells
    • Input your data and it will display exactly as entered

    Format Cell as Custom Number

    Another option is to format a cell with a 'Custom' format setting a specific number of characters, in order for this to be an options the data length must be consistent.  For example if all of your ID's are 5 characters long and you input 1234 Excel will convert the number to a 5 character string making it 01234.  

    While exporting the data to the excel leading zeros are not displaying in export to excel.What is the solution for this.


    Add your solution here

     B   I   U   S  small BIG code var  <   >   &  link [^] encode untab case indent outdent

    Preview 0

    Existing Members

    ...or Join us

    Download, Vote, Comment, Publish.

    Your Email  

    This email is in use. Do you need your password?

    Optional Password  

    When answering a question please:

    1. Read the question carefully.
    2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
    3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
    4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
    Let's work to help developers, not make them feel stupid.


    This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    How do I import data into Excel without losing leading zeros?

    How to open import text file in excel without losing leading....
    Click the "From Text" icon. ... .
    Select the CSV file with the mouse. ... .
    Select "Tab" Delimiters. ... .
    Select the column that contains the data with leading zeros. ... .
    Click the "Finish" button..
    Click the "OK" button in the "Input Data" dialog box..

    How do I keep leading zeros when exporting CSV?

    Steps to retain initial '0' when importing a CSV:.
    Once you open the CSV file, right-click the column letter and select Format Cells..
    Then choose Custom, and set the format to '00000000. ... .
    This will add the leading '0' to all cells from which it is missing. ... .
    Now you can use the CSV file to import your record..

    How do I stop Excel from removing leading zeros in CSV?

    Set the Text qualifier as either double or single quotes. Set the Column delimiter as a comma. Click OK. Click Save -- DO NOT OPEN THE CSV FILE DIRECTLY WITH EXCEL!

    How do you keep leading zeros in concatenate?

    In Excel, fortunately, you can use the CONCATENATE function to combine cells and keep the leading zeros. Select a blank cell, and type this formula =CONCATENATE(A1, B1,C1), press Enter key, then you can drag the autofill handle to fill this formula to the range you need.