I'm using PHPExcel to generate some excel export. Excel has an autoline break feature. How can i activate this ?
My customer use only Microsoft Excel, so it don't have to support others programs.
Any ideas ?
I may use something like this : how to make New lines in a cell using phpexcel But that's more a kind of hack, than a real solution.
UPDATE :
See, once columns are merged, wrap text fail. I tryied to add wrap text upon every column merged, but it don't affect result.
UPDATE 2 :
The cells are merged, then i add wrap text, then i add text.
Set the column to a fixed width; setWrapText(true) for the cells, and see what happens.
Look at the second sheet created in /Tests/05featuredemo.php for an example.
You only need to use \n if you want to control exactly where a line wraps
Related
for development, i use PHPExcel (https://github.com/PHPOffice/PHPExcel) for creating a Excel (xlsx) document filled with data from a mysql database. So far this works good.
I want to print this Excel document too, as hardcopy to spread around for people reading it from paper. Printing wont be a problem.
The problem lies in: it's a long document, far more rows then will fit on 1 or 2 pages. The worksheet consists of blocks which i want to keep together, when printed, to be on the same page.
I can use a method to set breaks on a row. That i will be able to get to work. But after finishing putting the data on the sheet, i don't know where the automatically placed page breaks are. There is a function (getBreaks()) on the worksheet, which should provide an array with the breaks, but the returned array remains empty, so i can't find out which blocks go over a break.
Can someone help me?
Should i first save the Excel sheet, then open it again and do my job then?
Excel document is created on a shared hosting webserver. No printing options there i guess, at least not where i can manage them.
Other solution is: put a macro's in that Excel document, and let the macro run (to put the breaks on the right places) and print the Excel sheet. (not my favorite solution as i am honest).
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);
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 and modified it to create a line chart with multiple lines / data series based on a table of numbers.
Now what I would like to know is: how to add an average line / trend line over one of the lines of my line chart? Is this possible with PHPExcel 1.8.0 using the 'Excel2007' writer?
As stated by #MarkBaker in the comments, the answer to the question is "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 add the trend line. 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.
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! ;