PHPExcel trimming leading zero? - php

I know this has been asked a thousand times but what I am currently doing seems to be the general answer I see online and it is still not working correctly.
I am populating an excel document from a SQL query in which one of the columns is a ISBN10 of which can start with a 0 (but not every time) The excel rows are populated with a for each loop of which I have done in the past with no issues I've then added :
$objPHPExcel->getActiveSheet()->setCellValue('B'.$c,$row['isbn10']);
$objPHPExcel->getActiveSheet()->getStyle('B'.$c)->getNumberFormat()
->setFormatCode('0000000000');
To state that this field will be 10 digits (at least that is my current understanding that the setFormatCode will do, when the xls file is downloaded however the ISBN column still trims off all leading zeros, I'm a bit stumped with what to do as a lot of answers I've seen say this is the method you need to stop this happening?
Does anyone here have any ideas of what could possibly solve this?

Related

Scraping Oracle text-file using pcre in php

I would like to scrape a text-file which is the output from Oracle AP. I don't have access to Oracle, but need to assist in bug hunting and compare text-file against two csv-files from other systems. Importing the csv-files into a database is not a problem, but I'm struggling with this text-file.
The text-file is divided in two parts. What is successfully imported, and what is rejected. Each column has a specific width set by Oracle when creating the report. They will not change the setting for column width. If content of a column exceeds the width it simply continues on the row below. And columns for imported and rejected are not 100% the same.
For the successful imports it's simple, as there is one version of every row, but the rejected one might have more than one row for different reasons.
The import file is shortened and obfuscated for obvious reasons, as it can be several thousands of lines. It's best viewed in a text editor without word-wrap. I cannot get it to look any good in this forum with blockquote or code sample in forum editor, so please view/copy it from links below.
I'm showing the successful ones on regex101.com here.
Regex finding the imported (I'm sure it could be better, but it works and that is good enough for me):
\s(\d+)\s+([\D]{2,})(\d+)\s+(\d{1,2}-[a-zA-Z]{3}-\d{2})\s+(\w+)\s+([\w+\,]*\.\d+)\s+(\d)\s+([\w+\,]*\.\d+)\s+(\d{1,2}-[a-zA-Z]{3}-\d{2})
I'm struggling with the rejected ones however, due to the variations.
Duplicate invoice number, if there are more than one reason (column) for not being imported.
Missing supplier number and supplier name (always shows up in pair).
Here is what I'm done so far with the rejected ones.
Regex finding rejected:
^\s(\d+)\s+([\D]{2,})(\d+)\s+(\d{1,2}-[a-zA-Z]{3}-\d{2})\s+(\w+)\s+(-?[\w]{1,}\.?\d+)\s+
Clearly my regex for rejected is not the final result. It's crap at the moment. It would even scrape a successful row.
My questions:
Is it possible to have only one regex for rejected catching the variations mentioned in bullet points above? Example would be appreciated.
Is it possible to fetch the word-wrapped parts of a column? Example would be appreciated.
I'm trying to understand the PCRE documentation regarding conditionals as it might be of help when dealing with the rejected variations, but so far I'm struggling with it.
Regards,
Bjørn

PDFLib (PHP) - disable some cells to shrink

I'm working with PDFLib (9.0.4) with PHP 5.5 to create a very large table with a lot of very small cells.
I'm aware that PDFLib use a special algorithm to fit the table into a specified space. I would like to know how to prevent some cells to shrink.
My current problem is that some time to time, certain cells are not shrinked the same way as others while those cells are empty.
I tried to play with the column witdh, margins, ... nothing really worked.
I tried to play with horshrinking and vertshrinking options when I call the PDF_fit_table function. But those options are too general.
I'm looking for a way to prevent only certain cells to shrink.
Thank you for your time.
EDIT
This is not a problem of shrinking cell but stretching instead.
I've got the answer to my problem : you just have to specify vershrinklimit and horshrinklimit option into the PDF_fit_table function.
But I've post the wrong question. My problem is not a shrinking cell but un stretching one. My cell is empty and fit_table stretched it while it's not wanted.
I've found the solution to my problem.
by default, in case the parameter was not provided, I was pre-pending a colwidth for every cells ... even for colspaned cells.
So, if one of my table chunks were ending by colspaned cell with a colwidth specified, the colwidth were applied to every other cells above.
The solution was to test if the cell options string was containing the colspan parameter. If so, no colwidth parameter is prepend.

Date/Number ranges displaying incorrectly

I am using a 3rd party "shopping cart" program (CartWeaver) that uses a MySQL database. The products in my store have primary and secondary categories, the latter of which where my issue lies.
I am using date ranges (e.g. 1930-1939, 1940-1949, etc), however when I view the ranges on the product search page, the first number sequence is displaying incorrectly. For example, the date range 1930-1939 is displaying as 3860-1930, and 1940-1949 is displaying as 3880-1949 (you can see the issue at www.silverscreencollectibles.com/searchpage.php).
I have tried multiple variables to try to get around this, all to no available. Here is what I've tried: Starting the sequence with an alpha character, starting it with a special character, putting the range in single as well as double quotes, putting a space between the sequences, replacing the dash with the alpha "to". I have also deleted and recreated the subcategories, and nothing I have tried changes the result. The entry for "2000-Present" also displays incorrectly (as 4000-Present).
I'm just a dumb user, not a programmer, so any responses that anyone is kind enough to offer will need to be "dumbed down". The application support group wants me to either send them my entire database, or allow them to directly access my site...and neither option appeals to me, from a security standpoint. I thought I would throw the issue out to the StackOverFlow community to see if anyone has seen this sort of issue before, and may be able to point me in the right direction to address the issue. Thank you so much for your time.

Get CHAR_LENGTH of mysql entry as a php variable

Thanks in advance for any help!
I have several different mysql columns (which are imported from a product feed) that I'm trying to convert into one to work with a custom plugin for Opencart.
The format of the MYSQL entry for the plugin is as follows...
a:11:{i:13;s:3:"964";i:14;s:9:"Automatic";i:15;s:3:"FWD";i:16;s:15:"Gas I6 4.2L/256";i:17;s:5:"Black";i:18;s:4:"Gray";i:19;s:12:"Some City, ST";i:20;s:2:"15";i:21;s:2:"21";i:22;s:6:"128365";i:23;s:17:"2XXXXG3XXXXH5XXXX";}
As you can see, the "s:X" represents the character count for each entry. I have 11 different columns with the info I'm trying to convert to this format, but without an accurate character count the plugin throws an error. So i'm trying to use a combo of sql/php to get an accurate character count that I can use to make this work. I have a handle on everything else.
SO!
My question is...how do I assign the character count to a variable? I did some googling and I found this...
SELECT CHAR_LENGTH('TABLENAME');
I realize there's more to it, just wondering how to set it as a variable.
AND
Not terribly important, but does anyone recognize the format? I've never seen this before!
Serialized PHP Array
Not sure if this will help anyone in the future since this is pretty specific, but based on the info I got from jraede (thanks alot!). I was able to load all 11 columns into a PHP array and serialize, then upload to DB. WAY easier than trying to create 11 variables for character count!

Cannot get correct characters from Excel (utf8 formatted) into PHP

There are lots of questions and answers to all kind of character encoding problems, but none of them seems to solve my problem.
I get a spreadsheet every month which needs to be converted to Prestashop data. I still help myself by first converting the .xls to .csv, but it would be so much easier if I could do it in one go.
I use PHP-ExcelReader for reading the .xls file which is saved in Unicode (UTF-8).
My problem is that whatever output encoding I choose, there is always a number of characters that will not show up properly.
I have created a test page to show exactly what is happening under what conditions:
http://www.num1.nl/test.php
Hope someone can help out.
#grahamj42, I know it doesn't but all characters I need are handled correctly. Just for the test setup it was easier to display the full range.
#Captain Payalytic, phpExcel indeed did the trick for me. All essential characters are treated correctly now.
Now I only need to figure out why phpExcel expands my data range with 1 row.
Thanks so much for the tip :)

Categories