Here is an example of Office Script code that writes data to Microsoft Excel in OneDrive:
function main(workbook: ExcelScript.Workbook) { // Get the active worksheet let sheet = workbook.getActiveWorksheet(); // Write data to the worksheet sheet.getRange("A1").setValue("Name"); sheet.getRange("B1").setValue("Age"); sheet.getRange("A2").setValue("John"); sheet.getRange("B2").setValue(30); sheet.getRange("A3").setValue("Mary"); sheet.getRange("B3").setValue(25); // Save the workbook to OneDrive workbook.save(); console.log("Data has been written to OneDrive."); }
This code gets the active worksheet in the current workbook, writes some data to the first two columns, and saves the workbook to OneDrive. You can run this code by creating a new script in the Excel Online or Excel for Windows desktop application and pasting it into the script editor. You will need to make sure that you are signed in to your OneDrive account and have the appropriate permissions to save files to it.