Last active
February 16, 2026 23:45
-
-
Save giobel/c4e992607831cb02d6cd21f9d7e217f7 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
| Excel Scripts |
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 main(workbook: ExcelScript.Workbook) { | |
| let selectedSheet = workbook.getActiveWorksheet(); | |
| let rgbRange = selectedSheet.getRange("A1:A6") | |
| let rangeValues = rgbRange.getValues(); | |
| let rangeLength = rangeValues.length; | |
| for (let i=0; i < rangeLength; i++) { | |
| let color = rangeValues[i][0].toString(); | |
| let rgbParts = color.split(' ') | |
| const [r, g, b] = rgbParts; | |
| let targetCell = selectedSheet.getCell(i,0); | |
| let hexcolor = rgbToHex(Number(r), Number(g),Number(b)); | |
| targetCell.getFormat().getFill().setColor(hexcolor); | |
| } | |
| } | |
| function rgbToHex(r:number, g:number, b:number) { | |
| return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase(); | |
| } |
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
| Sub ColorCells() | |
| Dim ws As Worksheet | |
| Dim rgbRange As Range | |
| Dim rangeValues As Variant | |
| Dim i As Long | |
| Dim rgbParts As Variant | |
| Dim r As Integer, g As Integer, b As Integer | |
| Dim targetCell As Range | |
| Dim colorRow As Variant | |
| colorRow = Array("E", "G", "I", "K", "M") | |
| endRow = 250 | |
| ' Set the active worksheet | |
| Set ws = ThisWorkbook.ActiveSheet | |
| ' Define the range of RGB values | |
| ' Set rgbRange = ws.Range("E2 :E222") | |
| For j = LBound(colorRow) To UBound(colorRow) | |
| Set rgbRange = ws.Range(Cells(2, colorRow(j)), Cells(endRow, colorRow(j))) | |
| ' Get the values from the RGB range | |
| rangeValues = rgbRange.Value | |
| ' Loop through the RGB values | |
| For i = 1 To UBound(rangeValues, 1) ' VBA arrays are 1-based | |
| ' Get the RGB value from the cell | |
| Dim color As String | |
| color = CStr(rangeValues(i, 1)) | |
| ' Split the RGB value into its parts | |
| rgbParts = Split(color, " ") | |
| If UBound(rgbParts) = 2 Then ' Ensure there are exactly 3 parts | |
| r = CInt(rgbParts(0)) | |
| g = CInt(rgbParts(1)) | |
| b = CInt(rgbParts(2)) | |
| ' Define the target cell in the same row | |
| Set targetCell = ws.Cells(i + 1, colorRow(j)) | |
| ' Set the background color using RGB | |
| targetCell.Interior.color = RGB(r, g, b) | |
| End If | |
| Next i | |
| Next j | |
| End Sub |
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
| interface ReviztoProject { | |
| id: number; | |
| uuid: string; | |
| title: string; | |
| } | |
| interface ReviztoDataContainer { | |
| data: ReviztoProject[]; // This is the inner array | |
| total_count?: number; | |
| } | |
| interface ReviztoResponse { | |
| result: number; | |
| data: ReviztoDataContainer | null; | |
| message: string; | |
| } | |
| async function main(workbook: ExcelScript.Workbook) { | |
| // Sheets | |
| let sheet = workbook.getWorksheet("Revizto"); | |
| let sheetProjects = workbook.getWorksheet("Projects"); | |
| // Clear Projects table | |
| sheetProjects.getRange("A:C").clear(); | |
| // Retrieve Access Token (example: stored in B2) | |
| let userAccessToken = sheet.getRange("A3").getValue() as string; | |
| let serverName = sheet.getRange("H1").getValue() as string; | |
| let licenseName = sheet.getRange("H2").getValue() as string; | |
| let licenseUUID = sheet.getRange("I2").getValue() as string; | |
| let apiUrl = `https://api.${serverName}.revizto.com/v5/project/list/${licenseUUID}/paged`; | |
| console.log(apiUrl); | |
| try { | |
| const response = await fetch(apiUrl, { | |
| method: "GET", | |
| headers: { | |
| "Authorization": `Bearer ${userAccessToken}`, | |
| "Content-Type": "application/json" | |
| } | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| // Cast to our new unique interface | |
| const responseData: ReviztoResponse = await response.json() as ReviztoResponse; | |
| const projectList = responseData?.data?.data; | |
| if (responseData?.result === 0 && Array.isArray(projectList)) { | |
| // Transform data into a 2D array for Excel [[id, uuid, title], ...] | |
| const excelData = projectList.map(p => [p.id, p.uuid, p.title]); | |
| if (excelData.length > 0) { | |
| // Bulk write to Excel (A1 to C + number of rows) | |
| const targetRange = sheetProjects.getRange(`A2:C${excelData.length+1}`); | |
| targetRange.setValues(excelData); | |
| } else { | |
| console.log("No projects found in the list."); | |
| } | |
| } else { | |
| console.log("API Error:", response ?? "Invalid response format"); | |
| } | |
| } catch (error) { | |
| console.log("Error: Unable to refresh projects."); | |
| console.log(error); | |
| return; | |
| } | |
| } |
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
| interface ReviztoSheetEntity { | |
| sheetLink: string; | |
| externalUuid: string; | |
| title: string; | |
| } | |
| interface ReviztoSheetResponse { | |
| result: number; | |
| data: { | |
| entities: ReviztoSheetEntity[]; | |
| } | null; | |
| message: string; | |
| } | |
| async function main(workbook: ExcelScript.Workbook) { | |
| const sheet = workbook.getWorksheet("Revizto"); | |
| let targetSheet = workbook.getWorksheet("Sheets"); | |
| // Safety check: Create the sheet if it doesn't exist | |
| if (!targetSheet) { | |
| targetSheet = workbook.addWorksheet("Sheets"); | |
| } | |
| const access_token = sheet.getRange("A3").getValue() as string; | |
| const serverName = sheet.getRange("H1").getValue() as string; | |
| const projectUuid = sheet.getRange("H3").getValue() as string; | |
| const apiUrl = `https://api.${serverName}.revizto.com/v5/project/${projectUuid}/sheet/list`; | |
| try { | |
| console.log("Fetching sheets for project..."); | |
| const response = await fetch(apiUrl, { | |
| method: "POST", | |
| headers: { | |
| "Authorization": `Bearer ${access_token}`, | |
| "Accept": "application/json", | |
| "Content-Type": "application/json" | |
| } | |
| }); | |
| if (!response.ok) throw new Error(`HTTP Error: ${response.status}`); | |
| const responseData: ReviztoSheetResponse = await response.json() as ReviztoSheetResponse; | |
| // Use optional chaining for safety | |
| const entities = responseData?.data?.entities; | |
| if (responseData.result === 0 && Array.isArray(entities)) { | |
| console.log(`Found ${entities.length} sheets.`); | |
| // 1. Clear old data safely (only if range exists) | |
| const usedRange = targetSheet.getUsedRange(); | |
| if (usedRange) { | |
| usedRange.clear(); | |
| } | |
| // 2. Set Headers | |
| targetSheet.getRange("A1:C1").setValues([["Title", "External UUID", "Sheet Link"]]); | |
| targetSheet.getRange("A1:C1").getFormat().getFont().setBold(true); | |
| // 3. Prepare and write data | |
| if (entities.length > 0) { | |
| const excelData = entities.map(e => [ | |
| e.title || "N/A", | |
| e.externalUuid || "N/A", | |
| e.sheetLink || "N/A" | |
| ]); | |
| // Write to range starting at A2 | |
| targetSheet.getRange(`A2:C${excelData.length + 1}`).setValues(excelData); | |
| // Final formatting | |
| targetSheet.getUsedRange().getFormat().autofitColumns(); | |
| } | |
| console.log("Sheet update complete."); | |
| } else { | |
| console.log("API Error: " + (responseData?.message ?? "Invalid response structure")); | |
| } | |
| } catch (error) { | |
| console.log("Error: " + error); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment