Set direction sheet in PHPExcel - php

I trying to export my database data to excel file, so I use PHPExcel classes.
my sheet should be Right to left, How can I switch sheet direction to 'RTL' in PHPExcel ?

Quoting directly from the developer documentation, which can be found in the /Documentation folder of the distribution:
4.6.48. Right-to-left worksheet
Worksheets can be set individually whether column ‘A’ should start at left or right side. Default is left. Here is how to set columns from right-to-left.
// right-to-left worksheet
$objPHPExcel->getActiveSheet()
->setRightToLeft(true);

Related

How do I rename Sheet in Excel using TinyButStrong Excel?

I have a TBS Excel template with numerous sheets. I want to rename each sheet to match a variable that is going to be put into cell A2. I know Excel will not allow special characters in table names, so I can not use a square brackets to set a TBS variable.
Is there a way to change the sheet names programatically either using TinyButStrong Excel or PHP (note: PHP Excel is not an option in this environment)?
Thank you
For now (OpenTBS version 1.9.11) there is no special feature for renaming a sheet in an XLSX workbook.
Nevertheless, you can open the sub-file 'xl/workbook.xml' and replace the the old sheet name by the new one knowing that the sheet name is stored in a name attribute.
XSLX example:
<sheet name="My old sheet" sheetId="1" r:id="rId1"/>
PHP code:
$TBS->PlugIn(OPENTBS_SELECT_FILE, 'xl/workbook.xml');
$TBS->Source = str_replace('name="My old sheet"', 'name="My new sheet"', $TBS->Source);

PHP Excel - Set cell or Column Direction (RTL)

I'm looking for a way to set the "Direction" of a cell in Excel from PHP Excel.
I've gone over any documentation i could find and found only the option to set the direction for a sheet, however, it does not affect the cell direction but rather, only the layout of the page from LTR to RTL.
I need to be able to set a specific Cell or better yet, a column, to be RTL.
Please note that I'm not talking about the alignment of the cell, I'm talking about the text direction.
this is not a duplication of Set direction sheet in PHPExcel
thanks
This can only be set at the Worksheet level using
// right-to-left worksheet
$objPHPExcel->getActiveSheet()
->setRightToLeft(true);
not for individual cells, ranges of cells, columns or rows
Got the answer to this by a dear friend (Bastien Koert) :
This takes care of the RTL for a single Cell.
$objPHPExcel->getActiveSheet()->getStyle('J' , $i)->getAlignment()->setReadorder(PHPExcel_Style_Alignment::READORDER_RTL);
This takes care of the right alignment needed with Hebrew
$objPHPExcel->getActiveSheet()->getStyle('J' , $i)->getAlignment()- >setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

Can PHPExcel add a sheet chart (as opposed to embedded chart)?

At the moment of this writing the current version of PHPExcel is version 1.8.0. I know how to make a chart and embed it in a worksheet, I basically followed the provided example.
Excel allows to either embed a chart into a worksheet or otherwise make a chart sheet. A chart sheet has it's own 'tab' in Excel and Excel keeps the chart scaled to the available size in the window.
Now what I would like to know is: how to add a chart sheet with PHPExcel? Is this possible with PHPExcel 1.8.0 using the 'Excel2007' writer?
As stated by #MarkBaker in the comments, the answer is simply "No" (at least not in version 1.8.1).
In my use case I was using PHP to generate an Excel workbook based on some processed data from different sources. What I did is to add VBA in Sub Workbook_Open() on the generated workbook to move the chart from a worksheet to it's own chart sheet. Then I used PHPExcel->getMacrosCode() to export the binary string of macro code to some file.
Now when generating files I add that binary string with PHPExcel->getMacrosCode(String) and save it as .xlsm instead of .xlsx. It is a bit of a hassle, but this is how I work around this problem for me.
Note that depending on your use case you might also need to generate a certificate to sign the code, to allow your user to always trust macros.

PHP style excel sheets

I am trying to export excel file from the mysql as per the answer in
Exporting data to excel sheet in php. The export is successful. But I would like to know about the styles. Can I make one line bold, italic etc in the excel file? And can I insert a table using this excel export?
Thanks!
https://www.google.com/search?q=php+excel+styling
yeilds:
PHPExcel: Coloring the cells?
PHPExcel specific cell formatting from style object
PHPExcel style problem
PHP Excel style formatting using col & row index
Style a range of cells with phpexcel
PHPexcel cannot reads styles from xls
SO is endless with information, and that's just the first page of results

How to formatting Excel Sheet cells using PHP

Please help me about my doubts on excel and php. I need to do the following process on excel report generation using php
to change cell's font styles
to change cell's BG color
to change cell's width
Try PHPExcel. I started using it few days ago and it works very good.
With PHPExcel
http://phpexcel.codeplex.com/wikipage?title=Features
http://phpexcel.codeplex.com/wikipage?title=Examples
With PEAR Spreadsheet Excel Writer
Format::setBgColor – Sets the cell's background color
Format::setFontFamily – Sets the font family.
Worksheet::setColumn – Set the width of a single column or a range of columns.
I'd definitely recommend PHPExcel as well, and it may well supercede the SEW within the PEAR repository

Categories