我在这里有两个不同的问题。
格式化适用于 filename.xls 格式,但不适用于 filename.xlsx (Microsoft office 2007) 文件格式
我试图切换到 filename.xls 版本,但在这个版本中,我们的公式像 ' =SUMIFS(tams_database!Q : Q, tams_database!I : I,F$1, tams_database!U : U, E1, tams_database!X : X, D1 ) ' 正在抛出一些警告,例如
PHP 警告:ExcelSheet::write():无法在第 493 行的 /var/www/portal/www/tcc_v2/app/controllers/DebriefController.php 中写入第 66 行第 13 列的单元格,并出现错误“公式中的标记不正确”
注意:我已经处理了 ExcelBook('','', true/false) wrt xlsx & xls 文件
如果我的代码有问题,请告诉我。谢谢
<?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;
}