java.lang.Objectcom.aspose.words.DocumentProperty
public class DocumentProperty
Example:
String fileName = getMyDir() + "Properties.doc";
Document doc = new Document(fileName);
System.out.println(MessageFormat.format("1. Document name: {0}", fileName));
System.out.println("2. Built-in Properties");
for (int i = 0; i < doc.getBuiltInDocumentProperties().getCount(); i++)
{
DocumentProperty prop = doc.getBuiltInDocumentProperties().get(i);
System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue()));
}
System.out.println("3. Custom Properties");
for (int i = 0; i < doc.getCustomDocumentProperties().getCount(); i++)
{
DocumentProperty prop = doc.getCustomDocumentProperties().get(i);
System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue()));
}
Property Getters/Setters Summary | ||
---|---|---|
java.lang.String | getName() | |
Returns the name of the property. | ||
int | getType() | |
Gets the data type of the property. The value of the property is PropertyType integer constant. | ||
java.lang.Object | getValue() | |
void | setValue(java.lang.Object value) | |
Gets or sets the value of the property. |
Method Summary | ||
---|---|---|
boolean | toBool() | |
Returns the property value as bool. | ||
byte[] | toByteArray() | |
Returns the property value as byte array. | ||
java.util.Date | toDateTime() | |
Returns the property value as DateTime in UTC. | ||
double | toDouble() | |
Returns the property value as double. | ||
int | toInt() | |
Returns the property value as integer. | ||
java.lang.String | toString() | |
Returns the property value as a string formatted according to the current locale. |
Property Getters/Setters Detail |
---|
getName | |
public java.lang.String getName() |
Cannot be null and cannot be an empty string.
Example:
Enumerates through all built-in and custom properties in a document using indexed access.String fileName = getMyDir() + "Properties.doc"; Document doc = new Document(fileName); System.out.println(MessageFormat.format("1. Document name: {0}", fileName)); System.out.println("2. Built-in Properties"); for (int i = 0; i < doc.getBuiltInDocumentProperties().getCount(); i++) { DocumentProperty prop = doc.getBuiltInDocumentProperties().get(i); System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue())); } System.out.println("3. Custom Properties"); for (int i = 0; i < doc.getCustomDocumentProperties().getCount(); i++) { DocumentProperty prop = doc.getCustomDocumentProperties().get(i); System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue())); }
getType | |
public int getType() |
Example:
Enumerates through all built-in and custom properties in a document using indexed access.String fileName = getMyDir() + "Properties.doc"; Document doc = new Document(fileName); System.out.println(MessageFormat.format("1. Document name: {0}", fileName)); System.out.println("2. Built-in Properties"); for (int i = 0; i < doc.getBuiltInDocumentProperties().getCount(); i++) { DocumentProperty prop = doc.getBuiltInDocumentProperties().get(i); System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue())); } System.out.println("3. Custom Properties"); for (int i = 0; i < doc.getCustomDocumentProperties().getCount(); i++) { DocumentProperty prop = doc.getCustomDocumentProperties().get(i); System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue())); }
Example:
Retrieves the types and values of the custom document properties.Document doc = new Document(getMyDir() + "Properties.doc"); for (DocumentProperty prop : doc.getCustomDocumentProperties()) { System.out.println(prop.getName()); switch (prop.getType()) { case PropertyType.STRING: System.out.println("It's a string value."); System.out.println(prop.toString()); break; case PropertyType.BOOLEAN: System.out.println("It's a boolean value."); System.out.println(prop.toBool()); break; case PropertyType.NUMBER: System.out.println("It's an integer value."); System.out.println(prop.toInt()); break; case PropertyType.DATE_TIME: System.out.println("It's a date time value."); System.out.println(prop.toDateTime()); break; case PropertyType.DOUBLE: System.out.println("It's a double value."); System.out.println(prop.toDouble()); break; case PropertyType.OTHER: System.out.println("Other value."); break; default: throw new Exception("Unknown property type."); } }
getValue/setValue | |
public java.lang.Object getValue() / public void setValue(java.lang.Object value) |
Cannot be null.
Example:
Enumerates through all built-in and custom properties in a document using indexed access.String fileName = getMyDir() + "Properties.doc"; Document doc = new Document(fileName); System.out.println(MessageFormat.format("1. Document name: {0}", fileName)); System.out.println("2. Built-in Properties"); for (int i = 0; i < doc.getBuiltInDocumentProperties().getCount(); i++) { DocumentProperty prop = doc.getBuiltInDocumentProperties().get(i); System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue())); } System.out.println("3. Custom Properties"); for (int i = 0; i < doc.getCustomDocumentProperties().getCount(); i++) { DocumentProperty prop = doc.getCustomDocumentProperties().get(i); System.out.println(MessageFormat.format("{0}({1}) : {2}", prop.getName(), prop.getType(), prop.getValue())); }
Method Detail |
---|
toBool | |
public boolean toBool() |
Throws an exception if the property type is not
Example:
Retrieves the types and values of the custom document properties.Document doc = new Document(getMyDir() + "Properties.doc"); for (DocumentProperty prop : doc.getCustomDocumentProperties()) { System.out.println(prop.getName()); switch (prop.getType()) { case PropertyType.STRING: System.out.println("It's a string value."); System.out.println(prop.toString()); break; case PropertyType.BOOLEAN: System.out.println("It's a boolean value."); System.out.println(prop.toBool()); break; case PropertyType.NUMBER: System.out.println("It's an integer value."); System.out.println(prop.toInt()); break; case PropertyType.DATE_TIME: System.out.println("It's a date time value."); System.out.println(prop.toDateTime()); break; case PropertyType.DOUBLE: System.out.println("It's a double value."); System.out.println(prop.toDouble()); break; case PropertyType.OTHER: System.out.println("Other value."); break; default: throw new Exception("Unknown property type."); } }
toByteArray | |
public byte[] toByteArray() |
Throws an exception if the property type is not
toDateTime | |
public java.util.Date toDateTime() |
Throws an exception if the property type is not
Microsoft Word stores only the date part (no time) for custom date properties.
Example:
Retrieves the types and values of the custom document properties.Document doc = new Document(getMyDir() + "Properties.doc"); for (DocumentProperty prop : doc.getCustomDocumentProperties()) { System.out.println(prop.getName()); switch (prop.getType()) { case PropertyType.STRING: System.out.println("It's a string value."); System.out.println(prop.toString()); break; case PropertyType.BOOLEAN: System.out.println("It's a boolean value."); System.out.println(prop.toBool()); break; case PropertyType.NUMBER: System.out.println("It's an integer value."); System.out.println(prop.toInt()); break; case PropertyType.DATE_TIME: System.out.println("It's a date time value."); System.out.println(prop.toDateTime()); break; case PropertyType.DOUBLE: System.out.println("It's a double value."); System.out.println(prop.toDouble()); break; case PropertyType.OTHER: System.out.println("Other value."); break; default: throw new Exception("Unknown property type."); } }
Example:
Retrieves a custom document property by name.Document doc = new Document(getMyDir() + "Properties.doc"); DocumentProperty prop = doc.getCustomDocumentProperties().get("Authorized Date"); if (prop != null) { System.out.println(prop.toDateTime()); } else { System.out.println("The document is not authorized. Authorizing..."); doc.getCustomDocumentProperties().add("AuthorizedDate", new Date()); }
toDouble | |
public double toDouble() |
Example:
Retrieves the types and values of the custom document properties.Document doc = new Document(getMyDir() + "Properties.doc"); for (DocumentProperty prop : doc.getCustomDocumentProperties()) { System.out.println(prop.getName()); switch (prop.getType()) { case PropertyType.STRING: System.out.println("It's a string value."); System.out.println(prop.toString()); break; case PropertyType.BOOLEAN: System.out.println("It's a boolean value."); System.out.println(prop.toBool()); break; case PropertyType.NUMBER: System.out.println("It's an integer value."); System.out.println(prop.toInt()); break; case PropertyType.DATE_TIME: System.out.println("It's a date time value."); System.out.println(prop.toDateTime()); break; case PropertyType.DOUBLE: System.out.println("It's a double value."); System.out.println(prop.toDouble()); break; case PropertyType.OTHER: System.out.println("Other value."); break; default: throw new Exception("Unknown property type."); } }
toInt | |
public int toInt() |
Example:
Retrieves the types and values of the custom document properties.Document doc = new Document(getMyDir() + "Properties.doc"); for (DocumentProperty prop : doc.getCustomDocumentProperties()) { System.out.println(prop.getName()); switch (prop.getType()) { case PropertyType.STRING: System.out.println("It's a string value."); System.out.println(prop.toString()); break; case PropertyType.BOOLEAN: System.out.println("It's a boolean value."); System.out.println(prop.toBool()); break; case PropertyType.NUMBER: System.out.println("It's an integer value."); System.out.println(prop.toInt()); break; case PropertyType.DATE_TIME: System.out.println("It's a date time value."); System.out.println(prop.toDateTime()); break; case PropertyType.DOUBLE: System.out.println("It's a double value."); System.out.println(prop.toDouble()); break; case PropertyType.OTHER: System.out.println("Other value."); break; default: throw new Exception("Unknown property type."); } }
toString | |
public java.lang.String toString() |
Converts a boolean property into "Y" or "N". Converts a date property into a short date string. For all other types converts a property using Object.ToString().
Example:
Retrieves the types and values of the custom document properties.Document doc = new Document(getMyDir() + "Properties.doc"); for (DocumentProperty prop : doc.getCustomDocumentProperties()) { System.out.println(prop.getName()); switch (prop.getType()) { case PropertyType.STRING: System.out.println("It's a string value."); System.out.println(prop.toString()); break; case PropertyType.BOOLEAN: System.out.println("It's a boolean value."); System.out.println(prop.toBool()); break; case PropertyType.NUMBER: System.out.println("It's an integer value."); System.out.println(prop.toInt()); break; case PropertyType.DATE_TIME: System.out.println("It's a date time value."); System.out.println(prop.toDateTime()); break; case PropertyType.DOUBLE: System.out.println("It's a double value."); System.out.println(prop.toDouble()); break; case PropertyType.OTHER: System.out.println("Other value."); break; default: throw new Exception("Unknown property type."); } }
Example:
Retrieves a built-in document property by name.Document doc = new Document(getMyDir() + "Properties.doc"); DocumentProperty prop = doc.getBuiltInDocumentProperties().get("Keywords"); System.out.println(prop.toString());