-
-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit on how many rows should be inserted. #240
Comments
It would not make sense to limit imports, if you want to import something, the normal thing is to import the whole sheet, also, you can limit the maximum size of the file that is uploaded to the server.. If you really want to limit imports, you can have a global variable that increases and when it reaches a certain amount call an exception, in this case, I advise you to create your own exception: $current_imports= 0;
$limit_imports = 1;
try {
(new FastExcel())->import($file_name, function ($row) use (&$current_imports, $limit_imports) {
if ($current_imports++ >= $limit_imports) throw new \Exception("Maximum imports reached");
//Import
});
} catch (\Throwable $th) {
//Do something
} Another alternative you have, is that the import returns a collection of all the data, you can perform a count to know how many records there are: $results = (new FastExcel())->import($file_name, function($row){
//parse row but don't insert
return $row;
});
//Or
$results = (new FastExcel())->import($file_name);
$count_results = count($results); EDIT: $reader->close(); EDIT2: (new FastExcel())->import($file_name, function ($row) use (&$current_imports, $limit_imports) {
if ($current_imports++ >= $limit_imports) return null;
//Import
}); |
This should be a feature, would you accept a PR? Use case, preview first x lines of file for the purpose of choosing data mapping |
.#248 |
Is it possible to set a limit on how many rows can be imported?
The text was updated successfully, but these errors were encountered: