I'm having 2 different issues here.
Formatting is working fine with filename.xls format but not working with filename.xlsx (Microsoft office 2007) file format
I tried to switch to filename.xls version but with this version our formulas like '=SUMIFS(tams_database!Q : Q, tams_database!I : I,F$1, tams_database!U : U, E1, tams_database!X : X, D1)' are throwing some some warnings like
PHP Warning: ExcelSheet::write(): Failed to write cell in row 66, column 13 with error 'incorrect token in formula' in /var/www/portal/www/tcc_v2/app/controllers/DebriefController.php on line 493
Note : I have taken care of ExcelBook('','', true/false) w.r.t xlsx & xls files
Please let me know if something wrong with my code. Thanks
<?php
$libxl = new ExcelBook("XXXX XXXX","linux-XXXXXXXXXXXXXXXXXXXXXXXX",true);
$libxl->loadFile('sample_workbook.xlsx');
$headerFont = $libxl->addFont();
$headerFont->bold(true);
$headerFont->name('Verdana');
$headerFont->size(10);
$headerFormat = $libxl->addFormat();
$headerFormat->fillPattern(ExcelFormat::FILLPATTERN_SOLID);
$headerFormat->verticalAlign(ExcelFormat::ALIGNV_CENTER);
$headerFormat->horizontalAlign(ExcelFormat::ALIGNH_CENTER);
$headerFormat->borderStyle(ExcelFormat::BORDERSTYLE_THIN);
$headerFormat->patternForegroundColor(ExcelFormat::COLOR_YELLOW);
$headerFont->color(ExcelFormat::COLOR_BLACK);
$headerFormat->setFont($headerFont);
$bodyFont = $libxl->addFont();
$bodyFont->bold(false);
$bodyFont->name('Verdana');
$bodyFont->size(10);
$bodyFormat = $libxl->addFormat();
$bodyFormat->fillPattern(ExcelFormat::FILLPATTERN_SOLID);
$bodyFormat->verticalAlign(ExcelFormat::ALIGNV_CENTER);
$bodyFormat->horizontalAlign(ExcelFormat::ALIGNH_CENTER);
$bodyFormat->patternForegroundColor(ExcelFormat::COLOR_WHITE);
$bodyFormat->borderStyle(ExcelFormat::BORDERSTYLE_THIN);
$bodyFont->color(ExcelFormat::COLOR_BLACK);
$bodyFormat->setFont($bodyFont);
/*-------------------------- Data Sheet End --------------------------*/
$sheet = $libxl->getSheetByName('sales');
$productListDetails = $debriefObj->getDebriefExportDataForProductList($sDateFrom, $sDateTo, $promotionID);
$iHeader = 5;
$iRow = 0;
if( count($productListDetails) > 0 )
{
foreach ($productListDetails as $data)
{
$sheet->write($iRow, $iHeader, $data['Name'], $headerFormat);
$iHeader++;
}
}
$sheet->write($iRow, $iHeader, 'TOTAL SALES', $headerFormat);
$iHeader++;
$sheet->write($iRow, $iHeader, 'HOW MANY CONSUMERS DID YOU APPROACH ?', $headerFormat);
$iHeader++;
$sheet->write($iRow, $iHeader, 'DAYS SCHEDULED', $headerFormat);
$iHeader++;
$sheet->write($iRow, $iHeader, 'DAYS RUN', $headerFormat);
$iHeader++;
$productDetails = $debriefObj->getDebriefExportDataForProducts($sDateFrom, $sDateTo, $promotionID);
$iRow = 1;
$lastColumnDaysRun = 0;
$productColStart = 0;
if( count($productDetails) > 0 )
{
foreach ($productDetails as $data)
{
$iHeader = 0;
$sheet->write($iRow, $iHeader, htmlspecialchars_decode($data['Region'], ENT_QUOTES), $bodyFormat);
$iHeader++;
$sheet->write($iRow, $iHeader, htmlspecialchars_decode($data['Chain'], ENT_QUOTES), $bodyFormat);
$iHeader++;
$sheet->write($iRow, $iHeader, htmlspecialchars_decode($data['Channel'], ENT_QUOTES), $bodyFormat);
$iHeader++;
$sheet->write($iRow, $iHeader, htmlspecialchars_decode($data['Outlet'], ENT_QUOTES), $bodyFormat);
$iHeader++;
$sheet->write($iRow, $iHeader, $data['SFDate'], $bodyFormat);
$iHeader++;
$totalSalesStart = $alphabates[$iHeader];
if( count($productListDetails) > 0 )
{
$productColStart = $iHeader;
foreach ($productListDetails as $product)
{
$sheet->write($iRow, $iHeader, "SUMIFS(tams_database!Q:Q; tams_database!I:I;".$alphabates[$iHeader]."$1; tams_database!U:U; E$iRow; tams_database!X:X; D$iRow)", $bodyFormat, ExcelFormat::AS_FORMULA);
$iHeader++;
}
}
$totalSalesEnd = $alphabates[$iHeader-1];
$sheet->write($iRow, $iHeader, "SUM($totalSalesStart$iRow, $totalSalesEnd$iRow)", $bodyFormat, , ExcelFormat::AS_FORMULA);
$iHeader++;
$sheet->write($iRow, $iHeader, "SUMIFS(tams_database!T:T; tams_database!U:U; E$iRow; tams_database!X:X; D$iRow)", $bodyFormat, , ExcelFormat::AS_FORMULA);
$iHeader++;
$sheet->write($iRow, $iHeader, 1, $bodyFormat);
$iHeader++;
$sheet->write($iRow, $iHeader, 1, $bodyFormat);
$iHeader++;
$iRow++;
}
$lastColumnDaysRun = $iHeader;
}