Skip to content

Commit

Permalink
Updated to v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaikech committed Sep 29, 2022
1 parent 6f7c0e3 commit 2248c48
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ExcelApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
disassembleExcel,
getCommentsAsObject,
getImagesAsObject,
getNamedFunctionsAsObject,
getQuotePrefixCellsAsObject,
getSharedStrings,
getStyleAsObject,
Expand Down Expand Up @@ -85,11 +86,30 @@
getQuotePrefixCells() {
return getQuotePrefixCellsAsObject.call(this);
}

getNamedFunctions() {
return getNamedFunctionsAsObject.call(this);
}
}

ExcelApp.name = "ExcelApp";

// --- end methods
getNamedFunctionsAsObject = function () {
var definedNames, root, xmlObj1;
xmlObj1 = getXmlObj.call(this, "xl/workbook.xml");
root = xmlObj1.getRootElement();
definedNames = root
.getChild("definedNames", root.getNamespace())
.getChildren();
return definedNames.map((e) => {
return {
definedName: e.getAttribute("name").getValue(),
definedFunction: e.getValue(),
};
});
};

getQuotePrefixCellsAsObject = function () {
var checkFilename, quotePrefix, sr, styler, xmlObj1, xmlObj2;
if (this.mainObj.sheetsObj.sheetsObj.hasOwnProperty(this.obj.sheetName)) {
Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The basic method of DocsServiceApp is to directly create and edit the data of Mi
- Insert images in cells of Google Spreadsheet using the image blob.
- Create new Google Spreadsheet by setting the custom header and footer.
- Retrieve cell coordinates of cells with the quote prefix.
- Retrieve named functions.

### [Google Slides](#googleslides)

Expand Down Expand Up @@ -383,6 +384,45 @@ console.log(res);

- I answered this method to [this thread at Stackoverflow](https://stackoverflow.com/a/73616511).

<a name="getnamedfunctions"></a>

### 6. `getNamedFunctions()`

![](images/fig5.png)

This method is for retrieving the named functions from Google Spreadsheet using Google Apps Script.

Recently, the named functions got to be able to be used in Google Spreadsheet. [Ref](https://workspaceupdates.googleblog.com/2022/08/named-functions-google-sheets.html) When several named functions are added, I thought that I wanted to retrieve these functions using a script. But, unfortunately, in the current stage, it seems that there are no built-in methods (SpreadsheetApp and Sheets API) for directly retrieving the named functions. So, I created this method.

#### Sample script

```javascript
const spreadsheetId = "###"; // Google Spreadsheet ID
const res =
DocsServiceApp.openBySpreadsheetId(spreadsheetId).getNamedFunctions();
console.log(res);
```

#### Result

When this script is run to the top sample situation in this section, the following result is obtained.

```json
[
{
"definedName": "CONTAINS",
"definedFunction": "LAMBDA(cell, range, NOT(ISERROR(MATCH(cell,range,0))))"
},
{ "definedName": "SAMPLE1", "definedFunction": "LAMBDA(range, SUM(range))" }
]
```

- Unfortunately, in the current stage, the description of the named function cannot be obtained.

- At XLSX format, the named functions are used as LAMBDA function. If you want to directly use this LAMBDA function, for example, please put a function like =LAMBDA(range, SUM(range))(A1:A5) into a cell. By this, the LAMBDA function can be run. Of course, you can retrieve the function from this result and put it as the named function again.

- I posted this method in my [blog](https://tanaikech.github.io/2022/09/28/retrieving-named-functions-from-google-spreadsheet-using-google-apps-script/).

<a name="googleslides"></a>

## For Google Slides
Expand Down Expand Up @@ -698,4 +738,8 @@ There are no methods yet.

1. Added a new method of [`getQuotePrefixCells()`](#getQuotePrefixCells). This method can detect the cells with the quote prefix cells.

- v1.2.0 (September 29, 2022)

1. Added a new method of [`getNamedFunctions()`](#getnamedfunctions). This method can retrieve the named functions from Google Spreadsheet.

[TOP](#top)
5 changes: 5 additions & 0 deletions SpreadsheetAppp.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@
}
return "Please set sheet name.";
}

getNamedFunctions() {
gToM.call(this);
return new ExcelApp(this.mainObj.blob).getNamedFunctions();
}
}

SpreadsheetAppp.name = "SpreadsheetAppp";
Expand Down
Binary file added images/fig5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2248c48

Please sign in to comment.