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.
Related
This is a very similar question to others asked, but I'm using Excel 2011 on a MAC and don't seem to be getting the desired result.
I have been exporting each sheet in an excel file manually as a windows comma separated CSV file (not MS DOS CSV) and using a bit of php my tables display perfectly on my site.
Using the code below in a Macro I can successfully export individual sheets as individual CSV files with one click. However, they don't have the .CSV extension at the end of the file name, and although the look okay with commas in the right place, when I upload them to my web site, they are displayed in one long row, instead of several rows.
Is this a MAC excel issue, or is there something that can be added to the below to fix?
Sub asdf()
Dim ws As Worksheet, newWb As Workbook
Application.ScreenUpdating = False
For Each ws In Sheets(Array("Sheet1", "Sheet2"))
ws.Copy
Set newWb = ActiveWorkbook
With newWb
.SaveAs ws.Name, xlCSV
.Close (False)
End With
Next ws
Application.ScreenUpdating = True
End Sub
Try building the extension into your filename:
.SaveAs ws.Name & ".csv", xlCSV
When you check the original file listing in the Finder, it reports "Simple Text Document", when you add the .csv extension it reports "comma-separated values" as the file type (Kind). Maybe this will fix your browser import issue?
If not an option may be to write out your data cell-by-cell. This similar post may be helpful to you.
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 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 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&""", ...
I am generating a simple csv file using php. The file contains some user's personal data.
When I open the generated file in office, the addresses are not displayed in full height. I have to double click on the cell for the address to be shown fully (in full width and height) otherwise I can only see the first word/number of the address.
Also, I have date of births displayed as ######, I have to expand the whole column to see them fully.
This doesn't happen in open office.
Is there any way to force MS Office to show all fields in full? Because otherwise it'll be to confusing for the people who will use (Hey where are all the details!:)
Thanks :)
I don't think you can "format" your sheets with CSV. You will have to produce some other file format that Excel understands. I would suggest XML which is really easy to generate.
Just make a sample sheet with the data you want, save it as XML and you'll see how your file should be generated.
Or you could use some ready-made PHP solution for writing excel files if you can't be bothered with analysing the XML file.
you could try the auto-size columns feature.
This is a UI issue with how Excel works, you can't force Excel or anything else how they handle it.
The quickest work around is to perhaps create an XLS file that runs a macro to retrieve the CVS file and format the cells as needed, but there's nothing you can do inside the CSV to affect what Excel is displaying.