views:

85

answers:

1

Hi,

I have a Excel COM addin which reads the CustomDocumentProperties section of a workbook.

This is how I access a particular entry from the CustomDocumentProperties section

DocumentProperties docProperties = (DocumentProperties)
                    xlWorkbook.CustomDocumentProperties;

            docProperty = docProperties[propName];

The problem is when the CustomDocumentProperties contain more than 8000 entries, the performance of this code is really bad. I have ran CPU profiler and it showed that the following line takes more than a minute.

docProperty = docProperties[propName];

Does anyone know how to improve the performance of accessing DocumentProperties?

Thanks!

+1  A: 

Hi raghvendra,

I doubt that there is anything that you could do to improve the performance of the document properties. I believe that it is implemented as a simple list -- not as a dictionary or hash table. In fact, I don't believe that the list is sorted, so with 8000 entries, on average half of them, or 4000, would have to be accessed in order to find the property that you are looking for.

You might consider not using the CustomDocumentProperties as a dictionary. Instead, you might try putting all 8000 of your entries into a custom dictionary, serializing it, and then adding the entire serialized dictionary to the CustomDocumentProperties as a single entry. So to use it, you would access the CustomDocumentProperties, deserialize the dictionary, and then use it repeatedly. When done, if there were any changes to the dictionary, you would have to re-serialize it and save it back to the CustomDocumentProperties, which you would probably only want to do once -- for example, just before saving your workbook. (You might want to put code to re-serialize and save your custom dictionary to the CustomDocumentProperties within the Workbook.BeforeSave event.)

-- Mike

(By the way, you might want to work on your accept rate. 14% is very low. Is it really the case that only 1 out of 7 of your questions has been successfully answered??)

Mike Rosenblum
Thanks Mike for your suggestion, its a good thing to try out.Regarding accept rate maybe its combination of not getting answer and my indiscipline.
raghvendra