### Get Connector Start Connection Site Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/ConnectorFormat/%E5%B1%9E%E6%80%A7/BeginConnectionSite%20%E5%B1%9E%E6%80%A7.html This example shows how to retrieve and log the connection site of the starting point for the third shape (assumed to be a connector) on the active worksheet. ```javascript /*本示例显示活动工作表中第三个形状(连接符)的起点所连接的连接结点的位置。*/ function test() { let shapes = ActiveSheet.Shapes let shape = shapes.Item(3) console.log(shape.ConnectorFormat.BeginConnectionSite) } ``` -------------------------------- ### Group Method - With All Parameters Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Range/%E6%96%B9%E6%B3%95/Group%20%E6%96%B9%E6%B3%95.html This example illustrates using the Group method with all its optional parameters: Start, End, By, and Periods. ```APIDOC ## Range.Group(Start, End, By, Periods) ### Description Groups data within a PivotTable field based on numbers or dates, utilizing all optional parameters for precise control over the grouping. ### Method Group(Start, End, By, Periods) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters - **Start** (any) - Optional - The first value to group by. If omitted or True, the first value in the field is used. - **End** (any) - Optional - The last value to group by. If omitted or True, the last value in the field is used. - **By** (any) - Optional - If the field is numeric, this parameter specifies the size of each group. If the field is a date and element 4 of the _Periods_ array is True while all others are False, this parameter specifies the number of days in each group. Otherwise, this parameter is ignored. If omitted, ET automatically selects a default group size. - **Periods** (any) - Optional - An array of **Boolean** values specifying the periods for grouping. If an element in the array is True, grouping is created for the corresponding time; if False, no group is created. This parameter is ignored if the field is not a date field. ### Request Example ```javascript /*This example groups the C1:G10 cell range, with the first value being cell E1 and the last value being cell F1, and specifies grouping by days (element 4 of Periods is True)*/ function test() { Range("C1:G10").Group(Range("E1"), Range("F1"), null, [false, false, false, true, false, false, false]) // Example for grouping by days } ``` ### Response Returns a Variant. #### Success Response Not explicitly defined, but the operation performs grouping. #### Response Example Not applicable (SDK method) ``` -------------------------------- ### Find Substring with Starting Position Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/WorksheetFunction/%E6%96%B9%E6%B3%95/Find%20%E6%96%B9%E6%B3%95.html This example demonstrates how to use the Find method to locate the starting position of a substring within another string, with an optional starting position for the search. The results are logged to the console. ```javascript /*本示例分别赋值B1等单元格,使用 Find 方法查找参数1字符串开始的位置。*/ function test() { Range("B1").Value2 = "World" Range("B2").Value2 = "hello,World!" Range("B3").Value2 = 4 console.log(WorksheetFunction.Find(Range("B1").Value2, Range("B2").Value2, Range("B3").Value2)) } ``` -------------------------------- ### Group Method - With Start and End Values Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Range/%E6%96%B9%E6%B3%95/Group%20%E6%96%B9%E6%B3%95.html This example shows how to use the Group method with specified start and end values for the grouping operation. ```APIDOC ## Range.Group(Start, End) ### Description Groups data within a PivotTable field based on numbers or dates, with specified start and end values for the grouping. ### Method Group(Start, End) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters - **Start** (any) - Optional - The first value to group by. If omitted or True, the first value in the field is used. - **End** (any) - Optional - The last value to group by. If omitted or True, the last value in the field is used. ### Request Example ```javascript /*This example groups the C1:G10 cell range, with the first value being cell E1 and the last value being cell F1*/ function test() { Range("C1:G10").Group(Range("E1"), Range("F1")) } ``` ### Response Returns a Variant. #### Success Response Not explicitly defined, but the operation performs grouping. #### Response Example Not applicable (SDK method) ``` -------------------------------- ### Set Connector Start Point to Existing Site Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/ConnectorFormat/%E5%B1%9E%E6%80%A7/BeginConnectionSite%20%E5%B1%9E%E6%80%A7.html This example demonstrates how to set the starting connection site of a new connector to match an existing connector's starting point. It assumes a worksheet with two shapes connected by a connector named 'Conn1To2'. The code adds a new shape and a new connector, then configures the new connector to start at the same site as 'Conn1To2' and end at the new shape. ```javascript /*此示例假定第一张工作表已包含由名为 Conn1To2 的连接符附加的两个形状。本示例的代码将向第一张工作表添加一个矩形和一个连接符。新连接符起点的连接位置与原来名为 Conn1To2 的连接符起点的连接位置相同,而新连接符的终点会连接到新矩形的第一个连接位置上。*/ function test() { let worksheet = Application.Worksheets.Item(1) let shapes = worksheet.Shapes let shape = shapes.AddShape(msoShapeRectangle, 450, 190, 200, 100) shapes.AddConnector(msoConnectorCurve, 0, 0, 10, 10).Name = "Conn1To3" let connFormat1 = shapes.Item("Conn1To2").ConnectorFormat let beginConnSite1 = connFormat1.BeginConnectionSite let beginConnShape1 = connFormat1.BeginConnectedShape let connFormat2 = shapes.Item("Conn1To3").ConnectorFormat connFormat2.BeginConnect(beginConnShape1, beginConnSite1) connFormat2.EndConnect(shape, 1) } ``` -------------------------------- ### Defining a Range using Start and End Cells Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Range/Range%20%E5%AF%B9%E8%B1%A1.html This example demonstrates how to define a range (A1:J10) by specifying the starting and ending cells and then setting the border style for that range. ```APIDOC ## Defining a Range using Start and End Cells ### Description This example demonstrates how to define a range (A1:J10) by specifying the starting and ending cells and then setting the border style for that range. Note the preceding periods before each Cells property, indicating the cells are on Worksheet 1. ### Method JavaScript (AirScript) ### Endpoint N/A (SDK Method) ### Parameters N/A ### Request Example ```javascript /*本示例设置单元格 A1:J10 的边框线条样式*/ function test() { Application.Worksheets.Item(1).Range(Worksheets.Item(1).Cells.Item(1, 1), Application.Worksheets.Item(1).Cells.Item(10, 10)).Borders.LineStyle = xlThick } ``` ### Response N/A ``` -------------------------------- ### FindB Method - Basic Usage Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/WorksheetFunction/%E6%96%B9%E6%B3%95/FindB%20%E6%96%B9%E6%B3%95.html This example demonstrates the basic usage of the FindB method by assigning values to cells and then using FindB to find the starting position of a substring within a larger string, starting from a specified position. ```javascript /*本示例分别赋值A1等单元格,使用 FindB 方法查找参数1字符串开始的位置。*/ function test() { Range("A1").Value2 = "wps" Range("A2").Value2 = "hello, wps!" Range("A3").Value2 = 2 console.log(WorksheetFunction.FindB(Range("A1").Value2, Range("A2").Value2, Range("A3").Value2)) } ``` -------------------------------- ### Using Search with a Starting Position and Console Output Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/WorksheetFunction/%E6%96%B9%E6%B3%95/Search%20%E6%96%B9%E6%B3%95.html This example assigns a string to cell B1 and a search character to cell C1. It then uses the Search method to find the character within the string, starting from the 9th position, and logs the result to the console. ```javascript /*本示例为B1等单元格赋值,使用 Search 方法计算第一个文本字符串从第二个文本字符串的第一个字符开始位置的编号。*/ function test() { Range("B1").Value2 = "Where are you from?" Range("c1").Value2 = "r" console.log(WorksheetFunction.Search(Range("C1").Value2, Range("B1").Value2, 9)) } ``` -------------------------------- ### Create New Files Source: https://airsheet.wps.cn/docs/apiV2/advanced/KSDrive.html Examples of creating new files of different types (ET, DB, KSheet, AP) and saving them with specified names and locations. ```javascript // Create an ET file, specifying the save location let url = KSDrive.createFile(KSDrive.FileType.ET, { name: 'et测试', dirUrl: '指定保存位置' }) console.log(url) // Create a new DB file url = KSDrive.createFile(KSDrive.FileType.DB) console.log(url) // Create a new KSheet file url = KSDrive.createFile(KSDrive.FileType.KSheet) console.log(url) // Create a new AP file url = KSDrive.createFile(KSDrive.FileType.AP) console.log(url) ``` -------------------------------- ### Get Default Slicer Style Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Workbook/%E5%B1%9E%E6%80%A7/DefaultSlicerStyle%20%E5%B1%9E%E6%80%A7.html This example demonstrates how to retrieve the current default slicer style of the active workbook. No setup is required beyond having an active workbook. ```javascript /*本示例演示活动工作簿切片器默认样式*/ function test() { console.log(ActiveWorkbook.DefaultSlicerStyle) } ``` -------------------------------- ### List and Open Files by Extension Source: https://airsheet.wps.cn/docs/apiV2/advanced/KSDrive.html Shows how to list files with specific extensions (ET, KSheet) from your cloud drive and then open the first file in the list. ```javascript // Get a list of et, ksheet documents under my cloud drive const fileList = KSDrive.listFiles({ includeExts: ['et', 'ksheet'] }) // Open the first document in the directory of my cloud drive file = KSDrive.openFile(fileList.files[0]) console.log(file.Application.Range('A1').Text) // Close the document ``` -------------------------------- ### Get IndentLevel of a Cell Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/DisplayFormat/%E5%B1%9E%E6%80%A7/IndentLevel%20%E5%B1%9E%E6%80%A7.html This example shows how to get the IndentLevel of cell E3. ```javascript /*本示例显示 E3 单元格的缩进级别。*/ function test() { console.log(Range("E3").DisplayFormat.IndentLevel) } ``` -------------------------------- ### LogInv Method Usage Example 1 Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/WorksheetFunction/%E6%96%B9%E6%B3%95/LogInv%20%E6%96%B9%E6%B3%95.html This example demonstrates the LogInv method to analyze data with a logarithmic distribution, assigning values to cells A2 and A3. ```javascript /*本示例演示 LogInv 方法使用对数分布可分析经过对数变换的数据,并分别赋值给A2和A3单元格。*/ function test() { Range("A2").Value2 = WorksheetFunction.LogInv(0.263, 21.3, 2) Range("A3").Value2 = WorksheetFunction.LogInv(0.45, 11, 0.5) } ``` -------------------------------- ### Find Substring and Assign to Cells Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/WorksheetFunction/%E6%96%B9%E6%B3%95/Find%20%E6%96%B9%E6%B3%95.html This example shows how to use the Find method to find the starting position of a substring and assign the results directly to worksheet cells. It includes examples with and without specifying a starting position. ```javascript /*本示例使用 Find 方法查找参数1字符串开始的位置,并分别赋值给E1等单元格。*/ function test() { Range("E1").Value2 = WorksheetFunction.Find("in", "Believe in yourself.") Range("E2").Value2 = WorksheetFunction.Find("bird", "The bird who dares to fall is bird who learns to fly.", 2) } ``` -------------------------------- ### LogInv Method Usage Example 2 Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/WorksheetFunction/%E6%96%B9%E6%B3%95/LogInv%20%E6%96%B9%E6%B3%95.html This example assigns values to cells A1, A2, and A3 to demonstrate the LogInv method for analyzing logarithmically transformed data. ```javascript /*本示例为A1等单元格分别赋值,演示 LogInv 方法使用对数分布可分析经过对数变换的数据。*/ function test() { Range("A1").Value2 = 0.75 Range("A2").Value2 = 100 Range("A3").Value2 = 5 console.log(WorksheetFunction.LogInv(Range("A1").Value2, Range("A2").Value2, Range("A3").Value2)) } ``` -------------------------------- ### Get Count of Hidden Items Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/PivotField/%E6%96%B9%E6%B3%95/HiddenItems%20%E6%96%B9%E6%B3%95.html This example demonstrates how to get the number of hidden PivotItems for a specific field in a PivotTable. ```APIDOC ## GET /api/v2/excel/workbook/PivotField/HiddenItems ### Description Retrieves the count of hidden PivotItems for a specified PivotField. ### Method GET ### Endpoint /api/v2/excel/workbook/PivotField/{fieldName}/HiddenItems ### Parameters #### Path Parameters - **fieldName** (string) - Required - The name of the PivotField. #### Query Parameters - **Index** (any) - Optional - Specifies the number or name of the item to return. Can be an array for multiple items. ### Response #### Success Response (200) - **Count** (integer) - The number of hidden items. ### Request Example ```javascript // This example shows the number of hidden PivotItems for the field "score" of a PivotTable in the active worksheet. function test() { let pvtField = ActiveSheet.Range("I1").PivotTable.PivotFields("score") console.log(pvtField.HiddenItems().Count) } ``` ``` -------------------------------- ### Get LegendKey Width Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/LegendEntry/%E5%B1%9E%E6%80%A7/LegendKey%20%E5%B1%9E%E6%80%A7.html This example shows how to get the width of the legend marker for the first legend item on Chart1. ```javascript /*本示例显示 Chart1 上图例项一的图例标示的宽度。*/ function test() { console.log(Application.Charts.Item("Chart1").ChartObjects(1).Chart.Legend.LegendEntries(1).LegendKey.Width) } ``` -------------------------------- ### Save File As New Source: https://airsheet.wps.cn/docs/apiV2/advanced/KSDrive.html Demonstrates how to save an existing file as a new file with a different name using the 'source' option. ```javascript // Save file as url = KSDrive.createFile(KSDrive.FileType.KSheet, { source: 'https://www.kdocs.cn/l/cqQwuiG2mo7E', name: '复制表格' }) console.log(url) ``` -------------------------------- ### Get HiLoLines Name Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/HiLoLines/%E5%B1%9E%E6%80%A7/Name%20%E5%B1%9E%E6%80%A7.html This example shows how to get the name of the first HiLoLines in the first chart group of Chart1. ```javascript /*本示例显示图表工作表 Chart1 中第一个图表组高低点连线的名称。*/ function test() { let chartGroup = Application.Charts.Item("Chart1").ChartObjects(1).Chart.ChartGroups(1) console.log(chartGroup.HiLoLines.Name) } ``` -------------------------------- ### Connect a New Connector to an Existing Endpoint Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/ConnectorFormat/%E5%B1%9E%E6%80%A7/EndConnectionSite%20%E5%B1%9E%E6%80%A7.html This example demonstrates how to add a new shape and connector, then connect the new connector's endpoint to the same site as an existing connector's endpoint. It also connects the new connector's start point to the new shape. ```javascript /*此示例假定第一张工作表已包含由名为 Conn1To2 的连接符附加的两个形状。本示例的代码将向第一张工作表添加一个矩形和一个连接符。新连接符终点的连接位置与原来名为 Conn1To2 的连接符终点的连接位置相同,而新连接符的起点会连接到新矩形的第一个连接位置上。*/ function test() { let worksheet = Application.Worksheets.Item(1) let shapes = worksheet.Shapes let shape = shapes.AddShape(msoShapeRectangle, 100, 420, 200, 100) let connFormat1 = shapes.Item("Conn1To2").ConnectorFormat let endConnSite1 = connFormat1.EndConnectionSite let endConnShape1 = connFormat1.EndConnectedShape let connFormat2 = shapes.AddConnector(msoConnectorCurve, 0, 0, 10, 10).ConnectorFormat connFormat2.BeginConnect(shape, 1) connFormat2.EndConnect(endConnShape1, endConnSite1) } ``` -------------------------------- ### Get Count of Slicer Items Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/SlicerCache/%E5%B1%9E%E6%80%A7/SlicerItems%20%E5%B1%9E%E6%80%A7.html This example demonstrates how to get the number of items in the first slicer cache of the active workbook. ```APIDOC ## GET /SlicerCache/{slicerCacheId}/SlicerItems ### Description Retrieves a collection of all items within a specified slicer cache. ### Method GET ### Endpoint `/SlicerCache/{slicerCacheId}/SlicerItems` ### Parameters #### Path Parameters - **slicerCacheId** (string) - Required - The ID of the slicer cache. ### Response #### Success Response (200) - **SlicerItems** (collection) - A collection of slicer items. ### Response Example ```json { "SlicerItems": [ { "Name": "Item 1", "Selected": true }, { "Name": "Item 2", "Selected": false } ] } ``` ``` -------------------------------- ### BeginConnect Method Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/ConnectorFormat/%E6%96%B9%E6%B3%95/BeginConnect%20%E6%96%B9%E6%B3%95.html Connects the starting point of a specified connector to a shape. If a connection already exists between the connector's start point and another shape, that existing connection is broken. If the connector's start point is not on the desired connection site, this method moves the start point to that site and adjusts the connector's size and position accordingly. ```APIDOC ## BeginConnect (Method) ### Description Connects the starting point of a specified connector to a shape. If a connection already exists between the connector's start point and another shape, that existing connection is broken. If the connector's start point is not on the desired connection site, this method moves the start point to that site and adjusts the connector's size and position accordingly. The `EndConnect` method can be used to connect the end point of the connector to a shape. When a connector is connected to an object, its size and position are automatically adjusted as necessary. Note that calls to the `RerouteConnections` method make the `ConnectionSite` parameters specified in the `BeginConnect` and `EndConnect` methods irrelevant. ### Parameters | Attribute | Data Type | Required | Description | |---|---|---|---| | ConnectedShape | Shape | Required | The shape to connect to the start point of the connector. The specified Shape object must be in the same Shapes collection as the connector. | | ConnectionSite | int4 | Required | The connection site on the shape specified by `ConnectedShape`. Must be an integer between 1 and the return value of the specified shape's `ConnectionSiteCount` property. If you want the connector to automatically find the shortest path between the two shapes it connects, specify any valid integer for this parameter and use the `RerouteConnections` method after the connector has been connected to both shapes. | ### Examples javascript ```javascript /*This example adds two rectangles to the first worksheet and connects them using a curved connector line.*/ function test() { let worksheet = Application.Worksheets.Item(1) let s = worksheet.Shapes let firstRect = s.AddShape(msoShapeRectangle, 100, 50, 200, 100) let secondRect = s.AddShape(msoShapeRectangle, 300, 300, 200, 100) let c = s.AddConnector(msoConnectorCurve, 0, 0, 100, 100) c.ConnectorFormat.BeginConnect(firstRect, 1) c.ConnectorFormat.EndConnect(secondRect, 1) c.RerouteConnections() } ``` javascript ```javascript /*This example connects the start point of the third shape (a connector line) in the active worksheet to the third connection point of the first shape, and the end point to the first connection point of the second shape.*/ function test() { let shapes = ActiveSheet.Shapes let shape1 = shapes.Item(1) let shape2 = shapes.Item(2) let shape3 = shapes.Item(3) shape3.ConnectorFormat.BeginConnect(shape1, 3) shape3.ConnectorFormat.EndConnect(shape2, 1) } ``` ``` -------------------------------- ### Get ET GUID Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Application/%E5%B1%9E%E6%80%A7/ProductCode%20%E5%B1%9E%E6%80%A7.html This snippet demonstrates how to retrieve the global unique identifier (GUID) of an ET using the Application.ProductCode property. ```javascript /*此示例显示 ET 的 GUID。*/ function test() { console.log(Application.ProductCode) } ``` -------------------------------- ### PivotLineCellsFull Property Examples Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/PivotLine/%E5%B1%9E%E6%80%A7/PivotLineCellsFull%20%E5%B1%9E%E6%80%A7.html Examples demonstrating how to use the PivotLineCellsFull property to get the count of cells and check if all hidden cells are retrieved. ```APIDOC ## PivotLineCellsFull Property ### Description Retrieves all pivot line cells, including those hidden in a compressed form. This is a read-only property. ### Examples #### Example 1: Get the count of cells for the first pivot line on the column axis. ```javascript /*This example shows the number of cells retrieved for the first pivot line on the column axis of a pivot table on the active worksheet.*/ function test() { let pvtLine = ActiveSheet.Range("I1").PivotTable.PivotColumnAxis.PivotLines(1) console.log(pvtLine.PivotLineCellsFull.Count) } ``` #### Example 2: Check if all hidden cells are retrieved for the second pivot line on the row axis. ```javascript /*This example shows whether the second pivot line on the row axis of the first pivot table on worksheet Sheet1 retrieves all hidden cells.*/ function test() { let pvtLine = Worksheets.Item("Sheet1").PivotTables(1).PivotRowAxis.PivotLines(2) console.log(pvtLine.PivotLineCellsFull.Full) } ``` ``` -------------------------------- ### Iterate and List Files in a Directory Source: https://airsheet.wps.cn/docs/apiV2/advanced/KSDrive.html Provides an example of how to traverse a directory in the cloud drive, listing files by their names. It handles pagination using 'offset' and 'nextOffset'. ```javascript // Traverse and get the file names of all files in a folder for (let offset = 0; offset >= 0; ) { const list = KSDrive.listFiles({ dirUrl: 'https://www.kdocs.cn/mine/xxxxxxxxxx', offset: offset, count: 100 }) for (let i = 0; i < list.files.length; i++) { console.log(list.files[i].fileName) } offset = list.nextOffset } ``` -------------------------------- ### Get AutoFilter Count Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/ListObject/%E5%B1%9E%E6%80%A7/AutoFilter%20%E5%B1%9E%E6%80%A7.html This example shows how to get the number of filters applied to the auto-filter range of the first list object on Sheet1. ```javascript /*本示例显示工作表 Sheet1 上第一张列表的自动筛选范围中的筛选器的数量。*/ function test() { let listObj = Application.Worksheets.Item("Sheet1").ListObjects.Item(1) console.log(listObj.AutoFilter.Filters.Count) } ``` -------------------------------- ### Log 'hello world!' to Console Source: https://airsheet.wps.cn/docs/start/quickstart.html Use console.log() to output messages to the AirScript console. ```javascript console.log("hello world!") ``` -------------------------------- ### Get LegendKey Height Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/LegendEntry/%E5%B1%9E%E6%80%A7/LegendKey%20%E5%B1%9E%E6%80%A7.html This example shows how to get the height of the legend marker for the second legend item on the first chart in Sheet1. ```javascript /*下例显示 Sheet1 中的第一个图表的第二个图例项的图例标示的高度。*/ function test() { let legend = Application.Worksheets.Item("Sheet1").ChartObjects(1).Chart.Legend console.log(legend.LegendEntries(2).LegendKey.Height) } ``` -------------------------------- ### Add and Delete a Custom List Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Application/%E6%96%B9%E6%B3%95/DeleteCustomList%20%E6%96%B9%E6%B3%95.html This example shows the process of adding a custom list, confirming the addition, and then deleting it. It first adds the list, logs a success message, retrieves the list's number, and finally deletes it. This illustrates a common workflow involving list manipulation. ```javascript /*本示例演示添加一个自定义序列,通知用户后,删除此自定义序列。*/ function test() { let customlist = ["water", "lemon", "apple"] Application.AddCustomList(customlist) console.log("添加成功,即将删除此自定义序列!") let n = Application.GetCustomListNum(customlist) Application.DeleteCustomList(n) } ``` -------------------------------- ### Get Active Workbook Sheet Count Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Sheets/%E5%B1%9E%E6%80%A7/Count%20%E5%B1%9E%E6%80%A7.html This example shows how to get the number of sheets in the currently active workbook. It logs the count to the console. ```javascript /*此示例显示活动工作簿中的工作表数量。*/ function test() { console.log(Application.ActiveWorkbook.Sheets.Count) } ``` -------------------------------- ### Calculate Product of Prices for Fruits (DProduct) Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/WorksheetFunction/%E6%96%B9%E6%B3%95/DProduct%20%E6%96%B9%E6%B3%95.html This example demonstrates how to use the DProduct function to calculate the product of prices for fruits within a specified range and criteria. It sets up sample data for fruits and their prices, then applies conditions to filter and multiply. ```javascript /*本示例为C1等单元格分别赋值,并使用DProduct方法计算从C1:D4相应的列中提取符合指定条件的值的乘积。*/ function test() { Range("C1").Value2 = "水果" Range("C2").Value2 = "西瓜" Range("C3").Value2 = "荔枝" Range("C4").Value2 = "香蕉" Range("D1").Value2 = "单价" Range("D2").Value2 = 2.3 Range("D3").Value2 = 10 Range("D4").Value2 = 3.4 Range("E1").Value2 = "单价" Range("E2").Value2 = ">3" Range("F1").Value2 = "单价" Range("F2").Value2 = "<30" let det1 = Application.WorksheetFunction.DProduct(Range("C1:D4"), Range("D1").Value2, Range("E1:F2")) console.log(det1) } ``` -------------------------------- ### ImProduct Method Example Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/WorksheetFunction/%E6%96%B9%E6%B3%95/ImProduct%20%E6%96%B9%E6%B3%95.html This example demonstrates how to use the ImProduct method to calculate the product of complex numbers. It shows calculations for two and three complex numbers, assigning the results to specific cells. ```APIDOC ## ImProduct Method ### Description Returns the product of 2 to 29 complex numbers represented in x + yi or x + yj text format. ### Method WorksheetFunction.ImProduct ### Parameters #### Path Parameters - **Arg1** (any) - Required - Arg30 - Inumber1, inumber2,... - 1 to 29 complex numbers to multiply. ### Request Example ```javascript /*This example uses the ImProduct method to calculate the product of 2 and 3 complex numbers represented in x + yi or x + yj text format, and assigns them to cells B3 and B4 respectively.*/ function test() { Range("B3").Value2 = WorksheetFunction.ImProduct(WorksheetFunction.Complex(2, 6), WorksheetFunction.Complex(12, 5)) Range("B4").Value2 = WorksheetFunction.ImProduct("8+4j", "8+9j", "9+9j") } ``` ### Response String ### Response Example ```javascript /*This example assigns values to cells A1 etc. and uses the ImProduct method to calculate the product of complex numbers in cells A1 etc.*/ function test() { Range("A1").Formula = "=COMPLEX(3,5)" Range("A2").Formula = "=COMPLEX(2,5)" Range("A3").Formula = "=COMPLEX(1,-6)" console.log(WorksheetFunction.ImProduct(Range("A1").Value2, Range("A2").Value2, Range("A3").Value2)) } ``` ``` -------------------------------- ### Using Choose with Cell References and Numerical Values Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/WorksheetFunction/%E6%96%B9%E6%B3%95/Choose%20%E6%96%B9%E6%B3%95.html This example shows how to use the Choose method with cell references and numerical values. It first assigns values to cells B2 through B6, then uses Choose to select values based on different indices and logs the results. The index can be a number, and the arguments can be cell references containing numerical values. ```javascript /*本示例为B2等单元格分别赋值,并使用Choose方法获取参数列表中相应的数值。*/ function test() { Range("B2").Value2 = 35 Range("B3").Value2 = 25 Range("B4").Value2 = 12.2 Range("B5").Value2 = 18.44 Range("B6").Value2 = 30 let Choose1 = Application.WorksheetFunction.Choose(2, Range("B2").Value2, Range("B3").Value2, Range("B4").Value2, Range("B5").Value2, Range("B6").Value2) let Choose2 = Application.WorksheetFunction.Choose(3, Range("B2").Value2, Range("B3").Value2, Range("B4").Value2, Range("B5").Value2, Range("B6").Value2) console.log(Choose1) console.log(Choose2) } ``` -------------------------------- ### Get DataFields Count Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/PivotTables/%E6%96%B9%E6%B3%95/Item%20%E6%96%B9%E6%B3%95.html This example shows how to retrieve the number of data fields in the first PivotTable on the active worksheet. It accesses the PivotTable and then its DataFields collection to get the count. ```javascript /*本示例显示活动工作表中第一张数据透视表值字段的数量。*/ function test() { console.log(ActiveSheet.PivotTables().Item(1).DataFields().Count) } ``` -------------------------------- ### Populate ComboBox with Specific Index Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/ControlFormat/%E6%96%B9%E6%B3%95/AddItem%20%E6%96%B9%E6%B3%95.html This example shows how to create a combo box and add items at a specific index. It adds two items, both at index 1, demonstrating control over item placement. ```javascript /*本示例创建一个组合框并按照指定索引对其进行填充。*/ function test() { let shape = ActiveSheet.Shapes.AddFormControl(xlDropDown, 500, 100, 110, 110) shape.ControlFormat.AddItem(1, 1) shape.ControlFormat.AddItem(2, 1) } ``` -------------------------------- ### Get SourceName for a Calculated PivotField Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/PivotField/%E5%B1%9E%E6%80%A7/SourceName%20%E5%B1%9E%E6%80%A7.html This example shows how to get the SourceName for a calculated PivotField like 'Sum of score' by first accessing the PivotTable via a range and then the PivotField. ```javascript /*本示例显示第一张工作表中数据透视表的字段“求和项:score”的原始源数据中展示的名称。*/ function test() { let pvtField = Worksheets.Item(1).Range("I1").PivotTable.PivotFields("求和项:score") console.log(pvtField.SourceName) } ``` -------------------------------- ### Get Category Axis Top Distance Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Axis/%E5%B1%9E%E6%80%A7/Top%20%E5%B1%9E%E6%80%A7.html This example shows how to get the distance from the category axis to the top of the chart in Chart1. It retrieves the Top property of the category axis. ```javascript /*本示例显示图表工作表 Chart1 中图表的分类轴到图表顶部的距离。*/ function test() { let axis = Application.Charts.Item("Chart1").ChartObjects(1).Chart.Axes(xlCategory) console.log(`分类轴到图表顶部的距离:${axis.Top} 磅`) } ``` -------------------------------- ### List All Named Formulas with R1C1 References Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Name/%E5%B1%9E%E6%80%A7/RefersToR1C1%20%E5%B1%9E%E6%80%A7.html This example creates a new worksheet and populates it with a list of all names in the workbook, including their formulas expressed in R1C1-style notation and macro language. ```javascript /*本示例新建一个工作表,并将当前工作簿所有名称的列表插入到新工作表中,名称列表中包括其公式(由 R1C1-样式引用和宏语言组成)。*/ function test() { let newSheet = Application.ActiveWorkbook.Worksheets.Add() let i = 1 for (let nm = 1; nm <= Application.ActiveWorkbook.Names.Count; nm++) { newSheet.Cells.Item(i, 1).Value2 = Application.ActiveWorkbook.Names.Item(nm).Name newSheet.Cells.Item(i, 2).Value2 = "'" + Application.ActiveWorkbook.Names.Item(nm).RefersToR1C1 i = i + 1 } } ``` -------------------------------- ### Get Slicer Count Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Slicers/Slicers%20%E5%AF%B9%E8%B1%A1.html This example shows how to get the number of slicers within the first slicer cache of the active workbook. It accesses the Slicers collection and retrieves its Count property. ```javascript /*本示例显示活动工作簿中第一个切片器缓存中的切片器数量。*/ function test() { console.log(ActiveWorkbook.SlicerCaches(1).Slicers.Count) } ``` -------------------------------- ### List Formulas for First PivotTable on First Worksheet Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/PivotTable/%E6%96%B9%E6%B3%95/ListFormulas%20%E6%96%B9%E6%B3%95.html This example creates a list of calculated items and fields for the first PivotTable on the first worksheet. Ensure the PivotTable exists and is accessible. ```javascript /*本示例为第一个工作表上的第一个数据透视表创建一个计算项和计算字段的列表。*/ function test() { Worksheets.Item(1).PivotTables(1).ListFormulas() } ``` -------------------------------- ### Numbering Connection Sites and Adding Connectors Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/ConnectorFormat/ConnectorFormat%20%E5%AF%B9%E8%B1%A1.html This example iterates through each connection site of a selected shape, numbers them, and adds a straight connector to each site. It then changes the connector type to elbow and sets its color to red. A textbox is added to display the connection site number. ```javascript /*本示例将对活动工作表所选形状的每个连接结点进行编号并连接一个连接符。*/ function test() { ActiveSheet.Shapes.SelectAll() let shape = Selection.ShapeRange.Item(1) let bx = shape.Left + shape.Width + 50 let by = shape.Top + shape.Height + 50 let count = shape.ConnectionSiteCount for (let j = 1; j <= count; j++) { let connector = ActiveSheet.Shapes.AddConnector(msoConnectorStraight, bx, by, bx + 50, by + 50) connector.ConnectorFormat.EndConnect(shape, j) connector.ConnectorFormat.Type = msoConnectorElbow connector.Line.ForeColor.RGB = RGB(255, 0, 0) let l = connector.Left let t = connector.Top let textbox = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, l, t, 36, 14) textbox.Fill.Visible = false textbox.Line.Visible = false textbox.TextFrame.Characters().Text = j } } ``` -------------------------------- ### Get Pivot Field Count from First Worksheet Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/PivotFields/%E5%B1%9E%E6%80%A7/Count%20%E5%B1%9E%E6%80%A7.html This example demonstrates how to get the number of pivot fields in the first worksheet of a workbook. It accesses the PivotTable and its PivotFields collection to retrieve the count. ```javascript /*本示例显示第一张工作表中数据透视表的字段数量。*/ function test() { console.log(Worksheets.Item(1).Range("I1").PivotTable.PivotFields().Count) } ``` -------------------------------- ### Display Custom List Contents Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Application/%E6%96%B9%E6%B3%95/GetCustomListContents%20%E6%96%B9%E6%B3%95.html This example retrieves the elements of the second custom list and displays them in the console as a string. It directly calls GetCustomListContents and then uses toString() to format the output. ```javascript /*本示例显示第二个自定义序列的元素。*/ function test() { console.log(Application.GetCustomListContents(2).toString()) } ``` -------------------------------- ### List Files with Specific Extensions Source: https://airsheet.wps.cn/docs/apiV2/advanced/KSDrive.html Demonstrates listing files from a specific directory, filtering by provided extensions such as 'ksheet', 'et', 'db', 'otl', 'wpp', or 'wps'. ```javascript const list = KSDrive.listFiles({ dirUrl: 'https://www.kdocs.cn/mine/xxxxxx', includeExts: ['ksheet', 'et', 'db', 'otl', 'wpp', 'wps'] }) ``` -------------------------------- ### Get PivotLines Count Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/PivotAxis/%E5%B1%9E%E6%80%A7/PivotLines%20%E5%B1%9E%E6%80%A7.html This example demonstrates how to get the total number of PivotLines on the row axis of a pivot table on the active worksheet. It accesses the PivotLines collection and logs its Count property. ```javascript /*本示例显示活动工作表上数据透视表中行轴上数据透视线的数量。*/ function test() { let pvtLines = ActiveSheet.Range("I1").PivotTable.PivotRowAxis.PivotLines console.log(pvtLines.Count) } ``` -------------------------------- ### Get Data Type of RevisionNumber Property Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Workbook/%E5%B1%9E%E6%80%A7/RevisionNumber%20%E5%B1%9E%E6%80%A7.html This example demonstrates the data type of the RevisionNumber property. ```javascript /*本示例演示RevisionNumber属性的数据类型。*/ function test() { console.log(typeof ActiveWorkbook.RevisionNumber) } ``` -------------------------------- ### Convert 4 Inches to Points and Log Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Application/%E6%96%B9%E6%B3%95/InchesToPoints%20%E6%96%B9%E6%B3%95.html This example shows how to convert 4 inches into points using the InchesToPoints method and then logs the resulting point value to the console. ```javascript /*本示例将4英寸转换为磅值并显示。*/ function test() { console.log(Application.InchesToPoints(4)) } ``` -------------------------------- ### Count AllowEditRanges Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Protection/%E5%B1%9E%E6%80%A7/AllowEditRanges%20%E5%B1%9E%E6%80%A7.html This example shows how to get the total number of AllowEditRange objects on a specific worksheet. ```APIDOC ## Count AllowEditRanges ### Description Returns the number of editable ranges configured on a worksheet. ### Method ```javascript // Get the count of AllowEditRanges on a worksheet // worksheet.Protection.AllowEditRanges.Count ``` ### Properties - **Count** (number) - The total number of editable ranges on the worksheet. ### Request Example (JavaScript) ```javascript // This example displays the number of AllowEditRange objects on the second worksheet. console.log(Worksheets.Item(2).Protection.AllowEditRanges.Count) ``` ``` -------------------------------- ### Get PivotTable Name Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/PivotTable/%E5%B1%9E%E6%80%A7/Name%20%E5%B1%9E%E6%80%A7.html This example demonstrates how to retrieve the name of the first PivotTable on the active worksheet. ```javascript /*本示例显示活动工作表中第一张数据透视表的名称*/ function test() { console.log(ActiveSheet.PivotTables(1).Name) } ``` -------------------------------- ### Compare Range, Union, and Intersect Methods Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Application/%E6%96%B9%E6%B3%95/Intersect%20%E6%96%B9%E6%B3%95.html This example compares different methods for selecting cells and ranges, including the Range property, Application.Union, and Application.Intersect methods. It shows how to select individual cells, contiguous ranges, and the intersection of ranges. ```javascript /*本示例比较 Worksheet.Range 属性、 Application.Union 方法和 Intersect 方法。*/ function test() { // Selects cells A1 to A10. Range("A1:A10").Select() // Selects cells A1 to A10. Range(Range("A1"), Range("A10")).Select() // Selects cells A1 and A10. Range("A1, A10").Select() // Selects cells A1 and A10. Union(Range("A1"), Range("A10")).Select() // Selects cell A5. Range("A1:A5 A5:A10").Select() // Selects cell A5. Intersect(Range("A1:A5"), Range("A5:A10")).Select() } ``` -------------------------------- ### Get ID of ShapeRange on Specific Worksheet Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/ShapeRange/%E5%B1%9E%E6%80%A7/ID%20%E5%B1%9E%E6%80%A7.html This example shows how to get the ID of a newly created ShapeRange object on the first worksheet. It requires accessing the Application and specifying the worksheet and shape range. ```javascript /*本示例显示第一张工作表中新建的ShapeRange对象的ID。*/ function test() { let shpRange = Application.Worksheets.Item(1).Shapes.Range([1]) console.log(shpRange.ID) } ``` -------------------------------- ### Populating a Range with Formulas Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Range/Range%20%E5%AF%B9%E8%B1%A1.html This example shows how to populate a specified range (A1:H8) on Sheet1 with a formula by first activating the sheet and then applying the formula to the range. ```APIDOC ## Populating a Range with Formulas ### Description This example shows how to populate a specified range (A1:H8) on Sheet1 with a formula by first activating the sheet and then applying the formula to the range. ### Method JavaScript (AirScript) ### Endpoint N/A (SDK Method) ### Parameters N/A ### Request Example ```javascript /*本示例通过为区域 A1:H8 中的每个单元格设置公式,用随机数字填充该区域*/ function test() { Application.Worksheets.Item("Sheet1").Activate() //Range is on the active sheet Application.Range("A1:H8").Formula = "=Rand()" } ``` ### Response N/A ``` -------------------------------- ### Get Pivot Field Count from Active Sheet Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/PivotFields/%E5%B1%9E%E6%80%A7/Count%20%E5%B1%9E%E6%80%A7.html This example shows how to get the number of pivot fields from the first pivot table on the active worksheet. The count is then logged to the console with a descriptive label. ```javascript /*本示例显示活动工作表中第一张数据透视表的字段数量。*/ function test() { console.log(`字段数量:${ActiveSheet.PivotTables(1).PivotFields().Count}`) } ``` -------------------------------- ### Add Shapes and Connectors Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Shape/%E5%B1%9E%E6%80%A7/ConnectionSiteCount%20%E5%B1%9E%E6%80%A7.html This example demonstrates adding two rectangles and connecting them with two connectors. It shows how to use ConnectionSiteCount to specify the end connection point for a connector. ```javascript /*本示例向活动工作表中添加两个矩形,并且用两个连接符连接这两个矩形。两个连接符的起点都连接到第一个矩形的第一个连接位置,两个连接符的终点分别连接到第二个矩形的第一个和最后一个连接位置。*/ function test() { let shapes = ActiveSheet.Shapes let firstRect = shapes.AddShape(msoShapeRectangle, 100, 50, 200, 100) let secondRect = shapes.AddShape(msoShapeRectangle, 300, 300, 200, 100) let lastsite = secondRect.ConnectionSiteCount let Con1 = shapes.AddConnector(msoConnectorCurve, 0, 0, 100, 100).ConnectorFormat Con1.BeginConnect(firstRect, 1) Con1.EndConnect(secondRect, 1) let Con2 = shapes.AddConnector(msoConnectorCurve, 0, 0, 100, 100).ConnectorFormat Con2.BeginConnect(firstRect, 1) Con2.EndConnect(secondRect, lastsite) } ``` -------------------------------- ### Get Response Body as Binary Source: https://airsheet.wps.cn/docs/apiV2/advanced/HTTP.html Retrieves the response body from a GET request as a binary Buffer. Use this for non-textual data like images or files. The example converts the buffer to a base64 string. ```javascript let resp = HTTP.get('https://open.iciba.com/dsapi/') console.log(resp.binary().toString('base64')) ``` -------------------------------- ### Pv Method with Cell References Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/WorksheetFunction/%E6%96%B9%E6%B3%95/Pv%20%E6%96%B9%E6%B3%95.html This example shows how to use the Pv method with cell references to calculate the present value of an investment. The values for rate, nper, and pmt are taken from cells A1, B1, and C1, respectively. ```APIDOC ## Pv Method with Cell References ### Description This example assigns values to cells A1, B1, and C1 and then uses the Pv method to calculate the present value of an investment based on these cell values. ### Parameters #### Arguments - **Arg1** (double) - Required - Rate: The interest rate per period. - **Arg2** (double) - Required - Nper: The total number of payment periods for the annuity. - **Arg3** (double) - Required - Pmt: The payment made each period. ### Return Value Double ### Example ```javascript /*This example assigns values to cells A1, B1, and C1 and then uses the Pv method to calculate the present value of an investment. */ function test() { Range("A1").Value2 = 0.0012 Range("B1").Value2 = 48 Range("C1").Value2 = -231.5 console.log(WorksheetFunction.Pv(Range("A1").Value2, Range("B1").Value2, Range("C1").Value2)) } ``` ``` -------------------------------- ### Get Trendline Index for a Series on a Worksheet Source: https://airsheet.wps.cn/docs/apiV2/excel/workbook/Trendline/%E5%B1%9E%E6%80%A7/Index%20%E5%B1%9E%E6%80%A7.html This example shows how to get the index of a trendline associated with a specific data series on a worksheet's chart. Verify the worksheet, chart, and series are correctly referenced. ```javascript /*此示例显示第一张工作表上的第一个图表的第一个数据系列指定趋势线的索引。*/ function test() { let series = Application.Worksheets.Item(1).ChartObjects(1).Chart.SeriesCollection(1) console.log(series.Trendlines(2).Index) } ```