I need a phpspreadsheet code for reading data from csv file using vlookup and then writing it to multiple xlsx file depending on the criteria
Example:
Reading from this file
source
Getting output like this:
output
I might recommend the PhpSpreadsheet library, it's free and has great documentation on how to do this exact sort of thing.
Related
Is there any way to format the cells of a csv file with php ? For instance , i have a csv file that i need to format its cell's size before i export it.And another thing is that for numbers with many digits,the excel shows it in another format before i dobule click it and i want to get rid of this too.
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=export.csv');
I know that i have to show what i have already tried,but i couldn't find any information about this,so i have nowhere to begin...
EDIT: The file is csv but i use it as an excel file,and the excel cells are the ones that need to be formated
CSV format consists of nothing more than raw values; there is no way of storing formatting or data type information. Which is why most, if not all, spreadsheet apps let the user manually set column types when importing a CSV file.
If you want to spare your users the hassle of doing that, your best bet would be generating an xls/xlsx rather than CSV. PHPExcel is a popular PHP library for generating Excel files, you might want to give it a try.
Since the accepted answer was written in 2014, the PHPExcel library has been abandoned. It's last version, 1.8.1, was released in 2015. It was officially deprecated in 2017 and permanently archived in 2019. It's direct successor is PhpSpreadsheet.
PHP can parse a CSV string into an array by using str_getcsv (http://php.net/str_getcsv). From there it's simply a matter of editing the values of the array.
As for more advanced features, the CSV format in itself does not support them since it's a pure text format and neither PHP nor the CSV file can decide how Excel should parse the file.
I've had success with exporting Excel XML files (the old, pure text XML files; not the new, zipped ones) and if data presentation is important for you, this might be the way to go.
I am using php-excel-reader, but got error on reading .xlsx file. So does this support xlsx format. Or what is other solution available.
My requirement is just to read the file(xls, xlsx and ods) and render on html page.
PHPExcel seems too much as there is no requirement for editing the excel file.
Yes php support to read .xlsx file.
For that you have to use PHPExcel library.
I have created script to read excle file, You can download script from : https://www.dropbox.com/s/oao0eskflu8nyz1/PHPExcleReader.zip?dl=0
Judging from this issue it doesn't seem to work. They referr you to PHPExcel if you want to use xlsl files. From a first look, this seems like a better alternative anyways.
As far as I know php-excel-reader doesn't support xlsx. PHPExcel would be the way to go. That being said it might be better to store whatever is in your xslx files in a less proprietary way. Taking a long shot I would assume your xslx doesn't contain calculations which do belong in xlsx files but rather table data which would be better stored in some database (txt, csv, sqlite, a database server).
is there a way that I can format data from a .csv file created with the php function fputcsv into Excel-like tables? Meaning, I don't want my data to be separated by commas, I want them to appear in tables like an Excel spreadsheet or something.
I know I can do that in Excel itself, but is there a way to do that directly without tweaking the file in Excel (like with a php function or something)
fputcsv does exactly what the manual says:
It formats a line as CSV and writes it to a file pointer.
The output can then be imported into Excel or other csv-capable software.
You can generate Excel files directly via php, too, but therefore you have to delve very deep into the Excel file format. If you want to do this, I recommend PHPExcel. This project provides...
...a set of classes for the PHP programming language, which allow you to
write to and read from different file formats, like Excel 2007, PDF,
HTML, ... This project is built around Microsoft's OpenXML standard
and PHP.
There is one excel sheet which contains student name, rollno etc. How can i parse the contents of excel file and store that in my sql database?
You are looking for PHPExcel library i believe.
http://phpexcel.codeplex.com/
use this class to read the excel files
http://sourceforge.net/projects/phpexcelreader
If you want to do it directly from the Excel file, rather than create an intermediate CSV using Excel's "Save As" options, then look at libraries such as PHPExcel that can read the xls binary format and make the data accessible to your PHP script.
I'd recommend to you that you save it as csv, it's much more easier and less hacking to upload it to the database
here is simple a sample
http://www.bradino.com/php/csv-upload-to-database/
PHPExcel is one of the best PHP classes i have ever worked with. In addition to parsing and reading files of all Excel variations (including csv) the output to Excel 2007 + is excellent.
Be sure to look at the documentation and examples...they will get you up to speed very quickly
I need to implement a functionality where a user can upload an Excel file, that is, .xls file and i need to write a function that will read that file and then save the values in a table, compare them to values in another table and then print some kind of billing quotation.
From what I have read, it seems that the best way to do that is to first convert that file to an xml file and then write a function to parse that xml file.
I want to know, is it possible to write a function in php that will convert an xls file to xml. Assuming that the users will save and upload the file as xls.
Thanks.
i often let admin users upload a csv file they exported from an xcel file, its much simpler to parse through using http://php.net/manual/en/function.fgetcsv.php
A quick Google search for "PHP excel parser" turns up PHP Excel Reader, for an open source library to use for reading data from .xls files. There may be others that suit your needs.
I have been successfully using the 'ABC Excel Parser Pro' from Zakkis.
This allows converting from a XLS file directly into a MySQL table.
A few notes on limitations:
column count must match exactly to database columns
Excel 2007 format (xlsx) are not supported