We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How should a Date type DocProperty be set?

Word document template has a DocProperty defined as Date type. Setting java.util.Date value to com.aspose.words.DocumentProperty will lead to undesired behaviour:

- DocumentProperty PropertyType.DATE_TIME changes to PropertyType.OTHER

- Word document cannot be saved anymore: SEVERE: java.lang.UnsupportedOperationException: Do not know how to write a property value of this type.

I need to preserve the original Date type DocProperty; setting the date as String works but changes the DocProperty type to Text. I'm stuck and can't find any help in Aspose.Words documentation. Please feel free to give some useful advice here.

Aspose.Words for Java 3.3 & 3.21 tested here.

ARi

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Could you please attach sample document and provide me simple code example, which will allow me to reproduce the problem on my side? I will check the issue and provide you more information.

Best regards.

Sorry for delayed reply, I was having some time off for the New Year...

A sample document is attached and a simple test code to reproduce the problem follows here:


	public void testForAsposeForum() throws Exception
	{
	String value = "2.1.2010";
	SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");

	Document doc = new Document("C:/DATA/test/mditest_types.doc");
	DocumentProperty property = doc.getCustomDocumentProperties().get(
	    "prop_date");

	System.out.println("property.getType() = " + property.getType()
	    + " - propertyname=" + property.getName());
	switch (property.getType())
	{
		case PropertyType.STRING:
			property.setValue(value);
			break;
		case PropertyType.DATE_TIME:
			Date d = formatter.parse(value);
			System.out.println("DATE=" + d.toString());
			property.setValue(d);
			System.out.println("DATE2=" + property.getValue());
			System.out.println("IS IT A DATE? property.getType() = "
			    + property.getType() + " - propertyname="
			    + property.getName());
			break;
	}

	try
	{
		doc.save("C:/DATA/test/mditest_types_OUTPUT.doc");
	} catch (Exception e)
	{
		e.printStackTrace();
		throw e;
	}

}


And here’s the output of the test program:

property.getType() = 1 - propertyname=prop_date
DATE=Sat Jan 02 00:00:00 EET 2010
DATE2=Sat Jan 02 00:00:00 EET 2010
IS IT A DATE? property.getType() = 7 - propertyname=prop_date
java.lang.UnsupportedOperationException: Do not know how to write a property value of this type.
at asposewobfuscated.le.a(PropertySetSection.java:401)
at asposewobfuscated.le.toByteArray(PropertySetSection.java:152)
at asposewobfuscated.co.c(PropertySet.java:86)
at com.aspose.words.do.a(DocPropertiesFiler.java:231)
at com.aspose.words.io.kx(DocWriter.java:146)
at com.aspose.words.io.a(DocWriter.java:27)
at com.aspose.words.Document.a(Document.java:1494)
at com.aspose.words.Document.save(Document.java:907)
at com.aspose.words.Document.save(Document.java:881)

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I managed to reproduce the problem on my side. You will be notified as soon as the issue is resolved.

Maybe you can just specify string as a value of the property:

Document doc = new Document("C:\\Temp\\in.doc");

doc.getCustomDocumentProperties().get("prop_date").setValue("2.1.2010");

doc.save("C:\\Temp\\out.doc");

Best regards.

Thanks,

Setting a string as a value will change the DocProperty type as text. I need to retain the date type DocProperty.

ARi

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. In this case you should wait for a fix. I will notify you as soon as the issues is resolved.

Best regards.

Hi,

We should be going in production shortly with our Aspose.Words implementation. I would like to know when the fix for this issue will be available. Could you provide some estimate please?

ARi

Hi

Thanks for your inquiry. This issue is already fixed in the latest version of Aspose.Words for Java (4.0.1). You can download it from here:
http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/category1378.aspx


Best regards,

The issues you have found earlier (filed as 13293) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.