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.
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 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&""", ...
Is there some utility that could be called via command line to produce a doc(x) file? The source file would be HTML and CSS.
I am trying to generate Word documents on the fly with PHP. I am only aware of phpdocx library, which is very low level and not much use for me (I already have one poor implementation of Word document generation).
What I need from a document:
TOC
Images
Footers/Headers (they could be manually made on each HTML page)
Table
Lists
Page break (able to decide what goes to which page, eg one HTML file per page, join multiple HTML files to produce the entire document.)
Paragraphs
Basic bold/etc styles
I didn't find PHPDOCX very useful either. An alternative could be PHPWord, i think it covers what you need. According the website it can do these things:
Insert and format document sections
Insert and format Text elements
Insert Text breaks
Insert Page breaks
Insert and format Images and binary OLE-Objects
Insert and format watermarks (new)
Insert Header / Footer
Insert and format Tables
Insert native Titles and Table-of-contents
Insert and format List elements
Insert and format hyperlinks
Very simple template system (new)
In your case that isn't enough, but there is a plugin available to convert (basic) HTML to Docx and it works very good in my opinion. http://htmltodocx.codeplex.com/
I am using this for a year or two now and am happy with it. Altough i have to add that the HTML can't be to complex.
The way I usually do these is to have a word document template file with the parts I want to replace using keywords (usually something like "{FIRSTNAME}").
This allows you to read the file via PHP then simply do str_replace on all the parts you want to replace, then write that to another file.
Dynamic tables using this method are a bit more tricky, as you need a sub template for a row, which you can then include inside the main template as many times as required.
I'm not sure if this is the best solution, it's always seemed very fiddly to me and every time I'm asked to do this I get frustrated with it, but I guess it works. So if anyone knows a better solution I'd love to hear it too!
I've got a custom table in WordPress and I'd like to be able to export the data in that table as a FILE in CSV (semi-colon seperated) format.
I've got the data coming out properly, but how do I then save it as an attachment?
Keep in mind that when using WordPress, headers have already been set... and I really don't know how to get around that.
I'm not sure exactly HOW you're doing what you're TRYING to do ...
... but this link gives you a simple, straightforward way to write the data as a .csv file you can do a "save as" from your browser:
http://wordpress.org/support/topic/export-wordpress-db-table-to-excel
For these plugins, they use database to store row & column details. You have to extract the data in MySQL database tables ( those table names are usually named after the plugin's name ) .
If you are still not sure how to do, you can just copy the table being displayed in page in browser, then paste in Excel. Last, save as CSV or XLS if you like.
you can use this code. just copy and past and you have it :)
https://gist.github.com/umairidrees/8952054#file-php-save-db-table-as-csv