CSV file keeps changing numbers on generated CSV file using php? - php

i am working in mysql table to generate CSV file conversion using php.
Credit card numbers are shown in mysql database like this 44445959636345. When i converting mysql table to csv file it doesn't show proper credit card number shown just like this 4.4446E+13
My sql query is $this->dbutil->csv_from_result($query);
CSV files changes all the card numbers! For example if your card
44445959636345
Instead of showing up as shown above... CSV changes it and makes it show up as:
4.4446E+13
How can i solve this issue please guide me.

If you want to view the csv file in excel you can put a single quote in front of the number that way it will be displayed as text.
WARNING this means that you need to remove that quote when importing a csv file like this into your DB. This can be done with php or sql substring functions.
so instead of 44445959636345 output '44445959636345 to your csv file.

The problem is: the function refers to the credit number as an integer. What you have to do is to make it refer to it as a text.

Related

CSV file number format is different in EXCEL and Notepad

I have received a report as an CSV file. It contains the contact names and contact numbers.
When i try to open the file in Excel, it displays the contact number like "912224308876". But, if i try to open that file in notepad or try to read in PHP then i get that contact number in different format i.e. "9.12224E+11".
Does any one has idea to solve this issue?
Thanks in advance.
The problem is that Excel treats long numbers as floating point and converts them to scientific notation, often in a lossy way. As described below, the best options are either to use a TXT extension instead of CSV and use the import wizard (which allows you to specify column types), or to use a formula instead of a number to fake out Excel.
http://social.msdn.microsoft.com/Forums/en-US/exceldev/thread/64c1ee52-eb53-4202-bb27-d9b08d3bd60a/

program to convert sheet1(excel) into standard sheet2(excel)

Is it possible to write a program that change the order of columns in sheet1(excel) based on a table in standard sheet2(excel)?
Sheet1 have the same header of each column as sheet2 but the position of columns is not same and also it is possible that some more columns are present in sheet(1). Finally I have to store the standard sheet into the database.
Yes it possible to change the order of columns.
Steps:
Change the excel sheet format file to csv file.
Write a PHP code to arrange the random columns as per the standard sheet.
Write a code to enter this data into the database. Each time you receive the new column append it at the last of the standard column.
Make the respective change in the PHP code for the same.
This is probably a dumb answer, but back in the day I used VB code inside of Excel workbooks to manipulate data including culling information from one worksheet and creating another based on contents.
Try http://msdn.microsoft.com/en-us/library/office/ee814737(v=office.14).aspx for more information.

turn excel column into php strings

I have an excel file with a large amount of strings in a column. I want to add these to an array in a php file, so I want each cell in the column to be enclosed in apostrophe's and insert a comma between each. I tried copying the excel column to word and doing a find and replace in word but it uses a different apostrophe type. Any ideas?
Export the Excel file to .csv, then you can either learn to read .csv files from PHP, e.g., from this tutorial, or do something more pragmatic like open the file in a text editor like BBEdit and select the column you want using block-select mode, discarding the rest of the document.
I'm not so sure about the """ but I used a similar method to create SQL queries from cells.
="""&A1&""","""&B1&""", ...

Convert CSV data into fixed width records using PHP and php-excel-reader class

My end result is to have a fixed length record created from either a csv of excel file using PHP. I have am working with excel_reader2.php and seems to import this nicely and displays it in the browser. I would like in turn to export or write the contents to a file so that each column would export as 35 characters fixed length fields . currently the $data is formatted as html and dont know how to write down what i am describing. Thank you in advance for someone to point me in the correct direction.
You would take every row of the CSV file. Then, every column of the row. For every cell you could use:
$newcell = sprintf("[%35s]\n", $cell);
So you would have a 35 chars width string with the data of $cell. And then, just add it via two loops into a file.

cell data format problem while getting php excell output

i created an application that takes the excell output of a table.There are long numbers in table cell.When i took the output the cells that have long numbers are seen like that 1234+E34.how can i fix that?Thanks for advance...
So you're not actually writing an Excel file: It looks as though you're writing an HTML file but sending headers to the browser telling it that it's an xls file...
Excel can then identify that HTML, and parse it into a structure that it can display.
You have a couple of alternatives.
The first is to create a genuine xls file rather than trying to con the browser and Excel. The Second option: instead of writing the value as
12345678901234567890
write it as
="12345678901234567890"
This will display in excel as "12345678901234567890" (with Quotes)
To avoid this, Use intval(12345678901234567890) in php, This forces Excel to treat this number as an integer

Categories