I copied this code from PhpSpreadsheet's documentation and it does not work.
This example can be found on this page:
LINK to PhpSpreadsheet's documentation
From the above link
My code:
$sheet->getCell('A2')->setValue(19);
$sheet->getStyle('A2')->getNumberFormat()->setFormatCode('0000');
// will show as 0019 in Excel
But its not working and this is the result:
The expected value of cell $A2 should be 0019 but it shows 19.
Any idea on how to fix this?
Maybe you use a CSV format try to use Xlsx, I think styling in CSV is not working.
I think this is already issued and there's no solution yet. I'm also looking for the solution but the solution i only found is not use CSV.
https://github.com/PHPOffice/PhpSpreadsheet/issues/2230
Related
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.
I have a cell in an excel sheet that i am trying to read.
When I use the function getCalculatedValue it's throwing following error:
Financials!LU83 -> Financials!LU81 -> Formula Error: An unexpected error occured
I wrote following function to read from a cell
private function getCellValue($data)
{
//example of data variable
//$data = [0, 'G79'];
$excel = $this->excel;
$excel->setActiveSheetIndex($data[0]);
\PHPExcel_Calculation::getInstance($excel)->flushInstance();
\PHPExcel_Calculation::getInstance($excel)->clearCalculationCache();
return $excel->getActiveSheet()->getCell($data[1])->getCalculatedValue();
}
that cell that I am trying to read has following value
=LU83+LT84
where LU83 has following value
=LU73-SUM(LU76:LU81)
LU81 has value
=VLOOKUP(LU8,'Wiser Return'!$O:$S,5,0)
I have no idea why I am getting this error. I wish there was a way to debug? Is there a way?
Any help is appreciated.
Thanks
The problem is that PHPExcel's calculation engine does not fully support row or column ranges.
=VLOOKUP(LU8,'Wiser Return'!$O:$S,5,0)
contains the column range $O:$S
If this can be converted to a cell range instead, e.g
=VLOOKUP(LU8,'Wiser Return'!$O1:$S1024,5,0)
then it should handle the formula correctly
I can't comment now, but I found some link that might help you.
In this question the accepted answer states, that you can get further information about the error with this gist.
(I suggest deleting your question if this helped you.)
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]
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.
I've been working with PHPExcel over the last few days and so far it's been perfect for what I need. However, today I've been trying to use mergeCells for "colspan" functionality but when I do it causes unreadable content errors and MS Excel prompts me to repair the file.
The code I'm using is:
$first = PHPExcel_Cell::stringFromColumnIndex($xCount).$yCount;
$second = PHPExcel_Cell::stringFromColumnIndex( $xCount + 2).$yCount;
$cell_merge = $first.":".$second;
$this->excelDoc->getActiveSheet()->mergeCells( $cell_merge );
I've output the result of $first, $second and $cell_merge to ensure I'm going about it the right way and the content is correct. Furthermore, when I try a static merge of cells (by entering mergeCells('A1:C1'); it works perfectly.
Would it be possible that trying to write to a merged cell would cause problems?
EDIT: just a note: I also tried to cast the variable as string just in case like this:
$this->excelDoc->getActiveSheet()->mergeCells( (string)$cell_merge );
... but no luck.
Just for future reference. The problem here existed between the keyboard and chair.
I was attempting to change the colspan during a loop and in this loop I had a call to mergeCells with 'A0:C0'.
When passing row "0" I wasn't getting any errors, just a bad excel sheet. Something to bear in mind.