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
Related
First of all, I do know the process of exporting MySQL data to excel file using php. But I have some specific requirement and I want to know if it can be done or not. I have already googled, but didn't get any specific information or method regarding the same.
This is my xls template :
Overview:
Column C is fixed and others are scrollable.
There are basically couple of organizations.
Data starting from COL-C8 to COL-L8 is exactly stored on a MySQL Table of an organization (e.g. Organization1).
Data of COL-C1 to COL-C5 & D1 to D5 is on another MySQL Table of Organization1.
So for every organization there are 2 different MySQL tables.
Requirement :
The goal is to export data from MySQL and add it to the excel file according to the image above.
Problem :
Adding data from MySQL table to excel is pretty easy if the requirement is to just replicate same on the excel sheet. But I have no idea how to do this customization.
Like pulling data from two different tables and adding them to different columns in an excel sheet.
Please let me know if it is possible. And if yes, then kindly direct me to some references on how to achieve this.
Thank You!
Try PHPExcel. This library allows you to read and write from/to .xls files.
We have a local site written in PHP, which contains some data in table format (index.php). It is a dynamically generated data/table, so I'm not able to access the database behind it.
Is there any way I can read the table in that web page, and write it to a text file in the same table format using perl/php/python?
The table is a huge one with around 1000 rows. But I need only the top 10 rows (sorted based on one of the columns).
Please help.
In PHP you can use file_get_contents() function to get the whole html of any page, than you can filter your required content and save it in a text file using fopen() and fwrite().
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).
When I do an import of data from a file, such as csv or text file, I would like to display on a summary page (table view) about what is going to be imported to the database, and user can select or deselect what will be imported into the database. I would like to find out what is the best way of temporary storing these data to be displayed onto the summary page?
To give a clearer understanding about what i am talking about, for example:
I have a csv file that holds a list of products.
I would do an importation to read the csv file and display onto a summary page with
table view and checkboxes to select/deselect some of the data.
After the selection, I would click the confirm button to store those checked data
So between the process of getting the csv data to the summary page for display, where should I store the data, in the database as a tbl_temp data and clean off when done, or just read directly from the csv file?
Thanks.
I would think an array would do the trick unless you think your environment is really unstable or, for user interface reasons, then just store to a temp file. Temp db table seems a bit much.
I would just display it in the browser, and stored? It's already stored, the uploaded CSV file!
Unless you don't run into an actual problem with that approach, why care?
Just use HTML to display the data read from the file in a web browser. Use standard HTML Form and form controls. Use PHP scripting logic to control what happens when the form is submitted. You could have the submit button hand off to a service or some other php file that could handle writing it to the db.
Why bother writing to a temp table, to just read back out and display in a form to be then written back to a perm. table.
If this were a process that you would be performing a lot, i might give it a little more consideration.
HI,
I am trying to display results from a database in results.php. In the same file, after all the data has been displayed in the current webpage,I am placing a button to create a file based on this results to produce a Excel file.
I am not sure how to do this. I have tried but it says you have to force excel file download before any echo, but I want to display as well as produce an excel file. Is this possible or am I missing something? can anyone please let me know how to do this correctly?
You have to change the header for the page, so you have to open the output for the excel file in a new window.
Header type: "application/vnd.ms-excel" .
If you want to create "good" Excel sheets , take a look on PHPExcel
PHPExcel
You're probably faceing an 'Header allready set' error. You need to separe the two steps in order to make that work. One step for displaying and one for excel file creation and downloading.
On th other hand you could combine the data display and excel creation too and eventually display a download link.
Just pokin in the dark, let us know which way you wanna go and we'll be helping you along...
This has been discussed before at StackOverflow:
Export MYSQL result to Excel..
PHP code to convert a MySQL query to CSV
See also these examples and tutorials:
Easy way to create XLS file from PHP
Export MYSQL data to CSV – PHP tutorial
PHP Script: Export MYSQL Table Data to CSV
Advanced CSV Export
Set your headers first and then echo your CSV output:
header("Content-type: application/text/x-csv");
header("Content-disposition: attachment; filename=report.csv");
echo "value1,value2\n";
echo "value3,value4\n";
You could create a .cvs-file which are a lot simpler than xls-files, and the best part is that excel supports .cvs-files.
Then while you are outputting your data to the user, have a seperate variable called something like $cvs which you apply the same data as you output, just in the .cvs-format and when you're done you write $cvs to a file.
Then you just link to that file at the bottom of the page.
You may have to force the download upon the user though.