Last active
July 16, 2023 13:32
-
-
Save ceaksan/4ff3b4a170514edc28f189c38e99bee6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
const ui = SpreadsheetApp.getUi(); | |
ui.createMenu('View more cell actions') | |
.addItem('Convert table to Markdown', 'convertTableToMarkdown') | |
.addToUi(); | |
} | |
function convertTableToMarkdown() { | |
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
const range = sheet.getDataRange(); | |
const values = range.getValues(); | |
const numRows = range.getNumRows(); | |
const numCols = range.getNumColumns(); | |
const columnNames = sheet.getRange(1, 1, 1, numCols).getValues()[0].map(String); | |
const piiColumns = ['Email_pii', 'Address_pii']; // Replace with your desired column names for array matching | |
let markdownTable = ''; | |
for (let i = 0; i < numRows; i++) { | |
for (let j = 0; j < numCols; j++) { | |
const columnName = columnNames[j]; | |
const isPiiColumn = piiColumns.includes(columnName); | |
if (isPiiColumn) { | |
values[i][j] = '***'; | |
} | |
markdownTable += `|${values[i][j]}`; | |
} | |
markdownTable += '|\n'; | |
if (i === 0) { | |
const horizontalLine = Array.from({ length: numCols }).fill('---').join('|'); | |
markdownTable += `${horizontalLine}|\n`; | |
} | |
} | |
Logger.log(markdownTable); | |
// Show the Markdown table in a dialog box | |
const htmlOutput = HtmlService.createHtmlOutput(`<pre>${markdownTable}</pre>`); | |
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Markdown Table'); | |
} |
Author
ceaksan
commented
Jul 16, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment