G
G
gsur2018-03-01 14:29:06
Google
gsur, 2018-03-01 14:29:06

How to read excel files in PHP?

Good day, actually a few questions.
The essence of the task is to get data from an excel file created in 1C using PHP and put it into the database.
Phpexcel and PhpSpreadsheet cannot load some of the files, and if one library loads normally, then the second is not the fact that it will do it, I can’t use them in specific cases, because the same user can load 2 seemingly identical files, and the difference, which cannot be intercepted, may not allow it, and if the files are "resaved" in MS Excel, then everything is fine, but I cannot force users to do this, I tried EasyXLS, paying repels the customer.
The question is - are there any other libraries for reading tables? Let me remind you that files are generated by 1C.
Question 2 - I haven't tried GoogleSheets yet, I'm tired of wasting time, and I decided to ask if it's possible to read files through this service without uploading to GoogleDocs, I can't find any information...

Answer the question

In order to leave comments, you need to log in

6 answer(s)
D
Dmitry Shitskov, 2018-03-01
@gsur

Before working with the file, try resaving it in xlsx (or even in csv, which will definitely not be a problem).
We used the unoconv utility (in fact, LibreOffice) for this purpose. Converted xls and xlsx from clients to csv, because working with xlsx started to require a lot of OP and time using the libraries you mentioned.

J
Justique, 2018-03-01
@Justique

I am using https://github.com/shuchkin/simplexlsx

A
Anton, 2018-03-01
@sHinE

I don’t know in what format 1c generates files, but if it’s .xlsx, then it’s a regular zip archive. Open it and dig deeper into the xml, see what is stored there and where.

G
gsur, 2018-03-01
@gsur

While there are .xls .xlsx .xlsb files, Phpexcel just opens .xlsx with this method, but one day the array with the result came empty, having spent a lot of time calculating the moment where the data disappears, I found that the simplexml_load_string line returns "nothing" , I don’t know if it’s possible to dig deeper, opening an “unreadable” file from 1C and its resaved version from MS Excel in a simple text editor (xml from the archive) did not find a difference, but the result of reading the first is empty, the second is in full.

D
desmos, 2020-05-21
@desmos

https://packagist.org/packages/phpoffice/phpspreadsheet

A
Artem Zolin, 2021-08-26
@artzolin

Another option is the SimpleXLSX library . The basic usage is very simple:

if ( $xlsx = SimpleXLSX::parse('book.xlsx') ) {
  print_r( $xlsx->rows() );
} else {
  echo SimpleXLSX::parseError();
}

Another example here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question