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);
Related
I'm working with PHPExcel to export data from website. So far, everything works fine with me. Here is my result
But as you see, the text in cell is aligned bottom. This is due to I setWrapText(true) on column G to display multiline in 1 cell.
How can I set the text in other cells on top?
Any suggestion will be appreciated. Thank you.
Besides the fact that you should really be working with PhpSpreadsheet rather than with the old, unsupported PhpExcel library:
$objPHPExcel->getActiveSheet()->getStyle('A1')
->getAlignment()
->setVerical(PHPExcel_Style_Alignment::VERTICAL_TOP);
as described in the doc
I need to change the direction of a comment in a single cell or better yet, make all comments in a sheet RTL. I can do this for the cell it self but could not manage for the comment.
This can be done manually in Excel but i want to do it via PHP Excel.
Thanks
Is it possible to set the width of one cell alone without affecting other cells?
I am generating a pdf file using phpexcel.
I need to set the width of cell A1 to 40.
Tried this
$objPHPExcel->getActiveSheet()
->getColumnDimension('A')
->setWidth(40);
It does affect the entire column .
No you can't, in exactly the same way that you can't in MS Excel, Open/Libre Office Calc, or in Gnumeric.... PHPExcel tries to replicate the functionality of these spreadsheet packages, not the tables in Word.
You can, perhaps, merge cells to achieve what you want
it seems you cannot change individual cell see https://phpexcel.codeplex.com/discussions/448594
not sure if it fits your need , anyway you can remove the right border from cell so that two adiacent cells looks like one, as shown in this code
I am using dhtmlxgrid for displaying data for my reports. I have embedded two export buttons i.e. pdf and excel. But there are some number fields which are left aligned in exported file. I want to change the alignment of the number fields to the right as well as I want to set the width of the columns(if possible).
You can change column types to number based ones ( edn or ron ), it will change align of data in those columns in case of export to Excel
I had to do a lot of debugging and a little customization to get column alignment and widths to work how I wanted them do. I have this working in production, but not sure if it will fit your case. This is with dhtmlxgrid v4.1 and I'm using the Java back-end Excel writer classes.
On the front end
You should debug through dhtmlxgrid_export.js in this function:
dhtmlXGridObject.prototype._serialiseExportConfig
Make sure your alignments are correct in this array:
this.cellAlign[i]
If they aren't, you probably need to explicitly set them when you create your grid (but before you load it):
grid.setColAlign(myColAligns.join('|'));
For widths, the same applies:
grid.setInitWidths(myColWidths.join('|'));
On the back-end
In ExcelWriter.java, debug through
headerPrint(ExcelXmlParser parser)
and make sure the your alignments are coming through here:
String al = cells[j].getAlign();
The col widths are also set in this same function. I did a little customization because it didn't seem like the sizes were comparable:
sheet.setColumnView(j, (int)(widths[j]/6.53)); // I replaced "*scale/sumWidth" with /6.53, which is a strange num, but it works! ;
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);