{"id":19553403,"url":"https://github.com/digicorp/data-dictionary-with-google-script","last_synced_at":"2025-07-09T03:11:19.573Z","repository":{"id":76078176,"uuid":"83284978","full_name":"digicorp/data-dictionary-with-google-script","owner":"digicorp","description":"This repository contains the end to end solution to create google app script that creates data dictionary in meaningful and deliverable format from google spreadsheet.","archived":false,"fork":false,"pushed_at":"2018-07-07T01:16:04.000Z","size":309,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-26T20:34:05.023Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digicorp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-27T08:09:52.000Z","updated_at":"2025-01-26T00:04:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"3ba88685-6572-418f-a6cf-3507fa7746ee","html_url":"https://github.com/digicorp/data-dictionary-with-google-script","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/digicorp/data-dictionary-with-google-script","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digicorp%2Fdata-dictionary-with-google-script","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digicorp%2Fdata-dictionary-with-google-script/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digicorp%2Fdata-dictionary-with-google-script/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digicorp%2Fdata-dictionary-with-google-script/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digicorp","download_url":"https://codeload.github.com/digicorp/data-dictionary-with-google-script/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digicorp%2Fdata-dictionary-with-google-script/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264384389,"owners_count":23599612,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T04:23:07.532Z","updated_at":"2025-07-09T03:11:19.282Z","avatar_url":"https://github.com/digicorp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Overview\n\nThis repository contains the end to end solution to create google app script that creates data dictionary document from google sheet. The solution solves our product team’s  problem of generating data dictionary in meaningful and deliverable format at [Digicorp](https://www.digi-corp.com) with few clicks. with few clicks. The  tutorial divided into following three sections.\n\n1. [Core Library (Lib.gs)](#core-library)\n2. [Helper Class (Helper.gs)](#helper-class)\n3. [Controller (Controller.gs)](#controller-class)\n\n_[Note : It is assumed that one will have basic knowledge of creating google app script on google spreadsheet. For basic steps you can refer [Google App Script](https://developers.google.com/apps-script/)]_\n\n# Getting Started\n1. [Spreadsheet](https://docs.google.com/spreadsheets/d/1rqK-ZTGejOAVQyNFKyHC1N_otsHTDFqRo30-4lFcML8/edit#gid=0) must have at-least one table described in following image\n2. [Spreadsheet](https://docs.google.com/spreadsheets/d/1rqK-ZTGejOAVQyNFKyHC1N_otsHTDFqRo30-4lFcML8/edit#gid=0) should have sheet called \"Metadata\" to store metadata during execution\n\n![Table Format](https://raw.githubusercontent.com/digicorp/data-dictionary-with-google-script/master/Table%20Format.png)\n\n# Core Library\n\nCore library contains generic functions and methods those are used throughout the solution. These functions are generic and can be used in any google script solution. These are wrapper functions written on top of google app script functions.\n\nFunction Definition\n\nFunction                                      | Type         | Description                                                  | Input                          | Output\n--------------------------------------------- | ------------ | ------------------------------------------------------------ | ------------------------------ | -------------\n[Get Current Spreadsheet Name](#get-current-spreasheet-name)                   | Core Library | Get the current active spreadsheet name             | `spreadsheet`    | `spreadsheetname`\n[Get Sheets](#get-sheets)                   | Core Library | Get all sheets as an array of the specific spreadsheet              | `spreadsheet`    | `sheets`\n[Get Active Sheet](#get-active-sheet)                   | Core Library | Get the active sheet             | `sheetname`    | `sheet`\n[Get Sheet Name](#get-sheet-name)                   | Core Library | Get name of specific sheet             | `sheets`,`index`    | `sheetname`\n[Set Cell Value](#set-cell-value)             | Core Library | Set value in specific cell of sheet                | `sheet`,`row`,`column`,`value` | `-`\n[Get Cell Value](#get-cell-value)             | Core Library | Set value of specific cell of sheet                | `sheet`,`row`,`column`         | `-`\n\n## Get Current Spreadsheet Name\n\n`GetCurrentSpreadSheetName` used to get the name of the specific spreadsheet. it takes `spreadsheet` as input and it returns spreadsheet name as `spreadsheetname`\n\n```javascript\n/**\n * To get the name of current active spreadsheet\n * @param spreadsheet Spreadsheet\n */\nfunction GetCurrentSpreadSheetName(spreadsheet)\n{\n  return spreadsheet.getName();\n}\n```\n\n## Get Sheets\n\n`GetSheets` used to get the all sheets in form of array of specific spreadsheet. it takes `spreadsheet` as input and it returns array of sheets as `sheets`\n\n```javascript\n/**\n * To get sheets of the current active spreadsheet\n * @param spreadsheet Spreadsheet\n */\nfunction GetSheets(spreadsheet)\n{\n  return spreadsheet.getSheets();\n}\n```\n\n## Get Active Sheet\n\n`GetActiveSheet` function used to get the active OR specific sheet of spreadsheet. it takes `sheetname` as input argument. in case if `sheetname` passed as blank string, it returns active sheet, otherwise it return the sheet provided as `sheetname`\n\nWe had need of get instance of Current Sheet and in some cases Specific Sheet. so we created a parameterized function that served purpose. To get the Current Active Sheet we can simply use this function with empty sting ('') and in case to get Specific Sheet we can simply use sheet name.\n\n```javascript\n/**\n * Get active sheet OR Get sheet by name\n * @param sheetname Name of the sheet.\n */\nfunction GetActiveSheet(sheetname) {\n    var sheet;\n\n    if (sheetname == '') {\n        sheet = SpreadsheetApp.getActive().getActiveSheet();\n    } else {\n        sheet = SpreadsheetApp.getActive().getSheetByName(sheetname);\n    }\n    return sheet;\n}\n```\n\n## Get Sheet Name\n\n`GetSheetName` used to get name of the particular sheet from the array of sheets. it takes `sheets` and `index` as input and it returns the name of sheet as `sheetname` from array of sheets for specific `index`.\n\n```javascript\n/**\n * To get name of sheet\n * @param sheets Array of sheets.\n * @param index Index number for item of arrary\n */\nfunction GetSheetName(sheets,index)\n{\n    var sheetname;\n    if (sheets.length\u003e0)\n    {\n       sheetname = sheets[index].getName();\n    }\n    else\n    {\n      sheetname = ''\n    }\n    return sheetname;\n}\n```\n\n## Set Cell Value\n\n`SetCellValue` method used to set the `value` in specific `row` and `column`\n\n```javascript\n/**\n * To set value of a cell\n * @param sheet Sheet contain cell on which value should set.\n * @param row Row on which value should set\n * @param column Column on which value should set\n * @param value Value which should set in cell\n */\nfunction SetCellValue(sheet,row,column,value)\n{\n  sheet.getRange(row, column).setValue(value);\n}\n```\n\n## Get Cell Value\n\n`GetCellValue` function used to get the of value `row` and `column` of specified `sheet`\n\n```javascript\n/**\n * To get value of a cell\n * @param sheet Sheet contain cell of which value should get.\n * @param row Row on which value should get\n * @param column Column on which value should get\n */\nfunction GetCellValue(sheet,row,column)\n{\n  return sheet.getRange(row, column).getValue();\n}\n```\n\n\n# Helper Class\n\nWe have created helper class that contains business logic specific functions and methods which will be called from controller on specific events.\n\nFunction                                | Type         | Description                                                                               | Input                            | Output\n--------------------------------------- | ------------ | ----------------------------------------------------------------------------------------- | -------------------------------- | -------------\n[Create New Document](#create-new-document)                 | Helper Class | Create new google document | `-`                              | `documentid`\n[Get Existing Document](#get-existing-document)                 | Helper Class | Get the existing document| `-`                               | `documentid`\n[Get Document File](#get-document-file)                 | Helper Class | Get the existing document file| `-`                               | `documentfile`\n\n\n## Create New Document\n\n`CreateNewDocument` method used to create new google document with the name same as spreadsheet. once document is created document id is stored in metadata.\n\n```javascript\n/**\n * To create new google document with same name that sheet has\n */\nfunction CreatNewDocument()\n{\n  var sheet = GetActiveSheet(\"Metadata\");\n  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();\n  var documentname = GetCurrentSpreadSheetName(spreadsheet)\n  var document=DocumentApp.create(documentname);\n  var documentid = document.getId();\n  SetCellValue(sheet,1,1,documentid);\n  return documentid;\n}\n```\n\n## Get Existing Document\n\n`GetExistingDocument` method used to get the existing document id from metadata\n\n```javascript\n/**\n * To get existing document\n */\nfunction GetExistingDocument()\n{\n  var sheet = GetActiveSheet(\"Metadata\");\n  var documentid = GetCellValue(sheet,1,1);\n  return documentid;\n}\n```\n\n## Get Document File\n\n`GetDocumentFile` method used to get google document file for the document id stored in metadata.\n\n```javascript\n/**\n * To get existing document file\n */\nfunction GetDocumentFile()\n{\n    var documentid = GetExistingDocument();\n    var documentfile = DriveApp.getFileById(documentid);\n    return documentfile;\n}\n```\n\n# Controller Class\n\nWe have created helper class that contains business logic specific functions and methods which will be called from controller on specific events.\n\nFunction                                | Type         | Description                                                                               | Input                            | Output\n--------------------------------------- | ------------ | ----------------------------------------------------------------------------------------- | -------------------------------- | -------------\n[Create Menu](#create-menu)                 | Controller Class | Create menu with submenu item | `-`                              | `-`\n[Create Data Dictionary](#create-data-dictionary)                 | Controller Class |Create data dictionary| `-`                               | `-`\n[Create Table](#create-table)                 | Controller Class | Create table| `-`                               | `-`\n[Email Data Dictionary](#email-data-dictionary)                 | Controller Class | Send data dictionary as PDF| `-`                               | `-`\n\n\n## Create Menu\n\n`onOpen` method used to create menu with submenu items in spreadsheet.\n\n```javascript\n/**\n * To create menu on google sheet\n */\n function onOpen() {\n      var spreadsheet = SpreadsheetApp.getActive();\n     var menuItems = [{\n         name: 'Generate Dictionary',\n         functionName: 'CreateDataDictionary'\n     },{\n         name: 'Email Document as PDF',\n         functionName: 'EmailDataDictionary'\n     }];\n     spreadsheet.addMenu('Digicorp Data Dictionary', menuItems);\n }\n```\n\n## Create Data Dictionary\n\n`CreateDataDictionary` method used to create data dictionary from spreadsheet. It will check all sheets under specific spreadsheet in specific format and create data dictionary in standard tabular format.\n\n```javascript\n/**\n * To create data dictionary from sheets of spreadsheet\n */\n function CreateDataDictionary()\n {\n   var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();\n   var documentid = GetExistingDocument();\n   if (documentid == '')\n   {\n       documentid = CreatNewDocument()\n   }\n   var body = DocumentApp.openById(documentid).getBody();\n   var sheets = GetSheets(spreadsheet);\n   var sheetscount = sheets.length;\n   body.clear();\n\n   for (count = 0; count\u003csheetscount; count++)\n   {\n     var sheetname = GetSheetName(sheets,count);\n     if (sheetname != \"Metadata\")\n     {\n        var sheet = GetActiveSheet(sheetname);\n        CreateTable(sheet,body);\n     }    \n   }\n\n   Browser.msgBox(\"Data dictionary is generated.\");\n   var to =  Browser.inputBox(\"TO\", \"Please Enter Email Address\", Browser.Buttons.OK_CANCEL);\n\n   if (to!=\"cancel\")\n   {\n        var sheet = GetActiveSheet(\"Metadata\");\n        SetCellValue(sheet,1,2,to);\n        Browser.msgBox(\"Thank you. Please click on 'Email Document as PDF' to get data dictionary.\");\n   }\n }\n```\n\n## Create Table\n\n`CreateTable` method used to create tables for database table and its sample values with defined format.\n\n```javascript\n/**\n * To create table on google document with pre-defined format\n */\n function CreateTable(sheet,body) {\n\n     //Style for header text\n     var headerStyle = {};\n     headerStyle[DocumentApp.Attribute.BACKGROUND_COLOR] = '#336600';\n     headerStyle[DocumentApp.Attribute.BOLD] = true;\n     headerStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#FFFFFF';\n\n     //Style for the cells for primary keys\n     var cellStylePK = {};\n     cellStylePK[DocumentApp.Attribute.BOLD] = false;\n     cellStylePK[DocumentApp.Attribute.FOREGROUND_COLOR] = '#000000';\n     cellStylePK[DocumentApp.Attribute.BACKGROUND_COLOR] = '#ff9900';\n\n     //Style for the cells for foriegn keys\n     var cellStyleFK = {};\n     cellStyleFK[DocumentApp.Attribute.BOLD] = false;\n     cellStyleFK[DocumentApp.Attribute.FOREGROUND_COLOR] = '#000000';\n     cellStyleFK[DocumentApp.Attribute.BACKGROUND_COLOR] = '#ffcc99';\n\n     //Style for the cells other than header row\n     var cellStyle = {};\n     cellStyle[DocumentApp.Attribute.BOLD] = false;\n     cellStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#000000';\n\n     var bold = {};\n     bold[DocumentApp.Attribute.BOLD] = true;\n     bold[DocumentApp.Attribute.ITALIC] = false;\n\n     var italic = {};\n     italic[DocumentApp.Attribute.BOLD] = false;\n     italic[DocumentApp.Attribute.ITALIC] = true;\n\n     var normal = {};\n     normal[DocumentApp.Attribute.BOLD] = false;\n     normal[DocumentApp.Attribute.ITALIC] = false;\n\n     body.appendParagraph(GetCellValue(sheet,1,1)).setAttributes(bold);\n     body.appendParagraph(GetCellValue(sheet,1,2)).setAttributes(italic);\n     body.appendParagraph(\"\");\n\n     body.appendParagraph(GetCellValue(sheet,2,1)).setAttributes(bold);\n     body.appendParagraph(GetCellValue(sheet,2,2)).setAttributes(italic);\n     body.appendParagraph(\"\");\n     body.appendParagraph(\"Dictionary\").setAttributes(bold);\n     body.appendHorizontalRule();\n\n\n     var table = body.appendTable();   \n     for(var i=1; i\u003c=sheet.getLastColumn(); i++){\n     var tr = table.appendTableRow();\n\n     for(var j=3; j\u003c=6; j++){\n       var td = tr.appendTableCell(GetCellValue(sheet,j,i));\n       if(i == 1) td.setAttributes(headerStyle);\n       else if (GetCellValue(sheet,7,i) ==\"YES\") td.setAttributes(cellStylePK);\n       else if (GetCellValue(sheet,8,i) ==\"YES\") td.setAttributes(cellStyleFK);\n       else td.setAttributes(cellStyle);\n\n     }\n   }\n\n   body.appendPageBreak()\n   body.appendParagraph(\"Sample Values\");\n   body.appendHorizontalRule()\n\n   var values = body.appendTable();\n   for(var j=1; j\u003c=sheet.getLastColumn(); j++)\n   {\n       var tr = values.appendTableRow();\n       var td = tr.appendTableCell(GetCellValue(sheet,3,j)).setAttributes(normal);\n\n       for(var i=1; i\u003c=sheet.getLastRow(); i++)\n       {\n       if (GetCellValue(sheet,i,1)==\"Value\")\n       {\n         td = tr.appendTableCell(GetCellValue(sheet,i,j)).setAttributes(normal);\n       }\n       }\n   }\n     body.appendPageBreak()\n }\n```\n\n## Emal Data Dictionary\n\n`EmailDataDictionary` method used to send email to specific user that stored in metadata in PDF format.\n\n```javascript\n/**\n * To send email data dictionary in PDF format\n */\n function EmailDataDictionary()\n{\n    var documentfile = GetDocumentFile();\n    var content = \"Please find attached PDF containing data dictionary in meaningful format\"\n    var sheet =  GetActiveSheet(\"Metadata\");\n    var toemailaddress = GetCellValue(sheet,1,2);\n    MailApp.sendEmail(toemailaddress, documentfile.getName(),content,{ name: Session.getActiveUser(), attachments: [documentfile.getAs(MimeType.PDF)]});\n    SetCellValue(sheet,1,2,'');\n}\n```\n\n# Summary\n\nOne scripts added to and open google spreadsheet again it will have menu with following submenu displayed below.\n\n![Menus](https://raw.githubusercontent.com/digicorp/data-dictionary-with-google-script/master/Menus.png)\n\n## Generate Dictionary\n\nClick on generate dictionary will execute scripts and prepare google word document in meaningful format based on provided raw data in google spread sheet. On successful creation of data dictionary will ask for email address on which data dictionary needs to be sent\n\n## Email Document as PDF\n\nClick on email document as PDF will convert google document into PDF format and send to specific email address as provided\n\nFollowing will be the output of data dictionary in form of [PDF](https://drive.google.com/file/d/0B7x-HcZjFfTtNFdHWXVfam9ITXIwODBzQ195OUt3SVRYX1pv/view?usp=sharing)\n\n![Data Dictionary Format](https://raw.githubusercontent.com/digicorp/data-dictionary-with-google-script/master/Data%20Dictionary%20Sample%20Image%201.png)\n![Data Dictionary Format](https://raw.githubusercontent.com/digicorp/data-dictionary-with-google-script/master/Data%20Dictionary%20Sample%20Image%202.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigicorp%2Fdata-dictionary-with-google-script","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigicorp%2Fdata-dictionary-with-google-script","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigicorp%2Fdata-dictionary-with-google-script/lists"}