How can I set PHPExcel to write a file and use gridlines? - php

I'm trying to set up the print options for an excel file in PHPExcel. I'm working from the packaged API documents (version 1.7.7) but can't find any methods to do this. Am I missing a setting somewhere?
This setting is found in MS Excel under Print > Page Setup > Sheet.

$objPHPExcel->getActiveSheet()->setPrintGridlines(TRUE);
EDIT
setPrintGridlines() identifies whether gridlines around cells should be displayed when printing a worksheet from MS Excel; the default is FALSE. setShowGridlines() identifies whether gridlines around cells should be displayed when the spreadsheet is shown in the MS EXcel GUI; the default is TRUE;

I've found the one I was looking for. It was under the Worksheet class and not the page setup class as I'd previously thought.
For anyone looking in future, this is the method you need:
PHPExcel_Worksheet setPrintGridlines( [boolean $pValue = false])
There are two functions very similar though: setPrintGridlines and setShowGridlines. I'm not quite sure of the difference. Can anyone enlighten me?

Related

Laravel excel Import when header have merged cells

It seams that http://www.maatwebsite.nl/laravel-excel/docs can't figure out how to handle simple merged cells.
Importing excel file like this:
Excel::load($tmp_path, function($reader) {
$reader->dd();
})->get();
See image bellow where is problem:
You'll have to read this file out differently, you can't use the simple import methods. You have to read it out per coordinate, example of the native PHPExcel methods:
http://docs.typo3.org/typo3cms/extensions/phpexcel_library/1.7.4/manual.html#_Toc237519900
Also you can check the link: https://github.com/Maatwebsite/Laravel-Excel/issues/442
Hope this helps.
Just checked configuration and we can set 'slugged_with_count' in heading, so results become like picture bellow. Or disable heading and rely on columns order.

Generate OpenOffice calc files using PHP

I have been trying to find a simple way to create OpenOffice calc files with no success.
I have tried:
openTBS - Seems to work writing an xml and a template file but can't find anything about how the xml file format.
Ods php generator - I tried this one as it provides clear examples, but when I copy the files to my server I always get corrupted files
Php doc writer - Tried an example and got an sxw file. I don't even know what that is
ODS-PHP - No documentation, only one example for creating 4 cells
Everything looks old, stalled and undocumented. ¿Any suggestion?
I have used opentbs successfully.
You can generate both excel and calc files. It also nice that you can "reuse" your html implementation so to speak.
Maybe this thread could get you going http://www.tinybutstrong.com/forum.php?thr=3069
Do the html version first.. then edit for calc/excel
Spout from Box works well enough for me. There are some missing features but it is simple to use, has a fluent API, and has no dependencies (it supports composer but you can use it standalone and its dependency graph has zero depth 😉 ).
Here's my "array of objects to ODS" pipeline, using Spout:
(I'm not using their recommended use import because all this code fits in a much larger file that I didn't want to contaminate and the $factory pattern looks cleaner to me anyway)
$factory = 'Box\Spout\Writer\Common\Creator\WriterEntityFactory';
$factory::createODSWriter()
->openToBrowser('filename.ods')
->addRow($factory::createRow([
$factory::createCell(__('Heading 1')),
$factory::createCell(__('Heading 2')),
$factory::createCell(__('Heading 3')),
]))
->addRows(array_map(function($row) use ($factory) {
return $factory::createRow([
$factory::createCell($row->first_val),
$factory::createCell($row->second_val),
$factory::createCell($row->third_val),
]);
}, loadDataFromSomewhere()))
->close();

File size issue with PEAR Spreadsheet Excel Writer?

I have this code:
$book = new Spreadsheet_Excel_Writer();
$book->send('book.xls');
$report =& $book->addWorksheet('sheet');
$i = 0;
while ($i<145){
$report->write($i, 0, 'dsbajk_'.$i);
$i++;
}
$book->close();
This produces a file of 6 KB but when I tried to open it in Excel there is an error with the file, something like: Excel found content that couldn't read and is possible that some data was lost. (I can't write the exact message because is in Spanish).
If I change 145 to 144 (or less) in the loop no messages is displayed, so I think is a problem with the buffer or size of the text. I need to replace the while loop with a db query with more data so is important this works well.
I tried this in other server and I didn't have this problem, so maybe is something with the config.
I apreciate any help.
As Marc B said switch to PHPExcel is a good decision if you're starting a new project. It supports xlsx and other modern formats as well as the traditional xls. It also has more options and is easy to install and use.
I used PHPExcel in my project and I'm pretty happy. :)

