<div class="blockquote blockquote_border">
<span class="title title_div-01">get_paragraph_text_block_by_index_odt(string file_path, int paragraph_index, int timeout = 300): string</span>
<p>Получить текст элемента типа `paragraph` по порядковому номеру (отсчет с 0)</p>
</div>
<div class="title title_div-01">Команда на вход принимает параметры: </div>
<ul class="ul ul_disc">
<li><span class="title title_div-01">file_path</span> – путь к файлу</span></li>
<li><span class="title title_div-01">paragraph_index</span> – индекс заголовка (отсчет с 0)</span></li>
<li><span class="title title_div-01">timeout</span> – таймаут на исполнение операции, сек</span></li>
</ul>
<div class="title title_div-01">После отработки команда возвращает результат своей работы в робот: </div>
<ul class="ul ul_disc ul_marker-green">
<li><span class="title title_div-01 c_success">Текст</span> - текст заголовка или пустая строка, если индекс вне диапазона</span></li>
</ul>
Пример использования (php)
<?php
// Scenario: Extract paragraph text by index from an ODT document
$xhe_host = "127.0.0.1:7010";
// подключим функциональные объекты, если еще не подключен
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();
?>