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

get_paragraph_text_block_by_index_odt

get_paragraph_text_block_by_index_odt($file_path,$paragraph_index,$timeout=300); - Получить текст элемента типа `paragraph` по порядковому номеру (отсчет с 0)

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

  • $file_path – Путь к файлу
  • $paragraph_index – Индекс заголовка (отсчет с 0)
  • $timeout – Таймаут на исполнение операции, сек

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

    Пример использования
    <?php
    // Scenario: Extract paragraph text by index from an ODT document
    
    $xhe_host = getenv("RPABOT_HOST_URL");
    
    // подключим функциональные объекты, если еще не подключен
    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 >libreOffice->".basename (__FILE__)."</span>\n";
    
    // Example 1: Get the first paragraph from a document
    echo "\n\nExample 1: Getting the first paragraph from a document\n";
    $filePath = "test/test_style.odt";
    $paragraphIndex = 0;
    $paragraphTextBlock = SYSTEM::$libreOffice->get_paragraph_text_block_by_index_odt($filePath, $paragraphIndex);
    
    if (!empty($paragraphTextBlock)) {
        echo "Paragraph $paragraphIndex:\n$paragraphTextBlock\n";
    } else {
        echo "No paragraph found at index {$paragraphIndex} or error occurred.\n";
    }
    
    // Example 2: Get all paragraphs from a document
    echo("\n\nExample 2: Get all paragraphs from a document\n");
    $paragraphCount = SYSTEM::$libreOffice->get_paragraph_text_blocks_count_odt($filePath);
    
    echo("Total paragraphs in document: $paragraphCount\n");
           
    if ($paragraphCount > 0) {
        for ($paragraphIndex = 0; $paragraphIndex < $paragraphCount; $paragraphIndex++){
            $paragraphTextBlock = SYSTEM::$libreOffice->get_paragraph_text_block_by_index_odt($filePath, $paragraphIndex);
    
            if (!empty($paragraphTextBlock)) {
                echo "Paragraph $paragraphIndex: $paragraphTextBlock\n";
            } else {
                echo "No paragraph found at index {$paragraphIndex} or error occurred.\n";
            }
        }
    }
    
    // Quit the application
    WINDOW::$app->quit();
    
    ?>
    # Example for get_paragraph_by_index_odt function
    # 
    # This example demonstrates how to extract paragraph text by index from an ODT file
    # using the XHELibreOffice class.
    
    
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7013"
    from xweb_human_emulator import libreOffice, app, echo
    
    # начало
    echo("<hr><font color=blue>libreOffice->get_paragraph_text_block_by_index_odt</font><hr>")
    
    # Example 1: Get the first paragraph from a document
    echo("Example 1: Getting the first paragraph from a document\n");
    filePath = "test/test_style.odt";
    paragraphIndex = 0;
    paragraphTextBlock = libreOffice.get_paragraph_text_block_by_index_odt(filePath, paragraphIndex);
    
    if paragraphTextBlock:
        echo(f"Paragraph #{paragraphIndex}:\n{paragraphTextBlock}\n");
    else:
        echo(f"No paragraph found at index #{paragraphIndex} or error occurred.\n");
    
    # Quit
    app.quit()
    using System;
    
    /**
     * Example for get_paragraph_by_index_odt function
     *
     * This example demonstrates how to extract paragraph text by index from an ODT file
     * using the XHELibreOffice class.
     */
    
    // Scenario: Extract paragraph text by index from an ODT document
    
    namespace XHELibreOfficeExamples
    {
        class GetParagraphTextBlockByIndexOdtExample
        {
            static void Main(string[] args)
            {
                string xheHost = "127.0.0.1:7010";
    
                // Initialize XHE API connection
                // In C#, you would initialize the XHE API client here
                // This is equivalent to including init.php in PHP
    
                Console.WriteLine("\nlibreOffice->get_paragraph_text_block_by_index_odt.cs");
    
                // Example 1: Get the first paragraph from a document
                Console.WriteLine("\n\nExample 1: Getting the first paragraph from a document");
                string filePath = "test/test_style.odt";
                int paragraphIndex = 0;
                string paragraphTextBlock = libreOffice.get_paragraph_text_block_by_index_odt(filePath, paragraphIndex);
    
                if (!string.IsNullOrEmpty(paragraphTextBlock))
                {
                    Console.WriteLine($"Paragraph {paragraphIndex}:\n{paragraphTextBlock}");
                }
                else
                {
                    Console.WriteLine($"No paragraph found at index {paragraphIndex} or error occurred.");
                }
    
                // Example 2: Get all paragraphs from a document
                Console.WriteLine("\n\nExample 2: Get all paragraphs from a document");
                int paragraphCount = libreOffice.get_paragraph_text_blocks_count_odt(filePath);
    
                Console.WriteLine($"Total paragraphs in document: {paragraphCount}");
    
                if (paragraphCount > 0)
                {
                    for (paragraphIndex = 0; paragraphIndex < paragraphCount; paragraphIndex++)
                    {
                        paragraphTextBlock = libreOffice.get_paragraph_text_block_by_index_odt(filePath, paragraphIndex);
    
                        if (!string.IsNullOrEmpty(paragraphTextBlock))
                        {
                            Console.WriteLine($"Paragraph {paragraphIndex}: {paragraphTextBlock}");
                        }
                        else
                        {
                            Console.WriteLine($"No paragraph found at index {paragraphIndex} or error occurred.");
                        }
                    }
                }
    
                // Quit the application
                app.quit();
            }
        }
    }
    /**
     * Example for get_paragraph_by_index_odt function
     * 
     * This example demonstrates how to extract paragraph text by index from an ODT file
     * using the XHELibreOffice class.
     */
    
    xhe_host = "127.0.0.1:7013";
    
    // подключим функциональные объекты, если еще не подключен
    require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>libreOffice.get_paragraph_text_block_by_index_odt</font><hr>");
    
    // Example 1: Get the first paragraph from a document
    echo("Example 1: Getting the first paragraph from a document\n");
    const filePath = "test/test_style.odt";
    let paragraphIndex = 0;
    let paragraphTextBlock = libreOffice.get_paragraph_text_block_by_index_odt(filePath, paragraphIndex);
    
    if (paragraphTextBlock) {
        echo("Paragraph paragraphIndex:\nparagraphTextBlock\n");
    } else {
        echo("No paragraph found at index {paragraphIndex} or error occurred.\n");
    }
    
    // Example 2: Get all paragraphs from a document
    echo("Example 2: Get all paragraphs from a document\n");
    const paragraphCount = libreOffice.get_paragraph_text_blocks_count_odt(filePath);
    
    if (paragraphCount > 0) {
        for (paragraphIndex = 0; paragraphIndex < paragraphCount; paragraphIndex++){
            paragraphTextBlock = libreOffice.get_paragraph_text_block_by_index_odt(filePath, paragraphIndex);
    
            if (paragraphTextBlock) {
                echo("Paragraph " + paragraphIndex + ":\n" + paragraphTextBlock + "\n");
            } else {
                echo("No paragraph found at index " + paragraphIndex + " or error occurred.\n");
            }
        }
    }
    
    // Quit
    app.quit();

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