在 PHP SDK 中打開 DOC

使用 REST API 在 PHP 中以編程方式打開和讀取 DOC 文件

只需幾行 PHP 代碼即可輕鬆打開 DOC 文檔。我們的 PHP 庫將為您提供以編程方式訪問 DOC 文檔內容所需的一切。

看程式碼片段

在 PHP 中打開一個 DOC 文件

讀取 DOC 文檔的任務就是讀取 DOM 模型中的分層數據結構的任務。這意味著了解每個單獨的 DOC 數據元素的格式,包括其所有可能的子元素和屬性。

我們的 PHP 庫是一個基於雲的解決方案,可讓您輕鬆打開 DOC 文件進行讀寫。這種分佈式方法使您可以靈活地使用 PHP 語言進行軟件開發,因為所有資源密集型 DOC 文檔處理都將在 Aspose 服務器上進行。您只需要獲取私鑰即可在 PHP 代碼中訪問 Cloud API。

在 PHP 中以編程方式讀取 DOC 文檔

您可以遍歷 DOC 文檔的所有元素,也可以在 DOM 樹中搜索特定元素。我們提供了廣泛的 PHP 函數,用於處理 DOC 文件的結構和文檔節點中包含的數據。

以下代碼示例將幫助您快速了解如何使用 PHP 加載 DOC 文件並對其執行一些操作。

上傳您要訪問的文檔
運行代碼
use Aspose\Words\WordsApi;

$wordsApi = new WordsApi('####-####-####-####-####', '##################');
$fileName = "Input.doc";

$requestFileContent = file_get_contents(realpath(
   __DIR__ . '/../../..') . "/TestData/" . $fileName);
$uploadDocumentRequest = new UploadFileRequest(
    $requestFileContent, $fileName, NULL
);
$wordsApi->uploadFile($uploadDocumentRequest);

$requestParagraph = new ParagraphInsert(array(
    "text" => "Reading and writing to the file in the cloud occurs automatically.",
));
$insertParagraphRequest = new InsertParagraphRequest(
    $fileName, $requestParagraph, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
);
$wordsApi->insertParagraph($insertParagraphRequest);

$downloadDocumentRequest = new DownloadFileRequest(
    $fileName, NULL, NULL
);
$wordsApi->downloadFile($downloadDocumentRequest);
運行代碼
  
將代碼PHP複製到剪貼板

如何讀取 PHP 中的 DOC 文件

  1. 為 PHP 安裝"Aspose.Words Cloud"
  2. 將庫引用(導入庫)添加到您的 PHP 項目
  3. 讀取 DOC 文件

安裝 PHP 庫以讀取 DOC 個文件

Packagist 存儲庫安裝 'Aspose.Words Cloud SDK for PHP' 。只需運行 composer require aspose-cloud/aspose-words-cloud 來安裝 SDK,然後使用 require_once('vendor/autoload.php'); 將其導入您的項目。

作為替代方案,您可以從 GitHub 手動克隆 Aspose.Words Cloud SDK for PHP 源代碼。請按照這些 Instructions 快速獲取必要的安全憑證並訪問我們的 REST API。

系統要求

PHP 7.1 或更新版本

請參閱 Repository Documentation 以查看更多詳細信息。

其他支持的文件格式

您可以打開其他格式的文檔:

5%

訂閱 Aspose 產品更新

獲取直接發送到您的郵箱的每月通訊和優惠。

© Aspose Pty Ltd 2001-2025. 版權所有。