For my website i want to give the user a new opportunity ,which is to export all user details in a excel file.It is possible to perform in php,if possible than may i get a link to this kind of work.
Simplest way is to use the built-in fputcsv function
PHP Manual - fputcsv
Related
I have been wondering whether or not it is possible to write VBA to an excel file using php? I ask this question for this reason -> I want to generate an excel report every monday when our users log in. The reports will pull data from our sql db, and write the data to an excel file.
My question is multi-part.
1) Is it possible to write data to an excel file and save that data without the user seeing it?
If I can, then I know how to have it attached using php mailer.
2) If it has to open as a result of using headers, can i write a vba script to minimize or make active workbook close. (I'm highly doubtful as it is because I think excel docs open up as csv when writing sql results to them.
Here's my clients scenario my client wants to put a excel file on server now from a PHP form
sends data to the file runs a formula in this excel file and get the results.
I don't know if this is possible.
If so direct me to a library best was PHP, or some other possible solutions.
It's perfectly possible: take a look at the PHPExcel library which has a built-in calculation engine for handling most Excel formulae
There's an example of populating an Excel file with data (in this case from a form input) then rendering a formula in that Excel file to generate a result an ddisplaying it to a web browser in the /Tests/ directory of the distribution. This simple example /Quadratic.php solves a quadratic equation; but the principle is similar enough
EDIT
See my response to this question for some indication of the limitations of PHPExcel's calculation engine
EDIT 2
The PHPExcel is deprecated, hence now you can use PhpSpreadsheet
You are thinking in the wrong direction. Instead trying to send the data to the excel file, read the excel file in you PHP script and do the math there.
Trying to send dynamic data into a static XLS file wont work.
And you can add a regular cronjob, that checks if the XLS file data has changed, if it has, then run your calculation again.
I want to modify a already existing excel sheet using PHP.
I tried to use pear class Spreadsheet_Excel_Writer.But this class is used to entirely create a new excel sheet and write in it.
Is there some way i can modify the already existing excel sheet using PHP?
I do believe, that PHPExcel class can help you out, but you may have to do a read and then a complete rewrite to another spreadsheet. I do not know, if the class allows for just modification.
A good solution for this is contained in PHPExcel... but... one can not modify an existing file. You have to open it, read the data, and write the modified data while creating a new excel file.
Its very good documented, accessing the data is very easy. A whole separate documentation is made for reading spreadsheet files.
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.
I have a PDF document that contains data that I would like to extract and store in a MySQL database. Could anyone give me some guidance or perhaps sample PHP code?
There's some basic code here for performing text extraction from a PDF. Might work for you. For commercial libraries, check out pdflib which I believe can do similar extraction.
Once you have the data, it's up to you to massage that into MySQL INSERT statements to create your database.
I often use the FPDF library to create PDF documents via a PHP script. Plenty of examples and documentation here: http://www.fpdf.org/
What do you wanna do ?
If you want to store the PDF in a MySQL database, i recommand you to store the pdf in a directory and the path to the pdf in the mysql database.
Or you can store file_get_contents($pathToThePDF) in the db but I don't think it's a good idea.
If you want to create with PHP a PDF with data from a MySQL db, i also use fpdf (like rascher) to do that and it works well + there are many example on the website.