Основной сайт хуманэмулятор.рф  |  Демо  |  Купить  |  API  |  Wiki



System / wordfile



get_table_by_number

get_table_by_number($path,$number,$as_array=false); - Прочитать таблицу по номеру из Word документа (только для docx)

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

  • $path – Путь к файлу
  • $number – Номер таблицы
  • $as_array – получить результат как массив

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

    Пример использования
    <?php
    // Scenario: Get table data from a Word document by table number
    $xhe_host = getenv("RPABOT_HOST_URL");
    // Connect functional objects if not already connected
    if (!isset($path)){
      $path = "../../../Templates/init.php";
      require($path);
    }
    // info
    echo "\n<span >wordfile->" . basename (__FILE__) . "</span>\n";
    
    // Initialize variables
    $filePath = "test/test.docx";
    $tableNumber = 0;
    $asArray = true;
    
    // Open the file to read
    SYSTEM::$wordfile->open($filePath, true);
    
    // Example 1: Read the specified table as text
    echo("1. Read the specified table as text: <br><br>");
    $tableText = SYSTEM::$wordfile->get_table_by_number($filePath, $tableNumber);
    echo($tableText);
    
    // Example 2: Read the specified table as an array
    echo("\n\n2. Read the specified table as an array: <br><br>");
    $tableArray = SYSTEM::$wordfile->get_table_by_number($filePath, $tableNumber, $asArray);
    var_export($tableArray);
    
    // Close the file
    SYSTEM::$wordfile->close($filePath);
    
    echo "\n";
    
    // Quit the application
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7012"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>sound.xxxxxxxxx</font><hr>")
    
    # 1 
    echo("1. Прочитать 0 таблицу как текст : <br><br>");
    echo(wordfile.get_table_by_number("test\\test.docx",0));
    
    # 2
    echo("\n2. Прочитать 0 таблицу как массив : <br><br>");
    echo(wordfile.get_table_by_number("test\\test.docx",0,True));
    
    # конец
    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>sound.beep</font><hr>");
    
    			// 1 
    			echo("1. Прочитать заданный файл как текст : \n\n");
    			echo(wordfile.get_table_by_number("test\\test.docx",0));
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7012";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>sound.beep</font><hr>");
    
    // 1 
    echo("1. Прочитать 0 таблицу как текст : \n");
    echo(wordfile.get_table_by_number("test\\test.docx",0));	
    
    // 2 
    echo("\n\n2. Прочитать 0 таблицу как массив : \n");
    echo(wordfile.get_table_by_number("test\\test.docx",0,true));	
    
    // Quit
    app.quit();

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