Page 1 of 1

Generate an id for imported data (Excel)

Posted: Sun Dec 13, 2015 11:45 am
by leven.steve
I was hoping that importing data would auto-generate/increment the ID column but it doesn't (unless I'm mistaken?)

So I wrote this function in Excel VBA to generate a random string for the "id".

Usage: (in Excel column)
=MakeApperyID(24)

Function MakeApperyID(length As Integer) As String
' create a id string of "length" chars using 0-9 and a-f only
' in keeping with Appery DB _id format you could call this
' with length 4 to create a starting 4 char sequence in a fixed cell location
' and then add that to a length 20 call to create the remainder of the ID

Dim Result
Dim i, j, k
Dim ch

Randomize (Now)
Result = ""
For i = 1 To length
k = CInt(Rnd()) 'zero or one to decide on letter or number
If k = 0 Then
j = CInt(Rnd() * 5)
ch = Chr(j + 97)
Else
j = CInt(Rnd() * 9)
ch = Chr(j + 48)
End If
Result = Result + ch
Next
MakeApperyID = Result
End Function

Feel free to use, amend and feedback any useful changes.

Re: Generate an id for imported data (Excel)

Posted: Fri Oct 23, 2020 4:25 pm
by Serhii Kulibaba

Hello,

Appery.io uses mongoDB, which has another way to generate IDs, so it doesn't increment the ID in the database.