humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | лог изменений

get_sheet

get_sheet($path,$sheet,$timeout=3000); - Получить содержимое заданного Листа Excel файла как двумерный массив

Функция на вход принимает параметры:

  • $path – Путь к файлу Excel
  • $sheet – номер Листа
  • $timeout – Таймаут ожидания выполнения операции, сек

    После выполнения функции возвращаемое значение будет равно одному из двух :
  • результат – двухмерный массив значений из прямоугольного диапазона ячеек листа, который начинается с ячейки А1 и заканчивается крайней правой нижней непустой ячейкой.
  • пусто / null – ошибка

    Пример использования
    <?php
    
    // Scenario: Get sheet data from Excel file
    
    $xhe_host = getenv("RPABOT_HOST_URL");
    
    // Connect functional objects if not already connected
    if (!isset($path)){
        // Path to the init.php file for connecting to the XHE API
        $path = "../../../Templates/init.php";
        // Including init.php grants access to all classes and functionality for working with the XHE API
        require($path);
    }
    
    echo "\n<span >excelfile->" . basename(__FILE__) . "</span>\n";
    
    // Initialize Excel
    SYSTEM::$excel->kill();
    
    // Example 1: Get sheet content as array
    echo("\nExample 1: Get sheet content as array: ");
    // Extract method arguments into variables
    $filePath = "test/test.xlsx";
    $sheetIndex = 0;
    var_export(SYSTEM::$excelfile->get_sheet($filePath, $sheetIndex));
    
    // View the result
    
    
    // Quit
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7028"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>excelfile.get_sheet</font><hr>")
    
    # 1 
    echo("\n1. Прочитаем лист как массив : \n\n")
    echo(excelfile.get_sheet("test\\test.xlsx",0))
    
    # конец
    echo("<hr><br>")
    
    # Quit
    app.quit()
    #region using
    
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    using Newtonsoft.Json.Linq;
    
    #endregion
    
     class MyScript:XHEScript
     {
    	  static void Main(string[] args)
    	  {			
    			// init XHE
    			server = "127.0.0.1:7027";
    			InitXHE();
    
                string path_excel ="challenge.xlsx";
    			// go to google
    			browser.navigate("https://rpachallenge.com/");
    			    
    			 // данные из файла
                JArray arr = excelfile.get_sheet(path_excel,0);   
                 
                btn.click_by_inner_text("START");
    
    			for (int i = 0; i < arr.Count; i++)
    			{
    				JArray row = (JArray)arr[i];
    				   
    				//label.get_by_inner_text("First Name").get_next().set_value(row[0]);
    				input.set_value_by_attribute("ng-reflect-name","labelFirstName", 1, (string)row[0]);
    				//  фамилия
    				//label.get_by_inner_text("Last Name").get_next().set_value(row[1]);
    				input.set_value_by_attribute("ng-reflect-name","labelLastName", 1, (string)row[1]);
    				// 
    				//label.get_by_inner_text("Company Name").get_next().set_value(row[2]);
    				input.set_value_by_attribute("ng-reflect-name","labelCompanyName", 1, (string)row[2]);
    				// 
    				//label.get_by_inner_text("Role in Company").get_next().set_value(row[3]);
    				input.set_value_by_attribute("ng-reflect-name","labelRole", 1, (string)row[3]);
    				// 
    				//label.get_by_inner_text("Address").get_next().set_value(row[4]);
    				input.set_value_by_attribute("ng-reflect-name","labelAddress", 1, (string)row[4]);
    				// 
    				//label.get_by_inner_text("Email").get_next().set_value(row[5]);
    				input.set_value_by_attribute("ng-reflect-name","labelEmail", 1, (string)row[5]);
    				// 
    				//label.get_by_inner_text("Phone Number").get_next().set_value(row[6]);
    				input.set_value_by_attribute("ng-reflect-name","labelPhone", 1, (string)row[6]);
    
    
                     button.click_by_value("Submit");   
    				   
    				/*for (int j = 0; j < row.Count; j++)
    				{
    					echo((string)row[j]+"<br>");
    					
    				}*/
    			}
    
    			// exit
    			app.quit();            
    	  }
    	  
    	  /*static void print_r(object val)
            {
                if (val.GetType() == typeof(string))
                {
                    Console.Write(val);
                    return;
                }
                else if (val.GetType().GetInterface(typeof(IEnumerable).FullName) != null)
                {
                    foreach (object i in val)
                    {
                        // Process val as array
                    }
                }
                else
                {
                    Console.Write(val);
                    return;
                }
            }*/
    }
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>excelfile.get_cell</font><hr>");
    
    // 1 
    echo("\n1. Получим соедержимое листа как массив: ");
    console.log(excelfile.get_sheet("test\\test.xlsx",0));
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    excelfile    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум
    .