A component of a project I am working on is to import text in cells from Excel using PHPExcel as a quicker way to populate the MySQL database.
How can I achieve preserving the Rich Text formatting of the Cell Contents e.g. "The Quick Brown Fox".
I am guessing it would require parsing the content-format somehow into matching HTML tags? Is there a way to achieve this in PHPExcel?
Thanks!
It's mentioned in the documentation.
$objRichText = new PHPExcel_RichText();
$objRichText->createText('This invoice is ');
$objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month');
$objPayable->getFont()->setBold(true);
$objPayable->getFont()->setItalic(true);
$objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) );
$objRichText->createText(', unless specified otherwise on the invoice.');
$objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText);
Related
I have a text like Hello World in a cell.
I want to change Color of the text World alone.
I am using PHPExcel for creating excel.
I tried the below codes :
$objXls = new PHPExcel();
$objXls->getActiveSheet($sheetCount)->getStyle($cellCoordinates)->applyFromArray($styleArray);
The result of the above code is like whole text in the cell changed.
I tried PHPExcel_RichText also
$objRichText = new PHPExcel_RichText();
$objRichText->createText('World');
$objPHPExcel->getActiveSheet()->getCell($cellCoordinates)->setValue($objRichText);
This also didn`t worked.
Please help me to figure out the issue.
Thanks
I have a two PDF forms that I'd like to input values for using PHP. There doesn't seem to be any open source solutions. The only solution seems to be SetaSign which is over $400. So instead I'm trying to dump the data as a string, parse using a regex and then save. This is what I have so far:
$pdf = file_get_contents("../forms/mypdf.pdf");
$decode = utf8_decode($pdf);
$re = "/(\d+)\s(?:0 obj <>\/AP<>\/)(.*)(?:>> endobj)/U";
preg_match_all($re, $decode, $matches);
print_r($matches);
However, my print_r is empty even after testing here. The matches on the right are first a numerical identifier for the field (I think) and then V(XX1) where "XX1" is the text I've manually entered into the form and saved (as a test to find how and where that data is stored). I'm assuming (but haven't tested) that N<>>>/AS/Off is a checkbox.
Is there something I need to change in my regex to find matches like (2811 0 obj <>/AP<>/V(XX2)>> endobj) where the first find will be a key and the second find is the value?
Part 1 - Extract text from PDF
Download the class.pdf2text.php # http://pastebin.com/dvwySU1a (Updated on 5 of April 2014) or http://www.phpclasses.org/browse/file/31030.html (Registration required)
Usage:
include('class.pdf2text.php');
$a = new PDF2Text();
$a->setFilename('test.pdf');
$a->decodePDF();
echo $a->output();
The class doesn't work with all pdf's I've tested, give it a try and you may get lucky :)
Part 2 - Write to PDF
To write the pdf contents use tcpdf which is an enhanced and maintained version of fpdf.
Thanks for those who've looked into this. I decided to convert the pdfs (since I'm not doing this as a batch) into svg files. This online converter kept the form fields and with some small edits I've made them printable. Now, I'll be able to populate the values and have a visual representation of the pdf. I may try tcpdf in the event I want to make it an actual pdf again though I'm assuming it wont keep the form fields.
How to add the break to the data used as column heading in excel in php. I am having excel sheet from php that is in which I have to add heading for columns. I am able to do that but the problem is the data is more and I need it as one line after that how can we break it in excel sheet using php.
Can someone help me please thanks.
$this->excel->getActiveSheet()->setCellValue('A2', 'a.Please include the legends in the bottom of the table, like in the online version:<br>
f – Based on "Actual Final Budget or Actual Spending"
a – Based on "Actual Spending"
p – Based on "Provisional Budget"
');
This is the heading, and at present am getting data up to f only.
Someone help me please.
Use a "\n" character rather than an html break tag: PHPExcel uses MS Excel formatting, not HTML markup.
You probably also want to set the cell to wrap, and the row to autofit as well
Add semi-column after every statment
$str = 'a.Please include the legends in the bottom of the table, like in the online version:'."\r\n";
$str .= 'f – Based on "Actual Final Budget or Actual Spending"'."\r\n";
$str .= 'a – Based on "Actual Spending"'."\r\n";
$str .= 'p – Based on "Provisional Budget"'."\r\n";
$this->excel->getActiveSheet()->setCellValue('A2', $str);
Try this one, it should be working.
Im using PHPexcel Library for exporting data in my SQL Server Database
Is there a way to style a cell with "Comma Style", e.g., "1000000" as "1,000,000"?
Yes, using the number format function
<?php
echo number_format(1000000);//will output 1,000,000
Do read the full docs though, number_format() is far more powerful than that.
I'm trying to generate an excel file using html in php and responding with an excel Content-type. Everything works fine except new lines within a cell . They are not preserved.
I've tried 
 ;
 ; \r\n ,chr(13).chr(10) and it didn't work.
I'm trying to get the same result from alt + enter from microsoft Excel .
I am generating in a cell content like:
http:\\www.example.com\blah
(Link)
http:\\www.example.com\blah2
(Event) ...
these have to be in a single cell and also converting the link text to hyperlinks would be great :).
I've found a solution here: http://www.bennadel.com/blog/1095-maintaining-line-breaks-in-an-html-excel-file.htm
The solution I found is to add into a
stylesheet:
br {mso-data-placement:same-cell;}