For Export :
Using the Labels Manager for Gmail Add-on
- Install the Labels Manager for Gmail add-on from the Google Workspace Marketplace.
- Open Google Sheets and the add-on's interface.
- Access the export function, then choose the "Export Labels (Light)" option.
- Click on "export labels" to generate a snapshot of your labels, including their names and IDs, in a new Google Sheet.
For Import :
-
Go to Google Apps Script.
-
Create a new project.
-
Paste the following script:
-
Replace the
labels
array with your exported labels (you can copy them from your CSV). -
Click Run → Grant permissions → Labels will be created in Gmail
You can save the exported labels as a CSV file and open it in Notepad++
To add " in the beginning and the end of each line in the CSV file, follow the following instructions:
- Press Ctrl+H to bring up the Find/Replace Dialogue.
- Choose the
Regular expression
option near the bottom of the dialogue.
To add a " at the beginning of each line:
- Type
^
in theFind what
textbox- Type " in the
Replace with
textbox- Place cursor in the first line of the file to ensure all lines are affected
- Click
Replace All
button
To add a ", at the end of each line:
- Type
$
in theFind what
textbox- Type ", in the
Replace with
textbox- Place cursor in the first line of the file to ensure all lines are affected
- Click
Replace All
buttonNow you can simply copy the text and paste it in the above-mentioned script.