Copying Document Properties when using Aspose.Cells.Worksheet.Copy() in .NET

Hi there,

When using Aspose.Cells.Worksheet.Copy(), I noticed that it does not copy over BuiltInDocumentProperties. The following is an example of code where this happens:

Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
wb.BuiltInDocumentProperties.Author = "John Doe";

Workbook wb2 = new Workbook();
wb2.Copy(wb);

Console.WriteLine("Author: " + wb2.BuiltInDocumentProperties.Author);

In the above example, wb2.BuiltInDocumentProperties.Author is an empty string. Is this normal behaviour for the Copy(…) function? If it is, are there any recommendation for copying over the rest of the properties?

Thank you kindly. If further details are needed, please let me know.

@danilolekovic,

Please note, the built-in document properties values are stored at workbook level and when you copy/merge from source workbook into destination workbook, these attributes’ values are not copied. In the copying operation, the properties values of the destination workbook are always intact. Since you have not specified the value of the Author for the second workbook, so it will remain blank/empty. To cope with it, you may try to add a line (see the line in bold) for your requirements:
e.g.
Sample code:

Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
wb.BuiltInDocumentProperties.Author = “John Doe”;

Workbook wb2 = new Workbook();
wb2.Copy(wb);

wb2.BuiltInDocumentProperties.Author = wb.BuiltInDocumentProperties.Author;

Console.WriteLine("Author: " + wb2.BuiltInDocumentProperties.Author);

Hope, this helps a bit.

1 Like