Adding custom property to XLS and DOC files visible in the Document Information Panel in .NET

Hi,

I am trying to save some custom properties into word/excel documents. I have already successfully done the addition with .docx format files using



doc.CustomDocumentProperties.Add(“ContentTypeId”, contentTypeValue);



for the content type and



CustomXmlPart myXml1 = new CustomXmlPart();

byte[] b1 = Encoding.UTF8.GetBytes(xmlString);

myXml1.Data = b1;

doc.CustomXmlParts.Add(myXml1);



for content type’s fields(custom properties).



This works as intended, I can see the newly added fields in the Document information Panel and all is good.



But the issue starts with the Xlsx,doc, docx formats.



XLSX: I can save the properties into the workbook and see them in Document information panel, however there is no way that I can specify what is the type of each field.This poses an issue since a date time field would be shown as a text field and no format validations will be done on the office client before being sent to the server. As far as I can tell, this is how custom properties are added in xlsx.



//CONTENT TYPE ID

doc.CustomDocumentProperties.Add(“ContentTypeId”, contentTypeValue);

//Fields

doc.ContentTypeProperties.Add(customPropertyName, customPropertyValue);// Only name and value, no type!



Refer to the document number 3 in the attachment for the output of xlsx with custom fields from aspose.cells and refer to document number 6 to see how it should be ideally.



XLS and Doc: Since xls and doc do not follow xml based structure, the custom properties are all added with just

doc.CustomDocumentProperties.Add(“ContentTypeId”, contentTypeValue);

doc.CustomDocumentProperties.Add(customPropertyName, customPropertyValue);



I can see that the properties are added, and I can right click the file and check the custom tab for the properties but none of these properties show up in the document information panel. This would work if I open the document with office 2003 but any other version shows no sign of properties from within the document( hence no way to modify them).

Refer to document 1,2 in the attachment for the doc and xls file with custom fields added from aspose.

Refer to 4,5 for the doc and xls with custom fields in their ideal condition( you can see the fields in the document information panel )

I hope I have explained the issue I have faced properly, if there is any questions please let me know.

I would like to know if there already is a better way to achieve what I am trying to do , or is this a unexpected behavior that needs to be fixed. Kindly advise.

With best regards,

Shahzad Naseem

For reference sake, please find attached a word document (docx) with custom properties successfully added via aspose complete with the field types.

Hi Shahzad,

Thanks for your posting and using Aspose.Cells.

Please also provide screenshots with red circles explaining and highlighting your issue in detail so that we could understand your requirements precisely and log it in our database.

Please also let us know if your issue is related to Aspose.Words too. In that case, please post your issue in Aspose.Words forum so that Aspose.Words could also look into this issue at their end.

Thanks for your cooperation.

Hi Please find attached the images as requested explaining the issue.



“Ideal XLS file created by sharepoint.png” shows how the desired end result should be.



“xls file properties with no custom fields in DIP.png” shows what I get when I pass a document with no custom properties to Aspose.



“xlsx All added fields are Text fields.png” shows the issue with xlsx file that do not allow the user to define the Type of field while adding custom fields.



“Custom property with datetime type.png” Shows how the xlsx should be like ideally. It would contain a datetime field that would be validated client side if the user inputs date in wrong format before sending it to the server.



Also I will create a post in the words section of Aspose for the same issues related to .doc format

Hi Shahzad,

Thanks for your posting and using Aspose.Cells.

I was able to successfully add Date type custom document property using the following code.

I have attached the output Excel file and screenshot for your reference. I tested this issue with the latest version: Aspose.Cells
for .NET v8.3.1.3
.

C#


Workbook workbook = new Workbook(FileFormatType.Xlsx);


DateTime dt = DateTime.Parse(“20-dec-2014”);


workbook.CustomDocumentProperties.Add(“MyDate”, dt);


workbook.Save(“output.xlsx”);


Hi,

Unfortunately this wont work if I open this in Office 2013 or 2010. I can not see the properties in the Document Information panel. The only way I can make them appear is using

workbook.ContentTypeProperties.Add(strName, strValues)

and this does not accept any value that is not a string. Hence the issue with dateTime.

To view the Document Information panel, click the properties in the image you have given and click show document panel. Ideally that should show the properties added as you can see in the sample excel document I have provided in a previous post.

To give a better point of view, I am trying to make something that allows users to retrieve documents from a sharepoint like document storage web server.



In order to index documents properly, we need to add certain custom fields to documents that the user can edit via the document information panel. Later while indexing these properties will be read from the document using Aspose and archived.



And in case of older documents that were archived manually without the document containing the custom fields, we need to add them using Aspose hence why I have encountered this issue.



So for my needs, 2 things are very important,

Reading properties from a document using Aspose and Writing into a document that doesn’t have any.



Word with .docx format is working completely as I want it to using aspose. I can read and write properties into a docx without any issues.

Hi Shahzad,

Thanks for your explanations and using Aspose.Cells.

We were able to observe this issue after executing the following sample code and found, Aspose.Cells creates DateTime values as Text. There should be a mechanism to specify the type of the contents added using the Workbook.ContentTypeProperties.Add() method.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43276 - Workbook.ContentTypeProperties.Add(name, value, type) is needed

I have attached the output Excel file generated by the code and screenshots illustrating this issue for a reference.

C#

Workbook workbook = new Workbook(FileFormatType.Xlsx);


//Here the Date is in string type. User wants to specify Date in date type.

workbook.ContentTypeProperties.Add(“MK31”, “20-Dec-2014”);

workbook.ContentTypeProperties.Add(“MK32”, “20-Dec-2014”);


workbook.Save(“output.xlsx”);

Hi ,
thanks for taking the time to help. I would like to still point out to the second issue mentioned in the first post regarding xls format documents not showing the custom properties in the document via the document information panel. Please have a look into that as well.
regards,
shahzad

Hi Shahzad,

Thanks for your posting and using Aspose.Cells.

We were able to observe your second issue. We have tested this issue with the following sample code and found content type properties are visible in DIP when the workbook is saved in XLSX format but when it is saved in XLS format, they are not visible.

Please also let me know how to add content type properties manually using Microsoft Excel.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43279 - Content Type Properties are not shown inside DIP (Document Information Panel) in XLS format

I have attached the output Excel files generated by this code and screenshot highlighting this issue for a reference.

C#

Workbook workbook = new Workbook();


workbook.ContentTypeProperties.Add(“MK31”, “Simple Testing31”);

workbook.ContentTypeProperties.Add(“MK32”, “Simple Testing32”);


workbook.Save(“output.xls”);

workbook.Save(“output.xlsx”);


“Please also let me know how to add content type properties manually using Microsoft Excel.”

I am adding these properties through a document management server like sharepoint. While saving the new document asks me to select the content type and then shows the DIP with the custom fields to be filled in.

Hi Shahzad,

Thanks for letting me know it.

Hi Shahzad,

Thanks for using Aspose.Cells.

Please try the latest fix Aspose.Cells
for .NET v8.3.2.7
, we have supported adding server document properties to xls file and Workbook.ContentTypeProperties.Add(name, value, type) method.

The issues you have found earlier (filed as CELLSNET-43279;CELLSNET-43276) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.