This module uses the DevExpress Spreadsheet API to read workbook metadata from Excel documents. You can process the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.
Select Read Workbook Properties to extract standard metadata such as title, author, subject, and keywords. Select Read Custom Workbook Properties to extract user-defined custom properties specific to the document.
Click Read Workbook Metadata to analyze the document and download a file with workbook metadata.
Select a Document
InvestmentPortfolio.xlsx
using DevExpress.Spreadsheet;
using System.Text;
string ReadDocumentProperties(Stream inputStream, bool readDocumentProperties, bool readCustomProperties) {
var output = new StringBuilder();
using var workbook = new Workbook();
var documentProperties = workbook.LoadDocumentProperties(inputStream);
if(readDocumentProperties) {
// Main Properties
output.AppendLine("MAIN DOCUMENT PROPERTIES:");
output.AppendLine(new string('-', 30));
output.AppendLine($"Application: {documentProperties.Application ?? ""}");
output.AppendLine($"Author: {documentProperties.Author ?? ""}");
output.AppendLine($"Category: {documentProperties.Category ?? ""}");
output.AppendLine($"Company: {documentProperties.Company ?? ""}");
output.AppendLine($"Content Status: {documentProperties.ContentStatus ?? ""}");
output.AppendLine($"Created Date: {documentProperties.Created.ToString("yyyy-MM-dd HH:mm:ss")}");
output.AppendLine($"Description: {documentProperties.Description ?? ""}");
output.AppendLine($"Document Revision: {documentProperties.DocumentRevision ?? ""}");
output.AppendLine($"Document Version: {documentProperties.DocumentVersion ?? ""}");
output.AppendLine($"Keywords: {documentProperties.Keywords ?? ""}");
output.AppendLine($"Last Modified By: {documentProperties.LastModifiedBy ?? ""}");
output.AppendLine($"Manager: {documentProperties.Manager ?? ""}");
output.AppendLine($"Modified Date: {documentProperties.Modified.ToString("yyyy-MM-dd HH:mm:ss")}");
output.AppendLine($"Printed Date: {documentProperties.Printed.ToString("yyyy-MM-dd HH:mm:ss")}");
output.AppendLine($"Security: {documentProperties.Security.ToString() ?? ""}");
output.AppendLine($"Subject: {documentProperties.Subject ?? ""}");
output.AppendLine($"Title: {documentProperties.Title ?? ""}");
output.AppendLine($"Version: {documentProperties.Version ?? ""}");
output.AppendLine();
}
if(readCustomProperties) {
var customProperties = documentProperties.Custom;
output.AppendLine("CUSTOM PROPERTIES:");
output.AppendLine(new string('-', 30));
// Check if there are any custom properties
var hasCustomProperties = false;
var customPropsList = new List<string>();
foreach(string propName in customProperties.Names) {
hasCustomProperties = true;
var propValue = customProperties[propName];
var valueStr = propValue?.ToString() ?? "";
var typeStr = propValue?.GetType().Name ?? "String";
customPropsList.Add($"{propName}: {valueStr} ({typeStr})");
}
if(!hasCustomProperties)
output.AppendLine("No custom properties found.");
else
foreach(var customProp in customPropsList)
output.AppendLine(customProp);
output.AppendLine();
}
return output.ToString();
}