1

I am trying to create a "check in - check out" form to register the time in and out of workers at a company, using Excel for Web (ExcelScript). For every worker in the form, there has to be in the adjacent rows a Check IN and a Check OUT button that will stamp in the cell underneath the button the current time, and delete the button, as it was usually done with VBA macros.

In understand that buttons cannot be used from the javascript API but this answer has an interesting workaround using event worksheet.onSingleClicked() so the user would click on a cell that looks like a button, and it will call a function to stamp the current time and remove all button formatting.

The Excel Javascript API docs has the worksheet.onSingleClicked() or onChanged(), but I cannot find anything similar on the ExcelScript docs, which I understand is the only API that can run on Excel for Web.

Is there any way to create user interactable buttons in a for loop, or to register events (like onSingleClicked() or onChanged()) to be used in Excel for Web?

Thanks

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Wolfeius
  • 303
  • 2
  • 14
  • Excel for the web uses the Office Scripts API. Office Scripts were updated to have buttons late last year. As of last month they should now be available to everyone with a corporate account. You can see more details on that here: https://techcommunity.microsoft.com/t5/excel-blog/announcing-buttons-for-office-scripts-run-scripts-with-a/ba-p/2917021 – Brian Gonzalez Mar 11 '22 at 22:48
  • Yes, I am aware of that, but can I instance a couple hundred of those with javascript? Or do I have to add each one manually? – Wolfeius Mar 11 '22 at 23:02
  • 1
    I'm not sure, but I'd imagine that you would have to add manually. You can try to make your posts of the Office Scripts page on StackOverflow. I believe some members of the Office Scripts team monitor that page. Or perhaps just update the tags in this post to include the office-scripts tag. – Brian Gonzalez Mar 11 '22 at 23:29

2 Answers2

1

You need to add manually. New Office scripts are quite limited nowadays. But you may post a feature request for the team.

Feature requests on Tech Community are considered, when the dev team go through the planning process. Use the github label: “Type: product feature request” at https://aka.ms/M365dev-suggestions .

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Thank you for your answer. Do you believe I could have this funcionality with office.js by writting an Add-In? Would that work on web-desktop-mobile? – Wolfeius Mar 13 '22 at 21:50
  • 1
    Yes, you can add ribbon commands, see [Add-in commands for Excel, PowerPoint, and Word](https://learn.microsoft.com/en-us/office/dev/add-ins/design/add-in-commands) for more information. – Eugene Astafiev Mar 14 '22 at 07:25
0

You can use the Excel Javascript API in Excel Online without writing an add-in from scratch. So you could us the trick you mention that formats a cell to look like a button, which I wrote. It requires the JADE addin, which works on Mac Windows and Online platforms and is free. It does not yet work for mobile versions, but you can run the Online version on most (all?) mobile platforms.

Using JADE, you could either format the cells to look like buttons on the sheet or have the code render a list of employees with actuall check-in / check-out buttons in the addin panel.

I'd be glad to write and example of either approach, but it probably should be in response to a questions specifically about how to do this with the JADE add-in. If you want such an example, post another question and link to in a comment to this answer and I'll write the example(s).

Discalimer: I wrote the JADE add-in.

Gove
  • 1,745
  • 10
  • 11