在 PHP SDK 中打开 DOCX

使用 REST API 在 PHP 中以编程方式打开和读取 DOCX 文件

只需几行 PHP 代码即可轻松打开 DOCX 文档。我们的 PHP 库将为您提供以编程方式访问 DOCX 文档内容所需的一切。

查看代码片段

在 PHP 中打开一个 DOCX 文件

读取 DOCX 文档的任务是读取 DOM 模型中的分层数据结构的任务。这意味着了解每个单独的 DOCX 数据元素的格式,包括其所有可能的子元素和属性。

我们的 PHP 库是一个基于云的解决方案,可让您轻松打开 DOCX 文件进行读写。这种分布式方法使您可以灵活地使用 PHP 语言进行软件开发,因为所有资源密集型 DOCX 文档处理都将在 Aspose 服务器上进行。您只需要获取私钥即可在 PHP 代码中访问 Cloud API。

在 PHP 中以编程方式读取 DOCX 文档

您可以遍历 DOCX 文档的所有元素,也可以在 DOM 树中搜索特定元素。我们提供了广泛的 PHP 函数,用于处理 DOCX 文件的结构和文档节点中包含的数据。

以下代码示例将帮助您快速了解如何使用 PHP 加载 DOCX 文件并对其执行一些操作。

上传您要访问的文档
运行代码
use Aspose\Words\WordsApi;

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

$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 中的 DOCX 文件

  1. 为 PHP 安装"Aspose.Words Cloud"
  2. 将库引用(导入库)添加到您的 PHP 项目
  3. 读取 DOCX 文件

安装 PHP 库以读取 DOCX 个文件

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. 版权所有。