I need to show excel type data for each of my website, means I want to show the sale on each date and if there is no sale on a particular day that date should be empty.
Currently my data is showing like this
This is what I want when I import it to excel
I am using this code for this
<?php
$k = 0;
foreach ($report as $loop) {
$month = $loop['month'] . ' ' . $loop['myyear'];
$onlymonth = $loop['month'];
if (isset($from)) {
$empu = $empWorked->GetAllRevenueWithUserIdForReports2($user, $from, $to);
}
$objPHPExcel->setActiveSheetIndex($k);
$counter = 2;
$cc = 1;
if (in_array($onlymonth, $monthName)) {
for ($col = 'A'; $col != 'AK'; $col++) {
$objPHPExcel->getActiveSheet($k)->getColumnDimension($col)->setAutoSize(true);
}
$objPHPExcel->getProperties()->setCreator("mycompany");
$objPHPExcel->getProperties()->setLastModifiedBy("mycompany");
$objPHPExcel->getProperties()->setTitle("Revenue History");
$objPHPExcel->getProperties()->setSubject("PHPExcel Document");
$objPHPExcel->getProperties()->setDescription("Test document for PHPExcel, generated using PHP classes.");
$objPHPExcel->getProperties()->setKeywords("office PHPExcel php");
$objPHPExcel->getProperties()->setCategory("Test result file");
$objPHPExcel->setActiveSheetIndex($k)->mergeCells('A1:C1');
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Stores Revenue');
$objPHPExcel->getActiveSheet()->getStyle("A1")->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle("A1")->getFont()->setSize(12);
$objPHPExcel->getActiveSheet()->getStyle('A2:C2')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('A2:C2')->getFill()->getStartColor()->setARGB('DBDBDB');
// Add some data
$objPHPExcel->getActiveSheet()->getStyle("A2:AJ2")->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle("A2:AJ2")->getFont()->setSize(10);
$objPHPExcel->getActiveSheet()->getStyle('A2:C2')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A1:C1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('A2:AJ2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->setActiveSheetIndex($k)->setCellValue('A2', 'Store');
$objPHPExcel->setActiveSheetIndex($k)->setCellValue('B2', ('Website'));
$objPHPExcel->setActiveSheetIndex($k)->setCellValue('C2', ('Currency'));
$showmonth = date("M", strtotime($onlymonth));
$showi = 1;
for ($col = 'D'; $col != 'AI'; $col++) {
if ($showi < 10) {
$objPHPExcel->setActiveSheetIndex($k)->setCellValue($col . '2', '0' . $showi . ' ' . $showmonth);
} else {
$objPHPExcel->setActiveSheetIndex($k)->setCellValue($col . '2', $showi . ' ' . $showmonth);
}
$showi++;
}
$objPHPExcel->setActiveSheetIndex($k)->setCellValue('AI2', 'Total');
$objPHPExcel->setActiveSheetIndex($k)->setCellValue('AJ2', 'Contribution');
$objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(100);
$i = 3;
$ii = 1;
foreach ($empu as $item) {
$itemmonth = $item['month'];
$itemdate_cost = $item['date_cost'];
$itemnetwork_id = $item['store_id'];
$itemsite_id = $item['site_id'];
$itemuser_id = $item['user_id'];
$empu2 = $empWorked->GetAllRevenueWithUserIdForReportss($user, $from, $to, $itemnetwork_id, $itemsite_id);
if ($onlymonth == $item['month']) {
$string = $item['date_cost'];
$shownetworkname = $item['store_id'];
$shownetworkcurrency = $ntname['currency'];
$showwebsitename = $stname['site_id'];
$objPHPExcel->setActiveSheetIndex($k)->setCellValue('A' . $i, $shownetworkname);
$objPHPExcel->setActiveSheetIndex($k)->setCellValue('B' . $i, $showwebsitename);
$objPHPExcel->setActiveSheetIndex($k)->setCellValue('C' . $i, $shownetworkcurrency);
// echo $partss[0].'<br>';
$condition = 1;
foreach ($empu2 as $item2) {
if ($itemnetwork_id == $item2['store_id'] && $itemsite_id = $item2['site_id'] && $itemuser_id = $item2['user_id']) {
for ($cols = 'D'; $cols != 'AI'; $cols++) {
$matchvalues = $partdates . ' ' . $showmonth;
$ytd_actual = $objPHPExcel->getSheet($k)->getCell($cols . $ii)->getValue();
$objPHPExcel->setActiveSheetIndex($k)->setCellValue($cols . $i, '$' . $item2['cost_amount']);
$objPHPExcel->getActiveSheet()->getStyle($cols . $i)->getFont()->setSize(10);
}
}
$condition++;
}
$ii++;
$i++;
}
}
}
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle($month);
$objPHPExcel->createSheet();
$cc++;
$k++;
}
Appreciate your's help.