ruskid / yii2-csv-importer Goto Github PK
View Code? Open in Web Editor NEWYii2 Excel helper to import csv files to tables
License: GNU General Public License v2.0
Yii2 Excel helper to import csv files to tables
License: GNU General Public License v2.0
Hi,
Is it possible to stop using private functions? I'd like to extend a few of these functions for some custom code but am unable to as everything is private.
Thanks,
bw
I am using MultipleImportStrategy
public function actionUploadCsv() {
$model = new MonitoringCsvForm();
$importer = new CSVImporter();
if (Yii::$app->request->isPost) {
$model->file = UploadedFile::getInstance ( $model, 'file' );
if ($model->file && $model->validate ()) {
$importer->setData ( new CSVReader ( [
'filename' => $model->file->tempName,
'fgetcsvOptions' => [
'delimiter' => ','
]
] ) );
$importer->import ( new MultipleImportStrategy ( [
'tableName' => UsersMonitoring::tableName (),
'configs' => [
[
'attribute' => 'user_id',
'value' => function ($line) {
return $line [0];
}
],
[
'attribute' => 'country',
'value' => function ($line) {
return $line [1];
}
],
[
'attribute' => 'reg_code',
'value' => function ($line) {
return $line [2];
}
],
[
'attribute' => 'start_date',
'value' => function ($line) {
return $line [3];
}
],
[
'attribute' => 'end_date',
'value' => function ($line) {
return $line [4];
}
],
[
'attribute' => 'condition_by_group',
'value' => function ($line) {
return $line [5];
}
],
[
'attribute' => 'comment',
'value' => function ($line) {
return $line [6];
}
]
]
] ) );
// return $this->render('upload-csv', ['model' => $model]);
Yii::$app->session->setFlash ( 'successMessage', Yii::t ( 'main', 'Records have been added' ) );
return $this->redirect ( 'index' );
}
}
return $this->render ( 'upload-csv', [
'model' => $model
] );
}
How can I validate CSV data against my model and show error if rules don't pass?The component loads the whole files into memory.
Then parses the whole result as arrays in memory again.
At the moment there is no easy way to work-around this.
I had to move on an existing project to league/csv to workaround this limitations on an inherited project handling 500k+ row CSV files.
I'm sorry to create an issue for this. Does this extension work with tab delimited files? I'm trying to set the delimiter to'\t
', but I get the error fgetcsv(): delimiter must be a single character
.
Any chance you will implement xls/xlsx import?
Would you please create a release?
Installing your package when ours requires yours, is a PITA.
When you have min stability set to stable
, as one should in their main production repo, you can not install a package that requires yours because it is dev-master
.
- main project
|->my package
\-> your package
So to install my package, I have to manually install yours in the main repo first, to force it to accept it. That completely goes against the point of composer. My package should be able to install it's required dependencies (ie: yours) streamlined with one command.
So please, click "Releases", create a release, and tag it v1.0.0
.
Thanks
I'm trying out this plugin with the following example:
//Import multiple (Fast but not reliable). Will return number of inserted rows
$numberRowsAffected = $importer->import(new MultipleImportStrategy([
'tableName' => VendorSwType::tableName(),
'configs' => [
[
'attribute' => 'name',
'value' => function($line) {
return $line[1];
},
'unique' => true, //Will filter and import unique values only. can by applied for 1+ attributes
]
],
]));
But var_dump of $numberRowsAffected
is 0
.
This line is suspicious. It is unsetting all the lines.
Hi,
i'm using this extension and works great!
Now i need to import a 18MBytes file (>100.000 records) and i get the typical 'Out Of Memory' error:
PHP Fatal Error โ yii\base\ErrorException
Allowed memory size of 268435456 bytes exhausted
In my test webserver i coud increase the php memory limit to 2GB and the file is imported but i can't do this in my production server.
I'm using this code:
`
//Import multiple (Fast but not reliable). Will return number of inserted rows
$numberRowsAffected = $importer->import(new MultipleImportStrategy([
'tableName' => $table,
'configs' => [
[
'attribute' => 'first_attribute',
'value' => function($line) {
.....`
Any help?
Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.