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.
Related
I am using php fopen on a .doc word document.
I am getting all this "garbly gook" on the top and bottom of the displayed page on the browser when opened. I'm assuming this is meta data of some sort...
This displays on the top before the writing is displayed.
"CB
(),-./0123456789#ADRoot Entry
FMicrosoft Word-Dokument
MSWordDocWord.Document.89q
hhDefault1753A3BOJQJCJsH sH KHPJnHJaJ_H9tH9FFHeading xOJQJCJPJJaJ.B. Text body
x / ListJ##Caption xxCJ6JaJ2IndexJ1tj6/i
j78911PGTimes New Roman5Symbol3Arial5SimSun3ArialGMicrosoft YaHei3ArialBhgn033n033 0 0Oh08 #
LXd p58####oW6.,D.,M 0
jCaolan80 t1674/b"
I don't want this, this is obviously not data I want to be displayed, only the writing within the document. Is there a way to remove this? I know a doc file is a sort of blob but is there some structural aspect to it that I'm not aware of to remove this junk before outputting. Thanks so much!
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
I am using the PHP extension FPDF to create PDF documents. I believe I have the margins set to 1" all the way around with justified text, but when I create a PDF document, download it and open it in Acrobat, I see the left margin is 1" but the right margin is about 1.2". I've gone through fpdf.php looking for the issue and cannot find it.
$oPdf = new myPDF('P', 'mm', 'letter');
$oPdf->Open();
$oPdf->SetMargins(25.4,25.4,25.4,25.4);
//set default font/colors
$oPdf->SetFont('Times', '', 12);
$oPdf->SetTextColor(0,0,0);
$oPdf->SetFillColor(255, 255, 255);
//add the page
$oPdf->AddPage();
$oPdf->AliasNbPages();
If I change the top and left margin values, the document reflects the changes. If I change the bottom or right, there is no change. I've seen how the bottom can be changed wth set auto default page break, answered elsewhere. My question is how can I change the right margin and it actually take effect in my document? I have a feeling that this has to do with the measurement of the text when FPDF calculates whether the justified text will fit on the line. I've checked the width of the line and it outputs 165.1 (which is 6.5 inches x 25.4mm) Completely stumped.
Ok, I feel kind of dumb, but hopefully this will help others. I use the FpdfMulticell (See http://www.interpid.eu/fpdf-multicell) for more control over cells and other parts of displaying the content on the PDF document. This is great and all, except for the redundancies that are created. The components of this function require width and height for the cell to be created. This is where the problem was. For some reason I was passing 160 to it rather than 165.1. 6.5" x 25.4 = 165.1. When I go through the references to create the multiCell function within the class, it fixes my problem.
If you're going to use the multicell, I suggest declaring a variable at the beginning of your page such as $pw (i.e., page width) and then instead of passing a constant value, pass the variable. That way your values are uniform and if you want to change it up, then you only have 1 value to change. Make sure you comment so you know what the purpose of that variable is.
$oMulticell = new FpdfMulticell($oPdf);
$pw = 165.1
//Make sure that the content is long enough to go to another line or you won't
//notice the difference with the justified text
$content = "Write some text here Write some text here Write some text here Write some text here Write some text here Write some text here Write some text here Write some text here ";
$oMulticell->multiCell($pw,10,$content,0,"J",1,0,0,0,0);
This works!
I'm new to tcpdf, creating my first document.
I wonder if there is a way to fit the width of the cell automatically to the content. I currently only see options for fixed size, or taking the whole page width until the end of the line.
I'm aware of GetStringWidth() but having the following problems with it
Why should one bother even for this? Is there a way to just make the cell fit automatically to its contents width?
GetStringWidth() seems to err from time to time, giving shorter results the actual, thus causing the text to be split to the next line. A font is set.
After learning TCPDF more, this is the conclusion:
Cell() and MultiCell() are not intended to be used for just outputting a string and fitting it's length. Instead, Write() and WriteHtml() should be used. Cells exist for the case where you actually want to control the dimentions of the field manually.
Nevertheless, in some cases one may want to compute the width of the cell, such that it takes into account the sizes of the text inside. For this purpose exists GetStringWidth(). (Unfortunately for me it err's from time to time. Maybe I'm not aware of something)
Have an internal "Legacy" application that uses TCPDF to generate a PDF of a checklist. We recently moved from creating a giant string of HTML that described a table, created using the $pdf->writeHTML($myHTMLString); method, to using the MultiCell() methods.
However, we ran into an issue where some text in a description cell would need to run on to a second line, this threw off our layout. As a fix, we created an if block based on 2 variables, one for the string width the other for the actual cell width. (We had 2 instances where the cell width might vary).
If block example:
// Get width of string
$lWidth = $pdf->GetStringWidth(strip_tags($clItem['description']));
// Determine width of cell
$oadWidth = (.01*$width[0])*186;
if ($lWidth < $oadWidth) {
$cHeight = 3.5;
} else {
$cHeight = 7;
}
We then used the variable created by the if block in the MultiCell() like this
$pdf->MultiCell((.01*$width[0])*186, $cHeight, strip_tags($clItem['description']), 1, 'L', 1, 0, '', '', true);
We reused the $cHeight variable for the height params in the other sibling cells so each row of cells had a uniform height. You could most likely reuse this method with any of the other right functions that have a height parameter in TCPDF. Thanks to #shealtiel for the original reference to GetStringWidth()
I am having trouble getting a text field to auto size on a form I'm creating. I am setting the textSize of the properties to 0 in the properties of the TextField but it seems to just use the font set for the document. Here is the code I am using to create the TextField.
$pdf->TextField('description', 195, 32, array('multiline'=>true, 'lineWidth'=>0, 'borderStyle'=>'none', 'textSize'=>0), array('v'=>$description));
I know a kinda round-about way of possibly fixing this..
Before your textfield code, what ever you would like your font to be (not the default for the entire document) you could always try:
$pdf->SetFont('fontName','',fontSize);
And after your textfield code, just set the font back to what ever you wanted it to be for the rest of the document.
Not really sure if this was exactly what you were looking for, but I hope it helps. Good luck with it all.
I faced also that exact problem. I had a long time before I could find out the solution to this.
To make the field auto size the textual content, the font size of the field must be set to 0. It looks like TCPDF doesn’t support the javascript textSize option (see at the end of TCPDF_STATIC::getAnnotOptFromJSProp() ), so we must set the font size to 0 before the field, and set back again to its original value after the text field :
// Beware to use getFontSize*Pt* and not getFontSize.
// getFontSizePt gets the size in pt, and getFontSize gets the size in user units
// (units you gave when you created TCPDF object or default to mm)
// We need to set it again back with SetFontSize() which takes the font size in pt
$originalFontSize = $pdf->getFontSizePt();
$pdf->SetFontSize(0);
$pdf->TextField($name, $w, $h);
$pdf->SetFontSize($originalFontSize);