Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9099203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:33:16+00:00 2026-06-17T00:33:16+00:00

I have the following sample line in a CSV file I am generating with

  • 0

I have the following sample line in a CSV file I am generating with PHP. When I cat the file this is what I see:

541787,271561,"04/01/2013 09:26:35",18801872,Many,"PINSTRIPE JACKET",18806821872,75.00,GBP,1,0078,5051916991872

However, when I open this file in MS Excel the “0078” has been changed to “78” – so MS Excel has taken it upon itself to strip the leading zeros. It has also converted the EAN13 number (in Column L) to an exponent.

Stripped Zeros

In terms of the PHP code I am outputting the file to the browser with the following code, which works in principal, but I would like to know if there is a way to control the stripping of the leading zeros with PHP?

// set the headers
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename=_report_' . date('Y-m-d-His') . '.csv');
header('Pragma: no-cache');

echo $report->getCSVOutput();
exit;    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:33:17+00:00Added an answer on June 17, 2026 at 12:33 am

    It turns out that with a small tweak (as suggested by the owner) to SimpleExcel this package can handle the stripping of leading zeros.

    I am using the code below:

    /**
     * get the order data in Microsoft Excel XML format (to be used when output to the browser directly)
     * @return void
     */
    public function getExcelXMLOutput() {
    
        // instantiate new object (will automatically construct the parser & writer type as XML)
        $excel = new SimpleExcel('xml');                    
    
        // add some data to the writer
        $excel->writer->setData($this->orders);                                                 
    
        // save the file with specified name
        // and specified target (default to browser)           
        $excel->writer->saveFile('report_' . date('Y-m-d-His'));
    
    }
    

    The code amendment required me to change the XMLWriter class in the addRow method to:

    $datatype = is_string($val) ? 'String' : (is_numeric($val) ? 'Number' : 'String');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sample set of data: <p>first line\n second line\n third line\n</p>
I have a simple text file containing some CSV with the following structure: @Parent1_Field1,
I have a CSV-file similar to this test.csv file: Header 1; Header 2; Header
I have the following code sample to illustrate my point. When I load this
I have a simple <input type=text/> styled with the following: font-size:1.5em;line-height:1.5em;padding:.6em .4em; It displays
I have the following sample code and noticed that if I attempt to use
I have the following sample code which doesn't seem to want to run. import
I have the following sample data: Id Name Quantity 1 Red 1 2 Red
I have the following sample of data to insert into tables(from parent to child,
I have the following sample dataset (below and/or as CSVs here: http://goo.gl/wK57T ) which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.