PHPExcel

Dear Export,

How can I change pattern color by using PHPExel?
http://phpexcel.codeplex.com/
arkam chouAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian TaoSenior Business Solutions ConsultantCommented:
I guess you're looking for something like this:
  $grayBkgStyle = array(
    'fill' => array(
      'type' => PHPExcel_Style_Fill::FILL_SOLID,
      'color' => array('rgb' => 'EEEEEE')
    )
  );

  $objPHPExcel->getActiveSheet()
              ->getStyle("A1:B2")
              ->applyFromArray($grayBkgStyle);

Open in new window

arkam chouAuthor Commented:
Dear Brian Tao,

I want put pattern color like excel in attachment. for background may be not now.

Regards,
Rada
pattern.xlsx
Brian TaoSenior Business Solutions ConsultantCommented:
Well, just pick a pattern then ^^
$typeArray = array(
  PHPExcel_Style_Fill::FILL_NONE,
  PHPExcel_Style_Fill::FILL_SOLID,
  PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
  PHPExcel_Style_Fill::FILL_GRADIENT_PATH,
  PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN,
  PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY,
  PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID,
  PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL,
  PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS,
  PHPExcel_Style_Fill::FILL_PATTERN_DARKUP,
  PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL,
  PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625,
  PHPExcel_Style_Fill::FILL_PATTERN_GRAY125,
  PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN,
  PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY,
  PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID,
  PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL,
  PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS,
  PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP,
  PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL,
  PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY
);
$startRow = 6;
for ($rowIdx = $startRow, $endRow = $rowIdx + count($typeArray); $rowIdx < $endRow; $rowIdx++){
  $objPHPExcel->getActiveSheet()->setCellValue("A$rowIdx", $typeArray[$rowIdx - $startRow]);
  $rowBkgStyle = array(
    'fill' => array(
      'type' => $typeArray[$rowIdx - $startRow],
      'startcolor' => array('rgb' => 'FF0000'), // for the pattern color
      'endcolor' => array('rgb' => 'FFFFFF')  // for the pattern background color
    )
  );
  $objPHPExcel->getActiveSheet()
              ->getStyle("D$rowIdx:M$rowIdx")
              ->applyFromArray($rowBkgStyle);
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

arkam chouAuthor Commented:
Dear Brian Tao,

Do you know how format number like accounting format in excel like this?

Thanks,
Rada
Accounting.xlsx
Brian TaoSenior Business Solutions ConsultantCommented:
Unfortunately, as I know there's no built-in constant for Accounting/Currency format in PHPExcel.
arkam chouAuthor Commented:
ok, thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.