如果您想打开一个文本文件并以纯文本格式处理数据,您可以使用 Ruby 语言和操作系统的最基本功能来完成。至于阅读以多种文件格式(DOCX、DOC、PDF、RTF、ODT、HTML 等)呈现的办公文档,这个任务更难解决,因为这些文档是由复杂的树状数据描述的DOM 模型中的结构。
我们的 Ruby 库是一个基于云的解决方案,可让您以任何办公室和 Web 格式打开文档。这种分布式方法使您可以灵活地使用 Ruby 语言进行软件开发,因为所有资源密集型文档处理都将在 Aspose 服务器上进行。您只需要获取私钥即可在 Ruby 代码中访问 Cloud API。
您可以迭代文档元素,也可以在 DOM 树中搜索特定元素。我们提供了广泛的 Ruby 函数,用于处理文档结构和文档节点中包含的数据。
以下 Ruby 代码示例将帮助您快速了解如何加载文档并对其执行一些操作。
require 'aspose_words_cloud'
AsposeWordsCloud.configure do |config|
config.client_data['ClientId'] = '####-####-####-####-####'
config.client_data['ClientSecret'] = '##################'
end
@words_api = WordsAPI.new
file_name= 'Input.docx'
request_file_content = File.open(File.read(file_name))
upload_document_request = UploadFileRequest.new(
file_content: request_file_content, path: file_name)
@words_api.upload_file(upload_document_request)
request_paragraph = ParagraphInsert.new(
{:Text => 'Reading and writing to the file in the cloud occurs automatically.'})
insert_paragraph_request = InsertParagraphRequest.new(
name: file_name, paragraph: request_paragraph)
@words_api.insert_paragraph(insert_paragraph_request)
download_document_request = DownloadFileRequest.new(path: file_name)
@words_api.download_file(download_document_request)
使用 RubyGems 托管服务安装 Aspose.Words Cloud SDK for Ruby 。运行 gem install aspose_words_cloud 来安装包。作为替代方案,您可以从 GitHub 手动克隆 Aspose.Words Cloud SDK for Ruby 源代码并在您的项目中使用它。请按照这些 Instructions 快速获取必要的安全凭证并访问我们的 REST API。