讀取 Word 文檔的任務就是讀取 DOM 模型中的分層數據結構的任務。這意味著了解每個單獨的 Word 數據元素的格式,包括其所有可能的子元素和屬性。
我們的 Ruby 庫是一個基於雲的解決方案,可讓您輕鬆打開 Word 文件進行讀寫。這種分佈式方法使您可以靈活地使用 Ruby 語言進行軟件開發,因為所有資源密集型 Word 文檔處理都將在 Aspose 服務器上進行。您只需要獲取私鑰即可在 Ruby 代碼中訪問 Cloud API。
您可以遍歷 Word 文檔的所有元素,也可以在 DOM 樹中搜索特定元素。我們提供了廣泛的 Ruby 函數,用於處理 Word 文件的結構和文檔節點中包含的數據。
以下代碼示例將幫助您快速了解如何使用 Ruby 加載 Word 文件並對其執行一些操作。
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。