StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Rob  
#1 Posted : Tuesday, May 30, 2023 12:36:34 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,359
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 419 time(s) in 356 post(s)
)from Discord user request)

Read ODS spreadsheet, select random row value from a column, display value, and send the value as keyboard input to activate application.

Code:
// Set variables

// Download from https://github.com/SheetJS/sheetjs/blob/github/dist/xlsx.full.min.js
var sheetsJSFile = "D:/Temp/xlsx.full.min.js"; 
// Change to your file path/name
var workbookFile = "D:/Temp/Book1.ods";

var columnNumber = 0;         // Use first column (A)
var startRow     = 1;         // Row to start random selection
                              // use 0 for entire column
                              // use 1 to skip header row
var sheetName    = "Sheet1";  // Name of worksheet

//Load sheetsjs into script engine
eval(System.IO.File.ReadAllText(sheetsJSFile));

//Load workbook from file
var wb = XLSX.read(
    new Uint8Array(System.IO.File.ReadAllBytes(workbookFile)), 
    { type: 'array', raw: true, cellFormula: false }
);

//Get worksheet
var ws = wb.Sheets[sheetName];
//Get cell ranges
var cellRanges = XLSX.utils.decode_range(ws['!ref']);

var randomRow = Math.floor(Math.random() * cellRanges.e.r) + startRow;

//Create cell reference for columna and randomRow
var cellRef = XLSX.utils.encode_cell({c:columnNumber, r:randomRow});

//Get cell
var cell = ws[cellRef];

//Show value from cell
var info = new DisplayTextInfo();
info.Title = "";
info.Message = cell.v; // Cell value 
info.Duration = 1000; //1 second
info.Location = sp.GetCurrentMousePoint().X + ',' + sp.GetCurrentMousePoint().Y;
info.MessageFont = new Font("Segoe UI Semibold", 10);
info.BackColor = "black";
info.Padding = 0;
info.ClipToWorkingArea = false;
sp.DisplayText(info);

//Slight pause
sp.Sleep(100); 

//Send cell value as string to active window
sp.SendUnicodeString(cell.v);
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.