1

I am using fputcsv for write data. It is working fine. what i need is i need to create another sheet like any name and i need to write data on that. How to do that? Please guide. I am not familiar with this. This is my code.

$filename = date("Y-m-d").".csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename=' . $filename);
header("Content-Transfer-Encoding: UTF-8");
$fp = fopen('php://output', 'a');
$yetToaproveFields = array('job_no'=>'Job Number',
                         'revisioncycle'=> 'Revision Cycle',
                         'version'=>'Version',
                         'is_approved'=>'Approved Status'
);

fputcsv($fp, $yetToaproveFields);

$notApproveArr = array();
$notApprovedValues = self::getNotApprovedJobs($_REQUEST);
foreach ($notApprovedValues as $key=>$value) {
    if ($value['is_approved'] == 1)
        $value['is_approved'] = 'No';
    fputcsv($fp, $value);
}
fclose($fp);
roberto06
  • 3,844
  • 1
  • 18
  • 29
shanthi Jagadeesh
  • 213
  • 1
  • 3
  • 10

2 Answers2

2

CSV doesn't support multiple sheets, it's a simple text file. To use sheets, you should use an Excel extension, such as PHPExcel.

roberto06
  • 3,844
  • 1
  • 18
  • 29
0

You can't.

CSV is a very simple data file format. It doesn't support spreadsheet features like styling or multiple worksheets. If you want multiple worksheets, then you need to use a spreadsheet file format like BIFF (.xls), OfficeOpenXML (.xlsx) or OASIS (.ods)

Mark Baker
  • 209,507
  • 32
  • 346
  • 385