create excel line break within string using php xlsx writer - php

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.

Related

how to find word position in PHPWord

i just interesting using PHPWord to be my MS word file editor. lets go to the case!.
first i have ms word file named template.docx. below are the data inside the file.
Name : ${name}
Address : ${address}
Now, i want to find this using php, i want to find any "${" word, why?, because it could show what name that could be inserted dynamically, so i could foreach those later on. the problem is, its not that simple, i see OOXML are using something that seperate the wording. Question is, how to solve this problem?.
i already try this code
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
but it cannot work with me.

HTML text in a Database

I want, that a user can format text (just like in this box) - And should store it in a database.
How can I achieve such a thing?
Save the string containing the HTML code of the text in the database.
Usually a string like this: 'String test format' is saved in the database as '<b>String</b> <i>test</i> format'.
Thanks for every information i got.
Due to you i started looking for wysiwyg ediots. (Like TinyMCE <- but i didnt used that^^)
Im using CKEdior - thanks!

OpenTBS Excel number format

I'm trying to format numbers in an Excel file using PHP and opentbs.
Here's template code I'm working from:
[gross_pay_names;block=begin;sub1=departments][gross_pay_names.name]
[gross_pay_names_sub1;block=begin]
[gross_pay_names_sub1.val; ope=tbs:num]
[gross_pay_names_sub1;block=end]
[gross_pay_names;block=end]
The problem is in the third line:
[gross_pay_names_sub1.val; ope=tbs:num]
It always renders with an apostrophe in the beginning ('0.00). So I can't use it in other formulas in the file.
Ok, I found a solutions myself. In case anybody needs it in the future here's the template code I ended up using:
[gross_pay_names.name;block=tbs:row;sub1=departments] [gross_pay_names_sub1.val;block=tbs:cell;ope=tbs:num]

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.

Adding new line in excel cell generated via html

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;}

Categories