Importing Data from Excel

I have converted csv file to Jason. Trying to copy and paste jason file into a text box in form I have created (as instructions). I get a message “Time for a new text box” but nothing happens when I do!

1 Like

I am following the ‘How to Import and Export Collection Data Using the wix-data API’ Article

Hi!
This just means that import is done and data should be in selected collection. Go to left panel, click on collection and check it

Or data is not displayed there?

It seems like there was too much code - I am copying contact details etc for 400 individuals. have tried copying and pasting less JSON code and it accepts it. However, when I press the ‘import’ button i then get an error message.

So you can try to fill in the collection by chunks. Split csv file on several chunks and feed them one-by-one

So I copied first chunk into text box. This time there was no ‘need a new text box message’. Pressed ‘import’ button. Looked at collection/database page. Still nothing in there. Pressed ‘Preview’, got the following come up in the developer console -

Loading the code for the Form page. To debug this code, open ctvn2.js in Developer Tools.There was an error in your scriptTypeError: e is not a function .

I am not a programmer, so not sure what this means. Any clues?

This for sure means error in your code… But without it i can’t say much) Can you please share everything you wrote in code section?

I am copying and pasting all the code from the page below. Let me know if there is a better way of doing it.

import wixData from ‘wix-data’;
// For full API documentation, including code examples, visit http://wix.to/94BuAAs

$w.onReady(function () {
//TODO: write your page related code here…

});

export function button1_click(event) {export function importButton_onClick(event) {
const items = JSON.parse($w(“#textBox”).value);
const collection = $w(“#collectionInput”).value;

items.forEach( (item) => {
wixData.insert(collection, item)
.then( (results) => {
console.log(Added item: ${JSON.stringify(results)});
} )
.catch( (err) => {
console.log(err);
} );
} );

$w(“#textBox”).value = “”;
}
//Add your code for this event here:
}

error exist in this line:

 export function button1_click(event) {export function importButton_onClick(event) { 

you try to use one export inside of another, this is for sure wrong usage…

Copy and paste this instead of all you have in code section:

import wixData from 'wix-data';

export function importButton_onClick(event) {
  const items = JSON.parse($w("#textBox").value);
  const collection = $w("#collectionInput").value;
 
  items.forEach( (item) => {
    wixData.insert(collection, item)
      .then( (results) => {
        console.log(`Added item: ${JSON.stringify(results)}`);
      } )
      .catch( (err) => {
        console.log(err);
      } );
  } );
 
  $w("#textBox").value = "";
}

and, you need button with id “importButton” - and you should add “onClick” event on it

Hi, I am hoping somebody can help!
I am trying to create the same thing, a page dedicated to uploading data into a database collection from a CSV file.
However, when I click my Import Button nothing happens; no message and the data has not been imported into my database.
I have copied the wix code from the same webpage and there appears to be no errors in my code.
Here is my code;

import wixData from ‘wix-data’;
// For full API documentation, including code examples, visit http://wix.to/94BuAAs

$w.onReady(function () {
//TODO: write your page related code here…

});

export function importButton_onClick() {
const items = JSON.parse($w(“#textBox”).value);
const collection = $w(“#collectionInput”).value;

items.forEach( (item) => {
wixData.insert(collection, item)
.then( (results) => {
console.log(Added item: ${JSON.stringify(results)});
} )
.catch( (err) => {
console.log(err);
} );
} );

$w(“#textBox”).value = “”;
}

I have a collectionInput field and textBox field and my button is called ImportButton

???

Thanks

Sorted. Wasn’t sure what was wrong with it, created a new page with same code and it worked, must have been something to do with the page.