Files
hpos-data/scripts/card_print_1.js
2024-01-15 21:00:33 +05:30

44 lines
1.6 KiB
JavaScript

function main(workbook: ExcelScript.Workbook) {
let selectedCell = workbook.getActiveCell();
let selectedSheet = workbook.getActiveWorksheet();
// Set fill colour to yellow for the selected cell.
selectedCell.getFormat().getFill().setColor("yellow");
// Get the hyperlink of the active cell.
let hyperlink = selectedCell.getHyperlink();
// Print the hyperlink in the console.
// console.log("Hyperlink: " + JSON.stringify(hyperlink.address));
// Check if there is a selected cell.
if (selectedCell) {
// Get the column index of the selected cell.
let selectedColumnIndex = selectedCell.getColumnIndex();
// Get the active sheet.
let selectedSheet = workbook.getActiveWorksheet();
// Get the number of rows in the sheet.
let rowCount = 10932;
// Iterate through each row and copy the value from the selected column to a new column.
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
// Get the value from the selected column.
let cellValue = selectedSheet.getCell(rowIndex, selectedColumnIndex).getHyperlink()?.address;
// Assume the new column is next to the selected column. You can adjust the index as needed.
let newColumnIndex = selectedColumnIndex + 1;
// Set the value in the new column.
selectedSheet.getCell(rowIndex, newColumnIndex).setValue(cellValue);
}
console.log("New column created with values from the selected column.");
} else {
console.log("No cell selected.");
}
}