Can we create a field in a word document locally using python ? Like without requesting the API.
@Flyomega
You can use the Aspose.Words Cloud SDK for Python to add a Table of Contents field to a local Word document. Please check the following unit test for reference. However, if there is any difference between your requirement and my understanding, then please share some more details about your requirement.
request_field = asposewordscloud.FieldInsert(field_code='{ NUMPAGES }')
request = asposewordscloud.models.requests.InsertFieldRequest(name=remote_file_name, field=request_field, node_path='sections/0/paragraphs/0', folder=remote_data_folder)
result = self.words_api.insert_field(request)
self.assertIsNotNone(result, 'Error has occurred.')
self.assertIsNotNone(result.field, 'Validate InsertField response')
self.assertEqual('{ NUMPAGES }', result.field.field_code)
self.assertEqual('0.0.0.1', result.field.node_id)
#
# Test for putting field online.
#
def test_insert_field_online(self):
field_folder = 'DocumentElements/Fields'
request_document = open(os.path.join(self.local_test_folder, field_folder + '/GetField.docx'), 'rb')
request_field = asposewordscloud.FieldInsert(field_code='{ NUMPAGES }')
request = asposewordscloud.models.requests.InsertFieldOnlineRequest(document=request_document, field=request_field, node_path='sections/0/paragraphs/0')
result = self.words_api.insert_field_online(request)
self.assertIsNotNone(result, 'Error has occurred.')