PHPexcel Read single cell in xlsx - php

Ive been trying to wrap my head around using PHPexcel and would like ot know if there is any other simpler solution.
Using PHPexcel i am able to load a standard .xsl file and pick the exact cell i need to import.
$code = $data->val(2,2,0);
echo $code
Now this works perfectly, it will echo the second cell in the second row without any issues. problem is the spreadsheets i need to parse are all in .xlsx format which PHPexcel does not support.
Is there an alternative to PHPexcel which will allow me to simply extract a single cell in a .xlsx file?

Related

How to edit pariticular cell in spout PHP excel writer

I was using PHP Excel to generate a large excel, but PHP Excel consume more memory, it consume 377.37 MB memory, so now i am tried to generate excel with spout excel library
in my case i have pre-generated excel file, i want to just write value of particular cell For Ex- modify value of D48
How can i do this with spout excel?
PHP Excel allow to access and modify particular cell
$objPHPExcel->getActiveSheet()->setCellValue('D48','New value');
Is there any methods like setCellValue() in Spout
There are no direct way to do that. You can take a look at this example: https://github.com/box/spout/wiki/Edit-an-existing-spreadsheet to achieve what you need though.
Just be aware that styles are not preserved when editing a spreadsheet.

Formatting the csv(excel) cells in php

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.

PHPExcel setReadDataOnly is not working with Excel 2007

I am using phpexcel class to read .xls, .ods and .xlsx files, I need to ignore blank cells, even, if these cells have format.
I have used setReadDataOnly method to get it, and it's working fine with .xls and .ods files but it's not working with .xlxs files.
What exactly do you mean by "not working".
The setReadDataOnly(TRUE) option on read doesn't prevent blank cells from being read if the cell actually exists in the spreadsheet file, it simply means that it doesn't read the formatting for any of the cells... a blank cell is still a blank cell, and unless you create a read filter to prevent certain cells from being read, then they will still be loaded.
This behaviour is identical for xls, ods and for xlsx.
The only facility provided in PHPExcel to "skip" blank cells is within the Cell Iterator.

How can i take an excel file, parse it contents and store the column's data of excel sheet in my database column?

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

CSV files and multi line text cells

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.

Categories