title: Excel is stripping leading 0's from CSV files
body: <p>It believe that Excel is stripping leading 0s. I was told that updating the column format to text during the export will fix this and to modify Excel output (coming from "ProofAndTracking actionIpromoteuAutomation" file, yet I can't find this file or how to access where the excel formatting code is generated). </p>
  
  <p>I've never worked with Excel. I tried this, but it seems to be a local fix:
  <a href="http://excelribbon.tips.net/T010262_Handling_Leading_Zeros_in_CSV_Files.html" rel="nofollow noreferrer">http://excelribbon.tips.net/T010262_Handling_Leading_Zeros_in_CSV_Files.html</a>
  Could someone point me in the right direction to start?</p>
  
  <p>I've researched these answers <a href="https://stackoverflow.com/questions/424412/how-to-stop-the-leading-0s-from-being-stripped-off-when-exporting-to-excel-from">How to stop the leading 0&#39;s from being stripped off when exporting to excel from a datatable?</a> and <a href="https://stackoverflow.com/questions/11574840/export-excel-avoid-stripping-the-leading-zeros">Export Excel : Avoid stripping the leading zeros</a><br>
  Thanks in advance!</p>
  
  <p>Here is the function I believe is causing the problem, but not sure yet how to format columns to text here.    /*
       * format and send order and tracking info (via Excel spreadsheet) for the day for ipromoteu (150837)
       */</p>
  
  <pre><code>public function actionIpromoteuAutomation() {
      $ordersGroup1 = $this-&gt;getIpromoteuProof();
      $ordersGroup2 = $this-&gt;getIpromoteuProofHistory();
      $orders = array_merge($ordersGroup1, $ordersGroup2);
      $fileName = 'Hit Promo Order Tracking ' . date('m-d-Y');
      $this-&gt;_export($orders, $fileName);
      $fileName = $fileName . '.xls';
      $toIPROMOTEU = array(//email to be sent to HR when request is submitted
          'body' =&gt; 'Attached, please find the Excel spreadsheet containing'
          . ' order details for orders on ' . date('m/d/Y') . '.',
          'from_email' =&gt; 'donotreply@hitpromo.net',
          'from_name' =&gt; 'Hit Promotional Products',
          'subject' =&gt; 'Order Tracking Information - ' . date('m/d/Y'),
          'to_emails' =&gt; 'orders@ipromoteu.com',
          'attachments' =&gt; array(array('path' =&gt; Yii::app()-&gt;basePath . '/../tmp/' . $fileName, 'filename' =&gt; $fileName)),
      );
      Hit::email((object) $toIPROMOTEU);
  
      $this-&gt;logForDeveloper('Order records sent to iPromoteU for '. date('m/d/Y'));
  }
  
  private function _export($data, $fileName, $format = 'excel', $output = false) {
      // get a reference to the path of PHPExcel classes
      $phpExcelPath = Yii::getPathOfAlias('ext.phpexcel');
  
      // Turn off our yii library autoload
      spl_autoload_unregister(array('YiiBase', 'autoload'));
      include($phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php');
  
      // Create new PHPExcel object
      $objPHPExcel = new PHPExcel();
  
      if ($format == 'excel') {
          // Set properties
          $objPHPExcel-&gt;getProperties()-&gt;setCreator(Yii::app()-&gt;user-&gt;name)
                  -&gt;setLastModifiedBy(Yii::app()-&gt;user-&gt;name)
                  -&gt;setTitle('Order Tracking Report');
      }
  
      $styleArray = array(
          'font' =&gt; array(
              'bold' =&gt; true,
              'underline' =&gt; true,
          )
      );
      $objPHPExcel-&gt;setActiveSheetIndex(0);
      $sheet = $objPHPExcel-&gt;getActiveSheet();
  
      for ($rowCounter = 0; $rowCounter &lt; sizeof($data); $rowCounter++) {
          $sheet-&gt;getStyle("A" . ($rowCounter + 1))-&gt;getAlignment()-&gt;setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
          $sheet-&gt;getStyle("B" . ($rowCounter + 1))-&gt;getAlignment()-&gt;setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
          $sheet-&gt;getStyle("C" . ($rowCounter + 1))-&gt;getAlignment()-&gt;setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
          $sheet-&gt;setCellValue("A" . ($rowCounter + 1), date('m/d/Y', strtotime($data[$rowCounter]['date'])));
          //$sheet-&gt;setCellValue("A".($rowCounter+1), $data[$rowCounter]['date']);
          if ($data[$rowCounter]['fedex_tracking'] != '')
              $sheet-&gt;setCellValue("B" . ($rowCounter + 1), $data[$rowCounter]['fedex_tracking']);
          else
              $sheet-&gt;setCellValue("B" . ($rowCounter + 1), $data[$rowCounter]['other_tracking']);
          $sheet-&gt;setCellValue("C" . ($rowCounter + 1), $data[$rowCounter]['sales_order_number']);
          $sheet-&gt;getStyle("B" . ($rowCounter + 1))-&gt;getNumberFormat()-&gt;setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
      }
  
      $sheet-&gt;setCellValue("A1", "DATE")
              -&gt;setCellValue("B1", "TRACKING")
              -&gt;setCellValue("C1", "PO NUMBER")
              -&gt;getStyle("A1:C1")-&gt;applyFromArray($styleArray);
  
      ////Set the column widths
      $sheet-&gt;getColumnDimension("A")-&gt;setWidth(25);
      $sheet-&gt;getColumnDimension("B")-&gt;setWidth(25);
      $sheet-&gt;getColumnDimension("C")-&gt;setWidth(25);
      // Rename sheet
      $objPHPExcel-&gt;getActiveSheet()-&gt;setTitle('Order Tracking Report');
  
      // Set active sheet index to the first sheet,
      // so Excel opens this as the first sheet
      $objPHPExcel-&gt;setActiveSheetIndex(0);
  
      $fileName = $fileName . ($format == 'excel' ? '.xls' : '.csv');
  
      $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
      $path = Yii::app()-&gt;basePath . '/../tmp/' . $fileName;
      $objWriter-&gt;save($path);
  
      // Once we have finished using the library, give back the
      // power to Yii...
      spl_autoload_register(array('YiiBase', 'autoload'));
  }
  
  public function getIpromoteuProof() {
      $date = date('Ymd');
      $db2params = Yii::app()-&gt;params['db2params'];
      $db = Zend_Db::factory('Db2', $db2params);
      $select = $db-&gt;select()
              -&gt;from(
                      // table
                      array('t' =&gt; 'WBPIPRAE'),
                      // columns
                      array(
                  'sales_order_number' =&gt; 'TRIM(WAESPO#)',
                      ),
                      // schema
                      $db2params['schemas']['hitdta'])
              -&gt;joinLeft(
                      // table
                      array('f' =&gt; 'MFD1MD'), 'CONCAT(TRIM(WAEORD#),RIGHT(TRIM(MDORDR),3))=TRIM(MDORDR)',
                      // columns
                      array(
                  'fedex_tracking' =&gt; 'TRIM(MDFTRK)',
                  'other_tracking' =&gt; 'TRIM(MDFBRC)',
                  'date' =&gt; 'TRIM(MDUPDT)',
                      ),
                      // schema
                      $db2params['schemas']['varfil'])
              -&gt;where("MDUPDT = '" . $date . "'")
              -&gt;where("WAEIVKY='150837'")
              -&gt;order('sales_order_number')
              -&gt;distinct(true);
  
      $stmt = $db-&gt;query($select);
      $orders = $stmt-&gt;fetchAll();
      return $orders;
  }
  </code></pre>