PhpSpreadsheet | A pure PHP library for reading and writing spreadsheet files | Data Visualization library
kandi X-RAY | PhpSpreadsheet Summary
kandi X-RAY | PhpSpreadsheet Summary
PhpSpreadsheet is a library written in pure PHP and offers a set of classes that allow you to read and write various spreadsheet file formats such as Excel and LibreOffice Calc.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Get next token
- Write the Theme
- Process token stack .
- Parses the formula into an array .
- Write a value axis .
- Compute Hqr2 - 2
- Write a CRLF rule .
- Apply style from array
- Insert new before a cell .
- Get Shadow presets map
PhpSpreadsheet Key Features
PhpSpreadsheet Examples and Code Snippets
Community Discussions
Trending Discussions on PhpSpreadsheet
QUESTION
I have one .xlsx file containing several worksheets. This .xlsx is generated using the php library phpoffice / phpspreadsheet. What I need to do is extract a specific worksheet from this file and create a new one - a separate .xlsx file.
My PHP code look like this:
...ANSWER
Answered 2022-Apr-15 at 02:28You were close to getting the solution! PhpSpreadsheet allows you to use the clone
keyword on sheet objects and then add them to other spreadsheets. I see you're getting this from an uploaded form so a simple check of the MIME Type is probably a good idea.
QUESTION
I've successfully convert Excel to PDF using this code:
...ANSWER
Answered 2022-Mar-30 at 10:31I think there's no solution for this. So I just reduce the font size. When my data is small, the paper space will be wasted
QUESTION
I'm currently using my app service to process files. I'm uploading Excel files and processing them using PhpSpreadsheet.
Locally, they're going through in less than 90 seconds (laptop, SSD, i7, 16GB RAM). On my app service (small Linux plan), the same file and script, can take upwards of 10 min. This results in the 504 Gateway Timeout error. I then manually confirm data upload in the database.
What would be an alternative to this way of processing files?
Edit #1
By Processing, I mean uploading an Excel file, going through the rows, extracting data and updating a database using PhpSpreadsheet. My current file is 102KB, has 4300 rows, 23 columns and takes around 6 minutes. Locally, only a few seconds.
Example:
...ANSWER
Answered 2022-Mar-26 at 22:13Comments offer some good thoughts on basic options, summarized briefly:
- Use a faster server
- Make your algorithm for parsing your file (whatever it is) faster.
Either may alleviate your problem in the short term. However let's say your algorithm is well-optimized and your server is as fast as you're willing to pay for, both of which may be true for you and are often true in real-world cases. Let's also assume that your file size is somewhat unpredictable, so even when well-optimized and fast, you may need to support outlier cases of larger files that are slow to process.
It sounds like your workflow is (synchronously):
- Client sends HTTP request to server with Excel file
- PHP Server runs file parsing
- Server returns an HTTP 200 (OK) and the parsed file when done. If a request takes > 600 seconds (or whatever the timeout is), it times out and returns a 504.
I would agree with the comments suggesting taking out Step 2 and putting it in background-job processing. This would make your workflow look like:
- Client sends HTTP request to server with Excel file
- Server sends the Excel file to a background job processor ASYNCHRONOUSLY, starting the processing but not waiting for it to finish.
- Server returns an HTTP "201 Created" saying the server has started processing the file.
- Client polls a Job Status endpoint on the server every
n
seconds to check if the job is done
There are a LOT of different ways to do this (the above background processing link details a few Azure-esque ways).
One Azure-centric way I can think of is to use a function app triggered by a queue. In this case, your server could accept an Excel File, persist it somewhere (or your client could upload it directly to Azure Blob Storage), and then adds an entry to your Queue, saying where your file to be processed is. Using a queue trigger, this can then automatically trigger your function app code, which can pull the oldest message from your queue, go and find the file to be processed, process it in as much time as it takes, and then upload the "processed" file back to blob storage for client consumption.
I know less about PHP background job tooling, hence the Azure-ness of the above suggestions, but there are definitely dozens of other ways to do the same basic workflow proposed above, and the benefit of the above is that you can implement it using basically any language you want, the core architecture remains the same.
QUESTION
I have tried to install the package of phpspreadsheet for both way for github and through composer also but I am unable to install In composer i am trying these command :- composer require phpoffice/phpspreadsheet but its not working It's basically show these type of error:- [InvalidArgumentException] Package phpoffice/phpspreadsheet has requirements incompatible with your PHP version, PHP extensions and Composer v ersion: - phpoffice/phpspreadsheet 1.19.0 requires ext-gd * but it is not present. And when i am trying directly for github code its files is not in proper way as the requriement git hub link:- https://github.com/PHPOffice/PhpSpreadsheet
...ANSWER
Answered 2022-Mar-15 at 05:56phpoffice/phpspreadsheet v1.19.0
requires php: ^7.3 || ^8.0
Check your installed PHP version by running this command
php -v
. Make sure it's greater or equal to7.3
.Secondly, make sure that the PHP version declaration in the
composer.json
file is also greater or equal to7.3
. I.e:
QUESTION
I am trying to add a date field into an Excel file without the time portion.
This is my current code:
...ANSWER
Answered 2022-Mar-14 at 17:03Apparently DateTime::createFromFormat()
adds the current time if you don't specify it.
The solution is to add !
in the format to reset all the fields to zero-like values which I got from this comment.
QUESTION
Tell me how to do it, I have a folder with xlsx files, with 2 arguments name and price
The task is that I need to pull out information from all files into one array.
Here is my code
...ANSWER
Answered 2022-Feb-24 at 11:56You are overwriting the array in the inner loop on the second pass
QUESTION
Currently I have a table where I'm displaying all my records. Now I have a functionality to export the table data to an excel sheet. Now when I click export the excel sheet goes to my C:\Xammp\htdocs
folder. The following is the code I'm using to save the excel sheet.
ANSWER
Answered 2022-Jan-26 at 10:32The problem occurs because you are generating the filename twice, and it's time-dependent, so it can be different each time. Define it once in a variable and then use it for both things:
QUESTION
I need to validate every rows from excel user upload in laravel which already converted to numeric array.
The validation i wanted is :
- to make sure that the 1st field (0) is not blank,
- then check whether the input is 'PRODUCTION-PROJECT' or not, if yes, then the 2nd field is required (1).
how to achieve this ?
My Controller Import class
...ANSWER
Answered 2022-Jan-21 at 03:24The params of Rule::requiredIf
should be a callback function that you need to custom the rule and input.
It's better to change Rule::requiredIf('*.0' === 'PRODUCTION-PROJECT')
to 'required_if:*.0,PRODUCTION-PROJECT"'
so the correct code is :
QUESTION
I've been banging my head on this one for a few days and thought it was time to ask. The task seems simple - Use PhpSpreadsheet to write an Excel sheet to a Google Cloud Storage bucket.
Currently my thought is that the file will need to streamed to the bucket. The other option it seems would be generating it the file in memory and then writing it to the bucket which I feel like could be resource intensive.
I'm using App Engine with a Standard environment and PHP 7.4.
To test it out out I've been using the most basic code to make the sheet -
...ANSWER
Answered 2022-Jan-17 at 07:36Here's a working sample code:
QUESTION
i'm using maatwebsite laravel excel to import some data from excel to database. But i want to add some custom ID with incremental value for each row of data. For now, i'm able to import data with some input value form together.
DataImport file
...ANSWER
Answered 2021-Dec-19 at 04:31Counting rows will bring you problems whenever you remove a single record from the table: You won't be able to insert new rows if your primary employee_id
field has UNIQUE key, or you will start inserting duplicated IDs.
Generating the ID in PHP isn't my recomendation either since you could face integrity problems if two records are trying to be stored simultaneously.
I would use the default model's model_id
field with autoincrement to make sure that I won't have problems with id assignation, and inmediatly after saving the record I would update the id for the employee_id
field which can be also keyed as "primary" in order to be indexed and accessed efficiently.
For example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PhpSpreadsheet
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page