Read and Modify Properties
This guide will show you how to Read and Modify Properties of a Microsoft Word Document.
Before you begin
You should get your API key from your UniCloud account.
If this is your first time using UniOffice SDK, follow this guide to set up a local development environment.
Clone the project repository
In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.
git clone https://github.com/unidoc/unioffice-examples
To get the example navigate to the path document/doc-properties
folder in the unioffice-examples directory.
cd unioffice-examples/document/doc-properties/
How it works
Lines 5-13
import the UniOffice packages and other required dependencies.
The init function in lines 15-22
authenticates your request with your UNIDOC_LICENSE_API_KEY
.
In the main function, the file is opened, with error handling on lines 25-29
. Next, the CoreProperties function is used to access the document properties on lines 33-40
, which can be conveniently obtained using the result variable.
Additionally, these properties can be modified using the corresponding configure method associated with each property, as demonstrated on lines 43-49
, just before saving the file.
Run the code
Run this command to generate a Word document that displays the changes applied to its custom properties.
go run main.go
Sample output
When you inspect the properties of the document, you will notice that they align with the properties assigned in the code, reflecting the alterations displayed on the screen via the printf statements.
Title: CP Invoices
Author: John Doe
Description:
Last Modified By: Вячеслав Згордан
Category: Invoices
Content Status:
Created: 2020-06-09 09:25:00 +0000 UTC
Modified: 2020-06-09 09:28:00 +0000 UTC