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

set_sheet

set_sheet($path,$sheet,$sheet_array,$timeout=3000,$row=1,$col="A"); - Задать содержимое листа Excel файла данными из двумерного массива

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

  • $path – Путь к файлу Excel
  • $sheet – Номер Листа
  • $sheet_array – Двумерный массив с данными
  • $timeout – Таймаут ожидания выполнения операции, сек
  • $row – строка (по умолчанию первая строка)
  • $col – Буквенное или цифровое значение (по умолчанию столбец "А")

    После выполнения функции возвращаемое значение будет равно одному из двух :
  • true – успешно
  • false – не удалось

    Пример использования
    <?php
    // Scenario: Set sheet content from an array in an Excel file
    $xhe_host = getenv("RPABOT_HOST_URL");
    // Connect functional objects if not already connected
    if (!isset($path)){
      $path = "../../../Templates/init.php";
      require($path);
    }
    
    // beginning
    echo "\n<span >excel->".basename (__FILE__)."</span>\n";
    
    // Kill existing Excel processes
    SYSTEM::$excel->kill();
    
    // Excel file path
    $filePath = "test/test.xlsx";
    
    // Example 1: Set sheet content from an array
    // Set arguments as variables
    $sheetIndex = 4;
    $sheetArray = array(
        array(11, 12, 13),
        array(21, 22, 23),
        array(31, 32, 33, 44, 55),
    );
    $timeout = 3000;
    $rowOffset = 5;
    $colOffset = 10;
    
    echo("\n\n1. Set sheet content from an array: ");
    $result = SYSTEM::$excel->set_sheet($filePath, $sheetIndex, $sheetArray, $timeout, $rowOffset, $colOffset);
    if ($result) {
        echo("Success - Sheet $sheetIndex content set from array\n");
    } else {
        echo("Failed - Could not set sheet $sheetIndex content from array\n");
    }
    
    // end
    echo "\n";
    
    // Quit
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7020"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>excelfile.set_sheet</font><hr>")
    
    excel.kill()
    arr  = [[1,2,3], [4,5,6], [7,8,9]]
    
    # 1
    echo("1. Задать лист из массива ")
    echo(excel.set_sheet("test/test.xlsx", 3, arr, 3000, 5, 10))
    
    # посмотрим
    app.shell_execute("open", "test\\test.xlsx")
    
    # конец
    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 XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    
    #endregion
    
     class Program:XHEScript
     {
    	  static void Main(string[] args)
    	  {
    			// init XHE
    			server = Environment.GetEnvironmentVariable("RPABOT_HOST_URL");
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>excel.set_sheet</font><hr>");
    
    			// 1
    			var arr = new string[,] {{"1","2","3"}, {"2","3","4"}, {"5","6","7"}};
    			echo("1. Задать содержимое листа из массива: ");
    			echo(excel.set_sheet("test/test.xlsx", 4, 3000,5,10));
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>excelfile.set_sheet</font><hr>");
    
    
    // 1 
    var arr = [[1,2,3], [2,3,4], [5,6,7]];
    echo("\n1. Зададим содержимое листа из массива: ");
    console.log(excel.set_sheet("test\\test.xlsx",4, arr, 3000,5,10));
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

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