Skip to main content

Read-Range

Command Description

Read values of the specified range in a sheet, and return a two-dimensional array

Command Prototype

arrayRet = Excel.ReadRange(objExcelWorkBook,sheet,strRange,bRetDisplay)

Parameter Description

ParameterRequiredTypeDefaultDescription
objExcelWorkBookTrueexpressionobjExcelWorkBookExcel workbook object (workbook opened with "Open Excel" command (Excel.OpenExcel) or the workbook object returned by the command "Bind Excel" (Excel.BindBook))
sheetTruestring"Sheet1"The string means sheet name. The number means sheet order(starting from 0)
strRangeTruestring"A1:B2"[[cell 1 row number, cell 1 column number],[cell 2 row number, cell 2 column number]] and "A1:B2" are supported to specify a certain area, and are case insensitive. When only one cell is written, data is read from the beginning of the cell to the end of the table
bRetDisplayTruebooleanTrueSelect "Yes", then the return content is consistent with the content displayed in the Excel cell, and always returns in the form of a string (when there is a wrap, the content will be automatically encapsulated with double quotation marks);Select "No", The content will be automatically converted according to the data type, for example, the returned value of 0.1 would be 0.1 instead of the string "0.1"

return

arrayRet,The variable used to save the output of the command.

Demo

/********************Read Area**************************** ********* 
**Input 1:
** objExcelWorkBook -- Excel workbook object (a workbook opened using the "Open Excel" command (Excel.OpenExcel) or a work bound using the "Bind Excel" command (Excel.BindBook) book object).
**Entry 2:
** sheet--If a string is used, it means the name of the specified worksheet; if a number is used, it means the order of the specified worksheet (starting from 0).
**Entry 3:
** strRange--Specified range, supports cell names such as "A1:B2" and two-dimensional row and column arrays such as [[cell 1 row number, cell 1 column number], [cell 2 Row number, cell 2 column number]] two forms, case-insensitive when using cell names.
**Entry 4:
** bRetDisplay--Select Yes, the returned content is consistent with the content displayed in the Excel cell, and is always returned in the form of a string (when the cell content has a line break, the returned content will be automatically at the beginning and end Add double quotation marks); select No, the returned content will be automatically converted according to the data type, such as 0.1 returns the value 0.1 instead of the string "0.1"
**Exports:
** arrayRet--The variable to which the output of the function call is saved.
**
*********************************************************************/

objExcelWorkBook = Excel.OpenExcel(@res"Test.xlsx",True,"Excel","","")
arrayRet = Excel.ReadRange(objExcelWorkBook,"Sheet1","A1:B2",true)
TracePrint "Read area: The value of the Excel object Sheet1 worksheet A1-B2 area is: "
TracePrint arrayRet
Excel.CloseExcel(objExcelWorkBook,False)