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

  • SEARCH
  • Home
  • 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 8366213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:51:36+00:00 2026-06-09T12:51:36+00:00

I am trying print some shipment details as a CSV file and I am

  • 0

I am trying print some shipment details as a CSV file and I am almost done in implementing this but it does not gives the the option for downloading.It automatically create the file and save it in the directory mentioned.

I think I am missing _prepareDownloadResponse() function but how do I implement this.

I am using this code ->

$file_path = 'sample_shipment.csv';
$mage_csv = new Varien_File_Csv();
$mage_csv->saveData($file_path, $content); 

Edit:
All this code is in my indexcontroller.php
full code in indexcontroller.php ->

class Company_Manifestupload_IndexController extends Mage_Adminhtml_Controller_Action
{        
public function indexAction() {
    echo 'Manifestupload Index!';
}
public function bluedartmanifestuploadAction() {
    $request = $this->getRequest();
    $shipmentIds = $request->getPost('shipment_ids', array());
    $file_path = 'manifest_upload_'.Mage::getSingleton('core/date')->date('d-m-Y_H-i-s').'_csv.csv';
    $mage_csv = new Varien_File_Csv();
    $shipment_csv=array();

            /*  Putting data in $shipment_csv[] */
            $mage_csv->saveData($file_path, $shipment_csv);
            }
  • 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-09T12:51:38+00:00Added an answer on June 9, 2026 at 12:51 pm

    In order to make the csv file downloadable, just put the following code inside the related controller action:

    $fileName       = 'filename.csv';
    $content        = $csvData; //prepare the csv data and return as string
    $this->_prepareDownloadResponse($fileName, $content); //this will make the csv file downloadable with the $content as contents in it.
    

    Hope this helps.

    Edit:
    Please find the updated controller action code.

    public function bluedartmanifestuploadAction() {
        $request        = $this->getRequest();
        $shipmentIds    = $request->getPost('shipment_ids', array());
        $fileName       = 'manifest_upload_'.Mage::getSingleton('core/date')->date('d-m-Y_H-i-s').'_csv.csv';
    
        //prepare csv contents
        #prepare header
        $csv = '';
        $_columns = array(
            "field1",
            "field2",
            //...
        );
        $data = array();
        foreach ($_columns as $column) {
            $data[] = '"'.$column.'"';
        }
        $csv .= implode(',', $data)."\n";
        #prepare data
        foreach($dataFromShipmentIds as $_data){ //just dummy loop
            $data = array();
            $data[] = $_data['field1'];
            $data[] = $_data['field2'];
            //...
            $csv .= implode(',', $data)."\n";
        }
        //now $csv varaible has csv data as string
    
        $this->_prepareDownloadResponse($fileName, $csv); 
    }
    

    Edit 2: The above code will only work properly in ideal case.It will not generate proper Csv when there “\n”s and “,”s in the fields .To make it work properly one can use code from varien file CSV .I’ll add it here-

    First make array of values in $data[] as above then instead of using $csv.=implode(',',$data)."\n" use the below code.

    foreach ($data as $value) {
             if (strpos($value, $delimiter) != false ||
                 strpos($value, $enclosure) != false ||
                 strpos($value, "\n") != false ||
                 strpos($value, "\r") != false ||
                 strpos($value, "\t") != false ||
                 strpos($value, ' ') != false) {
                 $str2 = $enclosure;
                 $escaped = 0;
                 $len = strlen($value);
                 for ($i=0;$i<$len;$i++) {
                     if ($value[$i] == $escape_char) {
                         $escaped = 1;
                    } else if (!$escaped && $value[$i] == $enclosure) {
                         $str2 .= $enclosure;
                     } else {
                         $escaped = 0;
                     }
                         $str2 .= $value[$i];
                 }
                 $str2 .= $enclosure;
                 $str .= $str2.$delimiter;
             } else {
                 $str .= $enclosure.$value.$enclosure.$delimiter;
             }
         }
                $str = substr($str,0,-1);
                $str .= "\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some trouble trying to print from a file. Any ideas? Thanks
Trying to print out some html forms but I get a parsing syntax error.
I was trying to print some text between <textarea> and </textarea> tags, but I've
I am trying to print out an unsigned int as a hex, but not
I'm trying to extract some textual data from a PDF file. To do this,
I'm almost positive that there is a stupid reason this is not working, but
I'm trying to print some parse trees, and Data::Dumper is very verbose for that,
I'm trying to print a JPanel with some painted graphics on it (overriding paintComponent).
When an exe file is run it prints out some stuff. I'm trying to
Im trying print Excel file data on a page. To do it i used

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.