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

delete_paragraph_by_number

delete_paragraph_by_number($path,$number); - Удалить параграф по номеру в WORD документе

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

  • $path – Путь к файлу
  • $number – Номер параграфа

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

    Пример использования
    <?php 
    // Scenario: Delete a paragraph from a Word document by its 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 >word->" . basename (__FILE__) . "</span>\n";
    
    // Initialize variables
    $filePath = "test/test.docx";
    $paragraphNumber = 0;
    
    // Open the file for edit
    SYSTEM::$word->open($filePath, false);
    
    // Get the number of paragraphs in the document
    echo("\nGet number of paragraphs in document: ");
    $paragraphsCount = SYSTEM::$word->get_paragraphs_count($filePath);
    echo($paragraphsCount . "\n");
    
    // Example 1: Delete paragraph by number
    echo("1. Delete paragraph by number: ");
    $result = SYSTEM::$word->delete_paragraph_by_number($filePath, $paragraphNumber);
    if ($result) {
        echo("Successfully deleted paragraph\n");
    } else {
        echo("Failed to delete paragraph\n");
    }
    
    // Get the number of paragraphs in the document
    echo("\nGet number of paragraphs in document after delete one: ");
    $paragraphsCount = SYSTEM::$word->get_paragraphs_count($filePath);
    echo($paragraphsCount . "\n");
    
    
    // Save and close the document
    SYSTEM::$word->save($filePath);
    SYSTEM::$word->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:3039"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>sound.xxxxxxxxx</font><hr>")
    
    path = "test/test_create.docx";
    
    # 1
    echo("1. Удалим параграф по номеру : ");
    echo(word.delete_paragraph_by_number(path,0));
    
    # 2
    echo("\n2. Получим весь текст : \n");
    echo(word.get_text(path));
    
    # 3
    echo("\n3. Получим количество параграфов в документов : ");
    echo(word.get_paragraphs_count(path));
    
    app.shell_execute("open",path);
    
    
    # конец
    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>word.delete_paragraph_by_number</font><hr>");
    
    			var path = "test\\test_create.docx";
    
    			// 1
    			echo("1. Удалим параграф по номеру : ");
    			echo(word.delete_paragraph_by_number(path,0));
    
    			// 2
    			echo("\n2. Получим весь текст : \n");
    			echo(word.get_text(path));
    
    			// 3
    			echo("\n3. Получим количество параграфов в документов : ");
    			echo(word.get_paragraphs_count(path));
    
    			app.shell_execute("open",path);
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:3039";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>sound.beep</font><hr>");
    
    var path = "test\\test_create.docx";
    
    // 1
    echo("1. Удалим параграф по номеру : ");
    echo(word.delete_paragraph_by_number(path,0));
    
    // 2
    echo("\n2. Получим весь текст : \n");
    echo(word.get_text(path));
    
    // 3
    echo("\n3. Получим количество параграфов в документов : ");
    echo(word.get_paragraphs_count(path));
    
    app.shell_execute("open",path);
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

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