Comments (3)
Hi @JohnHotham,
Thank you for the questions. I'm not quite sure I understand the scenario you're trying to accomplish, but I'll try my best.
First, you can't call a script from another script. You can have your script call multiple functions, like this:
function main(workbook: ExcelScript.Workbook) {
const selectedSheet = workbook.getActiveWorksheet();
for (let i = 0; i < 10; i++) {
for (let j = 0; j <= i; j++) {
highlightCell(selectedSheet.getRangeByIndexes(i, j, 1, 1));
}
}
}
function highlightCell(cell: ExcelScript.Range) {
cell.getFormat().getFill().setColor("yellow");
}
You could also call multiple scripts from Power Automate. This scenario shows a flow that calls multiple scripts on the same workbook (granted, there are intermediate steps in the sample).
As for the filter question, if you want to apply a value-based filter, you'll applyValuesFilter
on the Filter object of the TableColumn. In this example, the filter will only show rows when the value in the Description Rating is "Good" or "Fine".
function main(workbook: ExcelScript.Workbook) {
const coverageWorksheet = workbook.getWorksheet("Coverage");
const coverageTable = coverageWorksheet.getTable("CoverageTable");
const descriptionColumn = coverageTable.getColumnByName("Description Rating");
const descriptionSet = columnToSet(descriptionColumn);
descriptionColumn.getFilter().applyValuesFilter(["Good", "Fine"]);
}
If you want to make a filter that keeps everything except a certain value, you'll need to add every other value to that filter array. In this example, we'll keep every row that doesn't have a description rating of "Poor". We'll use a helper function that converts all the values in a column to a set (effectively turning a 2D-array with duplicates into a 1D-array with unique values).
function main(workbook: ExcelScript.Workbook) {
const coverageWorksheet = workbook.getWorksheet("Coverage");
const coverageTable = coverageWorksheet.getTable("CoverageTable");
const descriptionColumn = coverageTable.getColumnByName("Description Rating");
const descriptionSet = columnToSet(descriptionColumn);
descriptionColumn.getFilter().applyValuesFilter(descriptionSet.filter((value) => {
return value !== "Poor";
}));
}
/**
* Convert a column into a set so it only contains unique values.
*/
function columnToSet(column: ExcelScript.TableColumn): string[] {
const range = column.getRangeBetweenHeaderAndTotal().getValues() as string[][];
const columnSet: string[] = [];
range.forEach((value) => {
if (!columnSet.includes(value[0])) {
columnSet.push(value[0]);
}
});
return columnSet;
}
I hope that helps. Please let me know if I missed the mark.
from office-scripts-docs.
Hi @AlexJerabek
Thanks for the assist, it is appreciated, I'll look at integrating them one at a time and see which works best. However, just looking at them, I'm reckoning the second one is a much closer fit than the others. Bear with me.
from office-scripts-docs.
Sounds good. Please let me know if that helps. If so, I'll work on creating a sample so others can benefit.
from office-scripts-docs.
Related Issues (20)
- I do have the automation tab but my supervisor does not. We couldn't figure out the reason why. Can you help out? HOT 3
- In Excel Typescript / Javascript Add an image from a URL to a workbook code example works with URL images but not the local, how can I fix this? HOT 4
- Finally! Something that gives me a clear example on how to use Power Automate to run a script that works HOT 1
- What Is Microsoft Word Used for in the Workplace? Hereβs 5 Ways
- Add a known limitation for shared scripts HOT 5
- Demo walkthrough doesn't work because Adaptive Card Action no longer exists HOT 4
- This action cannot be recorded and cannot copy as code. HOT 12
- Issue in the sample HOT 5
- Documentation should reflect that refresh is supported for Power BI
- Error: Line 27: Table addRows: This won't work because it would move cells in a table on your worksheet. HOT 8
- Contradicting wording in docs? HOT 7
- The ability to simply update tables in XLSM is often inquired about - is it possible? HOT 1
- 'Open in VSCode' doesn't work HOT 5
- Excel Office Scripting default parameters HOT 8
- Tutorial: Update a spreadsheet from a Power Automate flow need update. HOT 1
- "Run Script" action not available HOT 1
- Run Office Scripts in Excel from buttons page out of date HOT 1
- 'excelonlinebusiness' operation 'GetSingleScript' failed with status code 'BadRequest' "status": 400, "message": "Unable to parse script reference" HOT 3
- Script converting then corrupt XLSX? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from office-scripts-docs.