I'm using the last PHPExcel version (7.7 i think). I'm able to generate my excel. I have to generate the pdf version with tcpdf, no choice here.
But the result is ugly and oversized.
See the gigantic font-size for 2012-000012, is 11 in excel.
As you can see, there is 2 problems here. The document is oversized, and the borders are crappy.
In order to get rid of the oversized side, i tryied this :
$this->printer->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
And this :
$this->printer->getActiveSheet()->getPageSetup()->setScale(50);
The scale is set to 50, but it do not affect output. So how can i get rid of these 2 problems ?
Here is a screen, of my excel How to set auto-line break PhpExcel? .
UPDATE :
By setting cellspacing to 0 borders are handled almost as expected, still a sligth problem, maybe caused by the oversized problem.
See :
Is there an opion or a method call to set it to 0 ?
This lies in the writer\html.php line 915, since i don't display gridlines.
To remove the borders that you find objectionable turn off grid lines on each sheet that you want to render in your the pdf.
For example:
$objPHPExcel->getActiveSheet()->->setShowGridlines(false);
to solve this problem I do two operations.
Step one is to set orientation for PHPexcel object
$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
Step two - set different paper size for PHPExcel object:
$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A2_PAPER);
Then convert PHPExcel object to object writer
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$objWriter->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A2_PAPER);
This works for me. Also i changed font size inside PHPExcel object - just like this for headers
$objPHPExcel->setActiveSheetIndex($lastsheet)->getStyle("A1:K3")->applyFromArray(
array(
'font' => array(
'size' => 8
)
)
);
and for the rest of data:
$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')->setSize(8);
Now im trying to get of ugly borders that tcPDF generates and one additional row at the end of file...
Related
I am generating Excel using PHPExcel.
All Code Works Fine.But Auto height code is not Working.
I have tried following code.
Apply row height on specific row
$objPHPExcel->getActiveSheet()->getRowDimension('7')->setRowHeight(-1);
Apply row height on for all row
$objPHPExcel->getActiveSheet()->getDefaultRowDimension(1)->setRowHeight(-1);
I have also tried word wrap property with it.
$objPHPExcel->getActiveSheet()
->getStyle('B7')
->getAlignment()
->setWrapText(true);
But it give me result as below:
Note : Working in MS office,Not Working in Apache open Office and
LibreOffice
Have just added the following to the 01simple.php example
$value = "To be or not to be-that is the question: whether 'tis nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and, by opposing, end them.";
$objPHPExcel->getActiveSheet()->setCellValue('A12', $value);
$objPHPExcel->getActiveSheet()->getRowDimension(12)->setRowHeight(-1);
$objPHPExcel->getActiveSheet()->getStyle('A12')->getAlignment()->setWrapText(true);
and this creates correctly wrapped output for both Excel2007 and Excel5 Writers
It has been asked before, years ago, but with no answer corrupt docx when adding image
Hey
I have a template where i replace some variables and generate a docx document... That works fine..
As soon as i add an image, word tells me that the files is corrupt. But letting Word correct the error gives me the document as i expect it to be with the image.
Im adding image like this...
$docx->addBreak(array('type' => 'page'));
$options = array(
'src' => $value['110333870356bc784cf1b6b0.56722572.png'],
'imageAlign' => 'center',
'scaling' => 100,
'spacingTop' => 10,
'spacingBottom' => 0,
'spacingLeft' => 0,
'spacingRight' => 20,
'textWrap' => 0,
);
$docx->addImage($options);
Im lost here .. ? ..
After being in contact with 2mdc (Creator of phpDocX) they told me, that PHP is not able to get the right extension because of the filename of the image i am inserting. As a result phpDocX adds some wrong values (such as dpi and image extension name).
As mentioned in my question, Word is able to detect those errors and correct them.
Changed my routine which creates my "unique" image names, to make sure that dot's are not present and it fixed the problem ..
As a result, filename: 110333870356bc784cf1b6b0.56722572.png will instead become 110333870356bc784cf1b6b0656722572.png (or other generated filename).
Just to share my experience.
I had exactly the same problem but not for the same reason.
It was because the image file extension I wanted to insert (addImage) was in capital letter.
Example :
image.JPG ==> result a "corrupt" file.
image.jpg ==> result OK !
I hope it will help someone...
When I print to pdf, my cells have some spacing between them, which I cannot get rid of.
Basically I have similar problems as this:
How to generate a nice PDF with php Excel? (see the first picture)
which is described as solved
By setting cellspacing to 0 borders are handled almost as expected,
So I guess I need to set cellspacing to 0, it's just that I can't find out how to do that.
Update:
I found this http://phpexcel.codeplex.com/discussions/249376. But the solution involves messing with the source code of PHPexcel, I would much rather find a way to achieve this within my project, not changing the PHPexcel files..
See lines 1028 to 1032 of the HTML Writer. Cellspacing is set to 0 unless you're writing to PDF and getShowGridLines() for the sheet is true (which is the default value), in which case it's set to 1... so calling setShowGridLines(false) for the worksheet(s) before saving should set cellspacing to 0.
I'm using Excel5 in my project. I have already tried the following codes:
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->getARGB();
and
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getEndColor()->getARGB();
but these codes are returning wrong color. The getStartColor() always returning FFFFFFFF and FF000000 for getEndColor() instead of red.
I don't know what am missing. Can any one help me in figuring this out?
setReadDataOnly(TRUE) means read only the data from the cells, but none of the styling... and as background colours are part of the styling the reader will ignore background colours when it loads the file... if the fill style is not loaded, then the call to $objPHPExcel->getActiveSheet()->getStyle('A1')->getFill() will return default fill style and colours.
Load the file with setReadDataOnly(FALSE) and you should find it works
EDIT
This is way beyond the scope of PHPExcel.... everything is populated via DDE, including most of the styling, so the underlying fill colour is plain (as returned by the PHPExcel getFill colour call) until the external executable TOS.exe populates the data and sets the styles accordingly. Your only option here is to use COM so that the workbook is being executed in MS Excel itself.
Your second code:
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getEndColor()->getARGB();
Works , it just returns a color hex code (FF0000).
RGB = Red Blue Green = xx xx xx
FF0000 is actually RED.
I am using xampp/wamp on windows and looking to convert an excel workbook to a html file.
I am not asking this question right away, i did a lot of research and finally managed to get to a point and got stuck here.
Am using php's COM library to open excel, then read a workbook and try to save it as html, how ever i am having issues with it
This is my code
$excel = new COM("Excel.Application",NULL,CP_UTF8) or die("Unable to instantiate Excel");
$excel->Application->Visible=1;
$excel->DisplayAlerts="False";
$workBook=$excel->Workbooks->Open(realpath("./example-03e-02.xlsx"));
$workBook->PublishObjects->Add(xlSourceSheet, "c:\\temp\\x.htm", "Sheet1", "", xlHtmlStatic, "test_27778", "");
$workBook->Publish (True);
$workBook->AutoRepublish(0);
$excel->Workbooks->Close();
$excel->Application->Quit();
$excel = null;
$workBook=null;
The PUlishObjects method keeps telling me that xlSourceSheet is not defined, i tried to pass it as a string "xlSourceSheet" but it keeps saying parameter type mismatch in one or the other. IN the above case, it says parameter 6 type mismatch;
if i remove the optional parameters like divid and title (the last 2) it shows a type mismatch on source range which empty obviously since am exporting a sheet.
Any body can shed some light on this and tell me what i am doing wrong.
Thanks
Anywyas, i managed to sort out the problem with some further digging into excel developer manual.
I just had to replace xlSourceSheet and xlHtmlstatic with their respective numbers that i found in the docs. xlSourceSheet is 1 and xlHtmlStatic is 0.
If anybody is looking for these codes, here they are
xlSourceAutoFilter 3 An AutoFilter range
xlSourcePivotTable 6 A PivotTable report
xlSourcePrintArea 2 A range of cells selected for printing
xlSourceQuery 7 A query table (external data range)
xlSourceRange 4 A range of cells
xlSourceSheet 1 An entire worksheet
xlSourceWorkbook 0 A workbook
xlHtmlCalc 1 Use the Spreadsheet component. Deprecated in Excel 2007.
xlHtmlChart 3 Use the Chart component. Deprecated in Excel 2007.
xlHtmlList 2 Use the PivotTable component. Deprecated in Excel 2007.
xlHtmlStatic 0 Use static (noninteractive) HTML for viewing only.
$object=$excel->ActiveWorkbook->PublishObjects->Add(1,"c:\\temp\\x.htm","Sheet1",0)->Publish(1);
Thanks cweiske :)