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&""", ...
Related
I have CSV file in which some rows are highlighted yellow colored, Is there anyway we can select highlighted rows through PHP script like we read any CSV file in PHP but with condition of formatting color.
Thanks
Unfortunately the "colored rows" is a functionality of Excel/Spreadsheet software. The technical specification for a .CSV (comma-separated values) file does not include styling elements (colored or highlighted rows). (See: https://www.rfc-editor.org/rfc/rfc4180 )
You can see this if you open up your CSV file in a text editor (Notepad, Notepad++, vim, emacs, etc.) the content will be displayed, but no highlighting. This is very similar to how PHP (and other programs) see the file.
One work around to this would be to add a new field to the file (Another column in Excel) which you would have to set to a value, and then look for that value when you move through the file in your php code. For example in a new column, put a 1 in any row which is highlighted. Then within your PHP code, when you a reading in that .CSV file, look for a 1 in that new column, and that would be your "highlighted" row.
i have a html dynamic html table, i want to download this table as excel file.And after downloading i could make some changes in it and again upload it to a folder where it would change the database data according to fields..I was able to download the html table to an excel file, but have no idea how after changing the contents in the excel file would update the database according to it.I have heard of tongue twisters but this nerve twisting.
You may want to take a look at the PHPExcel library, available at phpexcel.codeplex.com.
If you want to do this with JS (I not recommend) you could copy/paste the excel content to a textarea in your HTML and then with JS you can do:
var temp = document.getElementById("yourtextarea").value.split(" ");
Since excel by default separates columns with '(tab)' you can explode it and save in the DB. You will also have to explode the newlines. It could be \r\n or just \n depending on your OS. After doing so, you can commit it to the database, row by row using Ajax.
If you can do it with PHP then would be much more easier. You could you explode() using newline at first (to break lines) and tab at finally (to break columns).
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.
I have a question which is (I think) not easy to solve.
I have an Excel-sheet (.xls) that contains multiple columns and multiple rows. The Excel-file is derived from an export from a database. Within that export all the HTML-tags are stripped from the content so when you open the Excel-file all you see is text and not any HTML-tags or whatever can be confusing for somebody without any knowledge of HTML.
After doing some changes to the Excel-file the Excel-file must be imported again into the database. Now the question comes: is it possible to place back the stripped HTML?
We are using PHP 5.3 on a MySQL-database. To read the data from the Excel-file we use php-excel-reader
Is there please anyone who knows if there is a solution for this?
if you open a file exported by MySQL you will see the structure, something like
1,,'john','Quesada'
2,'t#t.com',,'Fonseca'
3,,'Gabriel','Smith'
....
so the Idea is open this in a text editor and make find and replace, I.E you can find-replace and change all the fields with (empty space) for Insert into t1 values ( so the file will looks like
Insert into t1 values (1,,'john','Quesada'
Insert into t1 values (2,'t#t.com',,'Fonseca'
Insert into t1 values (3,,'Gabriel','Smith'
you do that and at the end you have the file as you want to,
try doing that with your file, try to open it with a text editor and customize it how you want to.
If you stripped the HTML tags while you export the content, it seems hard to recover it after, if you don't save it somewhere. Are you modifying the column containing the HTML content, if no, then you should just remove those column from the export, otherwise you will have to export without striping tags, maybe changing the separators.
I know the names of the columns I want to keep in the .csv file, but I am interested in removing all columns in the .csv which I don't recognize. How can php do this?
(The names of the columns are defined in the first row of the file.)
In PHP use fgetcsv() to read in your CSV file, ignore the columns you want and then write back to a CSV file using fputcsv();
Look at fgetcsv and fputcsv. Read the contents, write the columns/data back out that you want.