|
java.lang.Object
com.aspose.words.DocumentProperty
- All Implemented Interfaces:
- java.lang.Cloneable
public class DocumentProperty - extends java.lang.Object
Represents a custom or built-in document property.
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. Buil-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()));
} - See Also:
- DocumentPropertyCollection
|
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.
|
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 user locale.
|
|
Property Getters/Setters Detail |
getName | |
public java.lang.String getName()
|
-
Returns the name of the property.
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. Buil-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()));
}
getValue/setValue | |
public java.lang.Object getValue() / public void setValue(java.lang.Object value)
|
-
Gets or sets the value of the property.
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. Buil-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()
|
-
Gets the data type of the property.
The value of the property is PropertyType integer constant.
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. Buil-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.");
}
}
toString | |
public java.lang.String toString()
throws com.aspose.words.PleaseReportException |
-
Returns the property value as a string formatted according to the current user locale.
Converts a number property using Object.ToString(). Converts a boolean property
into "Y" or "N". Converts a date property into a short date string. 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());
-
Returns the property value as integer.
Throws an exception if the property type is not PropertyType.Number.
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.");
}
}
toDouble | |
public double toDouble() |
-
Returns the property value as double.
Throws an exception if the property type is not PropertyType.Float.
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.");
}
}
toDateTime | |
public java.util.Date toDateTime() |
-
Returns the property value as DateTime in UTC.
Throws an exception if the property type is not PropertyType.Date. 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());
}
toBool | |
public boolean toBool() |
-
Returns the property value as bool.
Throws an exception if the property type is not PropertyType.Boolean. Example: Retrieves the types and values of the custom document properties.
Document doc = new Document(getMyDir() + "Properti
|