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

get_sheet_number_by_name

get_sheet_number_by_name($path,$name,$exactly=true); - Получить номер Листа по его названию

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

  • $path – Путь к файлу Excel
  • $name – Название Листа
  • $exactly – Точное соответствие названия Листа

    После выполнения функции возвращаемое значение будет равно одному из двух :
  • число (Номер Листа или -1 если произошла ошибка)
  • -1 – ошибка

    Пример использования
    <?php 
    // Scenario: Demonstrates how to get the index number of a sheet by its name in an Excel workbook
    
    $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);
    }
    
    // Set variables for method arguments
    $filePath = "test/test.xlsx";
    $sheetName1 = "Лист2";
    $sheetName2 = "Лист1";
    
    // Kill any existing Excel processes
    SYSTEM::$excel->kill();
    
    // Example 1: Get number of sheet by name "Лист2"
    echo("\nExample 1: Get number of sheet by name '$sheetName1'\n");
    $sheetNumber1 = SYSTEM::$excel->get_sheet_number_by_name($filePath, $sheetName1);
    if ($sheetNumber1 !== null) {
        echo("Sheet '$sheetName1' has number: $sheetNumber1\n");
    } else {
        echo("Failed to get number of sheet '$sheetName1'\n");
    }
    
    // Example 2: Get number of sheet by name "Лист1"
    echo("\nExample 2: Get number of sheet by name '$sheetName2'\n");
    $sheetNumber2 = SYSTEM::$excel->get_sheet_number_by_name($filePath, $sheetName2);
    if ($sheetNumber2 !== null) {
        echo("Sheet '$sheetName2' has number: $sheetNumber2\n");
    } else {
        echo("Failed to get number of sheet '$sheetName2'\n");
    }
    
    // Quit the application
    WINDOW::$app->quit();
    ?>
    xhe_host="127.0.0.1:7023";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>excelfile.get_cell</font><hr>");
    
    // 1 
    echo("1. Получим номер листа по имени : ");
    echo(excelfile.get_sheet_number_by_name("test\\test.xlsx","Лист2"));
    
    // 2
    echo("\n2. Получим номер листа по имени : ");
    echo(excelfile.get_sheet_number_by_name("test\\test.xlsx","Лист1"));
    
    // посмотрим
    app.shell_execute("open","test\\test.xlsx");
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

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