Insert image in xls sheet throgh php code

Greetings !!
I have to insert a logo(image) on the row[0],column[0].I am using "Spreadsheet_Excel_Writer" for that.i tried its insertBitmap() methode ,program working fine but it doesn't show the bitmap image on xls sheet,instead blank row. what could be reason ? can you please let me know the exact string format for the argument. Is there any other way to insert image on xls sheet using PHP5.i am very new to php ,it will be a great help .
Have a nice time ahead !!
[edit]
Here is the code, as per Aman's comment below:
$sew =& new Spreadsheet_Excel_Writer ();
$worksheet =& $sew->addWorksheet (substr (strval ($name).strval ($sht), 0, 31));
$worksheet->insertBitmap ($row,$col,$image,$x,$y,$scale_x,$scale_y);
I never could get Spreadsheet_Excel_Writer to work properly with image insertions. Not sure if it's a bug in the library or what. But in any case, S_E_W is hideously outdated, you should switch to PHPExcel instead, which supports recent Excel formats (including .xlsx) for reading AND writing, whereas S_E_W is limited to BIFF 5.0, which is Excel '95 (or thereabouts) and only supports writing.
I've just ran a test using Spreadsheet_Excel_Writer. SEW saves the excel file using BIFF5 format. Open Office Calc will read images from BIFF8, but not from BIFF5 files.
EDIT
Further testing:
Setting SEW to write BIFF8 by using $workbook->setVersion(8); still doesn't write the bitmap image correctly as a BIFF8 file. It would seem that unless you want to rewrite SEW to store images correctly for BIFF8, then you won't see them when opening the file in OOCalc... without reading through the OOCalc or SEW code, I couldn't say what the problem is. Nor does Gnumeric read the image when the file is saved as BIFF5, but it will display the image correctly when the file is saved as BIFF8.
I've gotten this to work. The thing is, this writer is EXTREMELY sensitive to cell overwriting.
Your syntax is correct.
Things to look out for:
Make sure the file is 24 bit BMP. That's the only thing this writer supports.
Make sure nothing overwrites the cell where you place the image.
Make sure that the image path is correct.
And make sure the scale is set. If it's not set, it goes to 0 which doesn't display the image. The default is noted as 1, but it's not.

Image inserted in xls sheet but doesn't appears ! [duplicate]

Greetings !!
I have to insert a logo(image) on the row[0],column[0].I am using "Spreadsheet_Excel_Writer" for that.i tried its insertBitmap() methode ,program working fine but it doesn't show the bitmap image on xls sheet,instead blank row. what could be reason ? can you please let me know the exact string format for the argument. Is there any other way to insert image on xls sheet using PHP5.i am very new to php ,it will be a great help .
Have a nice time ahead !!
[edit]
Here is the code, as per Aman's comment below:
$sew =& new Spreadsheet_Excel_Writer ();
$worksheet =& $sew->addWorksheet (substr (strval ($name).strval ($sht), 0, 31));
$worksheet->insertBitmap ($row,$col,$image,$x,$y,$scale_x,$scale_y);
I never could get Spreadsheet_Excel_Writer to work properly with image insertions. Not sure if it's a bug in the library or what. But in any case, S_E_W is hideously outdated, you should switch to PHPExcel instead, which supports recent Excel formats (including .xlsx) for reading AND writing, whereas S_E_W is limited to BIFF 5.0, which is Excel '95 (or thereabouts) and only supports writing.
I've just ran a test using Spreadsheet_Excel_Writer. SEW saves the excel file using BIFF5 format. Open Office Calc will read images from BIFF8, but not from BIFF5 files.
EDIT
Further testing:
Setting SEW to write BIFF8 by using $workbook->setVersion(8); still doesn't write the bitmap image correctly as a BIFF8 file. It would seem that unless you want to rewrite SEW to store images correctly for BIFF8, then you won't see them when opening the file in OOCalc... without reading through the OOCalc or SEW code, I couldn't say what the problem is. Nor does Gnumeric read the image when the file is saved as BIFF5, but it will display the image correctly when the file is saved as BIFF8.
I've gotten this to work. The thing is, this writer is EXTREMELY sensitive to cell overwriting.
Your syntax is correct.
Things to look out for:
Make sure the file is 24 bit BMP. That's the only thing this writer supports.
Make sure nothing overwrites the cell where you place the image.
Make sure that the image path is correct.
And make sure the scale is set. If it's not set, it goes to 0 which doesn't display the image. The default is noted as 1, but it's not.

Categories