Import from CSV

Thank you for your fast answer. I will try it with the script. It is no Problem about HTML converting to Markdown. There are a lot of possiblities to do that. My content will be of course in Markdown.

@texnixe, I’ve been using your import plugin for a number of projects, but I never used it to import users. How could I use the plugin for creating new user accounts? I suppose it’s also worth noting that I’ve created a new user role (member) and it has some custom fields. Any insight would be greatly appreciated.

There is a hidden createUser method, but currently it is quite limited and doesn’t care about roles or custom fields, I‘m afraid.

Gotcha. Thanks for the reply.

Hi,
thank you guys for this really helpful discussion here.

I am trying to create pages from CSV data with the wonderful kirby-csv-handler by @texnixe.
But I am always running into this problem:

The first col of my CSV dataset is called Title. The page uri should be created from this, so I put it into my config:
c::set('csv-handler.page.uid', 'Title');

When I hit the handler url in the browser to import the CSV as subpages, it says: “The index does not exists”. But this is only the case for the Title col. When I use one of the other col names, everything works just fine.

Do you have any ideas to solve this?

@frederik Have you checked that your spelling is correct? Uppercase/lowercase? Is the delimiter set correctly?

Hi @texnixe,
yes, I copied the col name from the CSV file to be sure. I also changed the delimiter from comma to semicolon and back again.

At the moment, the “Title“ col is the first col. When I change the cols and make “Title” the second col, everything works. I checkd this, because I was wondering if the col name “Title” is the problem …

That shouldn’t be the problem, I have a test file here with a title column in the first place and it works without problems. Could you send me the file for testing?

@frederik Where in the world are you? What operating system are you on? How are you saving the data? With Excel? I spent an afternoon a while back getting frustrated with CSV and it turned out not to be a problem with the CSV plugin, but rather the CSV itself. How you save it in Excel matters (there are two options for CSV when you save it) and the locale settings of your computer matters.

From what I remember, on a mac, Excel gets its locale from the operating system. Excel on windows allows you to set the locale from within Excel, independent of the operating system.

After hours of head scratching, the only way I could get the data in was to set my computers location to Germany and the deliminator for the plugin to a semicolon. The issue seemed to because here in the UK we use a comma for numbering and currency (1,000) it was confusing the delimination.

Maybe thats useful to you.

@jimbobrjames We are currently trying to sort this out in private conversation. It seems to be a file encoding issue. The problem is not the file contents nor the delimination.

@jimbobrjames Thanks for sharing!

@texnixe made some tests with files from me and now the problem seems quite clear.

What I want to do is to take some airtable.com sheets, export them (CSV only) and then put the rows as subpages into my Kirby installation.

So far we are assuming that the CSV encoding from Airtable is causing the problem. When I copy the content of the original files (from Airtable) into new CSV files, save and trigger the handler, everything is fine!

I don’t understand @texnixe plugin (where I need to create an object ?) — but I understand the bash from @steenweg :slight_smile:
May be just php script could be usefull to deal with first line ?
Tips : check the content of your excel and remove “ ; ” before export in CSV (Numbers.app is stupid) :):neutral_face:

Hello I’m trying to populate a structure field from a CSV and a panel hook. I didn’t manage to get it. Any help please?

Here is my code

'hooks' => [
        'file.create:after' => function ($file) {
           if ($file->template() == "csvfile") {
           		$page = $file->parent();
           		
           		$openFile = fopen($file->url(), "r");
           		$fileData = [];
           		while (($row = fgetcsv($openFile, 1000, ";")) !== FALSE) 
				{
					$fileData[] = $row;
				}
				$fileData = yaml::encode($fileData);
           		$page->update([
				    'seleccionado' => $fileData,
				]);
           }
        }
    ],

Maybe this helps: https://getkirby.com/docs/guide/virtual-pages/content-from-csv#reading-from-the-csv

Error Class ‘SonjaBroda\CsvHandler’ not found

what am i doing wrong? i followed every step. is this solution outdated?

What are you trying to do? Which plugin, which Kirby version?

hey texnixe :slight_smile:

im using the latest kirby version. im trying to work with your CsvHandler.

but the kirby debuger gives me this message: “Error Class ‘SonjaBroda\CsvHandler’ not found”
when i past in the example codelines you provided in this forum.

This plugin GitHub - texnixe/kirby-csv-handler: This plugin provides a class to handle .csv files in your templates and methods to create pages and structure entries from a .csv file. has been archived, it was developed for Kirby 2 and is not compatible with Kirby 3.

As mentioned above, you can use the csv() function in the virtual pages guide to read data from a csv file and then do with this data whatever you need to do.

1 Like