使用PHP + libxl中的* .xlsx文件进行单元格格式化问题

时间:2017-04-24 14:52:13

标签: php excel phpexcel libxl

我在这里有两个不同的问题。

  1. 格式化工作正常使用filename.xls格式,但没有 使用filename.xlsx(Microsoft Office 2007)文件格式

  2. 我尝试切换到filename.xls版本但是使用此版本 我们的公式如' = SUMIFS(tams_database!Q:Q,tams_database!I: 我,F $ 1,tams_database!U:U,E1,tams_database!X:X,D1)'是 抛出一些警告,如

  3. PHP警告:ExcelSheet :: write():无法在第66行第13列中写入单元格,并在/ var / www / portal / www / tcc_v2 / app / controllers /中出现错误“公式中的标记错误”第493行的DebriefController.php

    注意:我已经处理了ExcelBook('','',true / false)w.r.t 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;
      }
    

0 个答案:

没有答案