如果您想打開一個文本文件並以純文本格式處理數據,您可以使用 Go 語言和操作系統的最基本功能來完成。至於閱讀以多種文件格式(DOCX、DOC、PDF、RTF、ODT、HTML 等)呈現的辦公文檔,這個任務更難解決,因為這些文檔是由複雜的樹狀數據描述的DOM 模型中的結構。
我們的 Go 庫是一個基於雲的解決方案,可讓您以任何辦公室和 Web 格式打開文檔。這種分佈式方法使您可以靈活地使用 Go 語言進行軟件開發,因為所有資源密集型文檔處理都將在 Aspose 服務器上進行。您只需要獲取私鑰即可在 Go 代碼中訪問 Cloud API。
您可以迭代文檔元素,也可以在 DOM 樹中搜索特定元素。我們提供了廣泛的 Go 函數,用於處理文檔結構和文檔節點中包含的數據。
以下 Go 代碼示例將幫助您快速了解如何加載文檔並對其執行一些操作。
import (
"os"
"github.com/aspose-words-cloud/aspose-words-cloud-go/dev/api/models"
)
config, _ := models.NewConfiguration("config.json")
wordsApi, ctx, _ := api.CreateWordsApi(config)
fileName:= "Input.docx"
requestFileContent, _ := os.Open(ReadFile(t, fileName))
uploadDocumentRequestOptions := map[string]interface{}{}
uploadDocumentRequest := &models.UploadFileRequest{
FileContent: requestFileContent,
Path: ToStringPointer(fileName),
Optionals: uploadDocumentRequestOptions,
}
_, _, _ = wordsApi.UploadFile(ctx, uploadDocumentRequest)
requestParagraph := models.ParagraphInsert{
Text: ToStringPointer("Reading and writing to the file in the cloud occurs automatically."),
}
insertParagraphRequestOptions := map[string]interface{}{}
insertParagraphRequest := &models.InsertParagraphRequest{
Name: ToStringPointer(fileName),
Paragraph: &requestParagraph,
Optionals: insertParagraphRequestOptions,
}
_, _, _ = wordsApi.InsertParagraph(ctx, insertParagraphRequest)
downloadDocumentRequestOptions := map[string]interface{}{}
downloadDocumentRequest := &models.DownloadFileRequest{
Path: ToStringPointer(fileName),
Optionals: downloadDocumentRequestOptions,
}
_, _ = wordsApi.DownloadFile(ctx, downloadDocumentRequest)
運行 go get -v github.com/aspose-words-cloud/aspose-words-cloud-go/2007/api 安裝 Aspose.Words Cloud SDK for Go 。您可以從 "How to use SDK" 部分獲得有關其他安裝方法的大量有用信息。
從 GitHub 克隆 Aspose.Words Cloud SDK for Go 源代碼並在您的項目中使用它。請按照這些 Instructions 快速獲取必要的安全憑證並訪問我們的 REST API。
請參閱 Repository Documentation 以查看詳細信息。