Adding new line in excel cell generated via html - php

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 &#13 ;&#10 ; \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;}

Related

How to Change color of a particular text using phpExcel by reading the text from the cell?

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

docx to html with phpword issue

I'm encountering an issue when converting docx document into HTML with PHPWord library (https://github.com/PHPOffice/PHPWord).
Here is the code snippet I use:
$phpWord = \PhpOffice\PhpWord\IOFactory::load('test.docx');
$htmlWriter = new \PhpOffice\PhpWord\Writer\HTML($phpWord);
$htmlWriter->save('test.html');
The issue is that each block of text is encapsulated in <p> tags regardless if I defined titles in the docx document. I would expect <h1> <h2>... tags to be generated. Bullet list are lost too.
Does it work as designed or did I miss something?
Thank you for your feedback.
Regards
There's a little bit of a problem when it comes to using IOFactory::load of PHPWord such as what you encountered now, depending what saved the file or what version of Microsoft Word is used to create that file. If the encoding and tags of the docx file cannot be found by PHPWord , then it will produce unexpected results
The code is fine, the problem is already with the dependency.

create excel line break within string using php xlsx writer

I'm using php xlsx writer (https://github.com/mk-j/PHP_XLSXWriter) to create my excel file and try to figure out how to force excel to make a line break.
My source data contains html tags (<br />) and i want to replace them with the correct formular. The replace function is working but i need how the string needs to be formated to force the break.
The line wrap option at format cells is enabled for the column as shown in the picture below (excel is installed german at the moment - please don't hate me for that)
What i tried so far is using CHAR(10) and CHAR(13) - altough CHAR(13) should be for mac and i am on windows.
I tried the following inputs to get my line break working. Also i tried all of the combinations with \n and \r\n instead of CHAR(10) and CHAR(13)
="text"&CHAR(10)&"text"
='text'&CHAR(10)&'text'
=text&CHAR(10)&text
The data was entered in the formular row in excel (picture below) - i think this is the only possible location to enter this isn't it?
Whatever i try my output always looks like this:
Any suggestions what i could do?
Thanks for your help!
The question got answered in https://github.com/mk-j/PHP_XLSXWriter/issues/114.
There was a release of a new brunch supporting new line character which fixed the problem.

PHP pdf form parse regex

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.

Converting html for mysql - what to do with <br/>s?

I’m converting a number of html documents into csv files to upload into MySQL – I’m replacing html div’s etc with tabs as necessary in a text editor to get the data into the columns, then pasting into a spreadsheet and saving as CSV. This is working fine
A couple of ‘fields’ have data on more than one line, which in html is achieved by using br’s, leaving these in the CSV displays the data in the required format.
I’ve also produced a script to add/amend data and for the multi line fields I’m using textareas and then outputting using nl2br() which again displays the data as required. But the uploaded data with br’s is displayed in the add/amend script as a continuous line with the br’s.
Question – Is there anything I can do when manipulating the html data to replace the br’s so that they appear as multi lines in the textareas ?
Replace with "\n"
<?
$string="Some stuff <br/> some other";
$string=str_replace("<br/>","\n",$string);
?>
<textarea><?=$string?></textarea>
You can replace with \n instead of br tag

Categories