Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
de63e3c
Add example: load-a-workbook-and-retrieve-the-title-builtin-property-…
agent-aspose-cells-examples May 20, 2026
8a38f25
Add example: open-an-excel-file-and-read-the-author-builtin-property-…
agent-aspose-cells-examples May 20, 2026
b23219c
Add example: instantiate-a-workbook-and-obtain-the-documentversion-bu…
agent-aspose-cells-examples May 20, 2026
2acd493
Add example: load-a-spreadsheet-and-read-the-language-builtin-propert…
agent-aspose-cells-examples May 20, 2026
0d01902
Add example: open-a-workbook-and-query-the-scalecrop-builtin-property…
agent-aspose-cells-examples May 20, 2026
49e6d31
Add example: load-an-excel-document-and-inspect-the-linksuptodate-bui…
agent-aspose-cells-examples May 20, 2026
51df1a0
Add example: create-a-workbook-and-set-the-title-builtin-property-to-…
agent-aspose-cells-examples May 20, 2026
308c007
Add example: open-a-file-and-update-the-author-builtin-property-with-…
agent-aspose-cells-examples May 20, 2026
6d47bd1
Add example: load-a-workbook-and-assign-the-documentversion-builtin-p…
agent-aspose-cells-examples May 20, 2026
c32bc63
Add example: open-a-spreadsheet-and-set-the-language-builtin-property…
agent-aspose-cells-examples May 20, 2026
1086d29
Add example: instantiate-a-workbook-and-enable-the-scalecrop-builtin-…
agent-aspose-cells-examples May 20, 2026
520fe73
Add example: load-a-workbook-and-disable-the-linksuptodate-builtin-pr…
agent-aspose-cells-examples May 20, 2026
b2110d4
Add example: open-a-workbook-and-add-a-custom-property-processeddate-…
agent-aspose-cells-examples May 20, 2026
c9e47d3
Add example: load-an-excel-file-and-create-a-custom-property-projecti…
agent-aspose-cells-examples May 20, 2026
8c31f2e
Add example: open-a-workbook-and-add-a-custom-boolean-property-isrevi…
agent-aspose-cells-examples May 20, 2026
8ce0a16
Add example: load-a-workbook-locate-the-custom-property-projectid-and…
agent-aspose-cells-examples May 20, 2026
164518f
Add example: open-a-spreadsheet-and-remove-the-custom-property-isrevi…
agent-aspose-cells-examples May 20, 2026
fce4da8
Add example: load-a-workbook-and-check-whether-a-custom-property-clie…
agent-aspose-cells-examples May 20, 2026
4d370b4
Add example: open-a-file-and-iterate-through-all-builtin-properties-l…
agent-aspose-cells-examples May 20, 2026
027aeb7
Add example: load-a-workbook-and-enumerate-custom-properties-exportin…
agent-aspose-cells-examples May 20, 2026
cf41f18
Add example: open-a-spreadsheet-and-filter-custom-properties-by-datet…
agent-aspose-cells-examples May 20, 2026
e46baa8
Add example: instantiate-two-workbooks-and-copy-all-document-properti…
agent-aspose-cells-examples May 20, 2026
c0d8580
Add example: load-a-template-workbook-and-clone-its-builtin-propertie…
agent-aspose-cells-examples May 20, 2026
d9623a8
Add example: open-a-workbook-and-validate-that-documentversion-matche…
agent-aspose-cells-examples May 20, 2026
aa329a8
Add example: load-an-excel-file-and-verify-that-language-contains-a-v…
agent-aspose-cells-examples May 20, 2026
cda996c
Add example: open-a-workbook-set-scalecrop-to-true-and-ensure-the-fla…
agent-aspose-cells-examples May 20, 2026
1bf7780
Add example: instantiate-a-workbook-and-deliberately-access-a-nonexis…
agent-aspose-cells-examples May 20, 2026
88b878f
Add example: load-a-spreadsheet-and-use-trycatch-to-safely-read-a-cus…
agent-aspose-cells-examples May 20, 2026
58c6be9
Add example: open-a-workbook-and-confirm-that-application-metadata-fi…
agent-aspose-cells-examples May 20, 2026
958d600
Add example: load-a-workbook-modify-several-properties-and-save-the-f…
agent-aspose-cells-examples May 20, 2026
dbe5fbf
Add example: open-a-workbook-update-document-properties-and-export-th…
agent-aspose-cells-examples May 20, 2026
514562e
Add example: instantiate-a-workbook-adjust-builtin-properties-and-sav…
agent-aspose-cells-examples May 20, 2026
f6af576
Add example: batch-process-all-workbooks-in-a-folder-setting-each-fil…
agent-aspose-cells-examples May 20, 2026
32626a3
Add example: iterate-through-a-directory-of-excel-files-and-update-ev…
agent-aspose-cells-examples May 20, 2026
e91f6ac
Add example: create-a-utility-that-reads-custom-properties-from-a-wor…
agent-aspose-cells-examples May 20, 2026
a71fb6b
Add example: generate-a-summary-report-that-aggregates-builtin-proper…
agent-aspose-cells-examples May 20, 2026
0fc5275
Add example: validate-that-the-title-builtin-property-is-not-empty-be…
agent-aspose-cells-examples May 20, 2026
472eacf
Add example: use-documentpropertycollection-to-retrieve-the-total-cou…
agent-aspose-cells-examples May 20, 2026
2a13a0c
Add example: compare-custom-property-sets-between-two-workbooks-and-g…
agent-aspose-cells-examples May 20, 2026
29e72bc
Add example: remove-all-custom-properties-whose-names-start-with-the-…
agent-aspose-cells-examples May 20, 2026
14745d2
Add example: add-a-custom-property-containing-an-array-of-string-tags…
agent-aspose-cells-examples May 20, 2026
aeadf75
Add example: set-the-builtin-comments-property-to-a-multiline-descrip…
agent-aspose-cells-examples May 20, 2026
b55760d
Add example: read-the-keywords-builtin-property-and-use-its-values-to…
agent-aspose-cells-examples May 20, 2026
28f4685
Add example: validate-that-scalecrop-cannot-be-enabled-when-the-workb…
agent-aspose-cells-examples May 20, 2026
a24c4df
Add example: log-a-warning-whenever-code-attempts-to-modify-applicati…
agent-aspose-cells-examples May 20, 2026
c5d9178
Add example: create-a-unit-test-that-adds-a-custom-property-saves-the…
agent-aspose-cells-examples May 20, 2026
5860689
Update agents.md
agent-aspose-cells-examples May 31, 2026
db00179
Resolve index.json merge conflicts with release/26.5.0
agent-aspose-cells-examples May 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Aspose.Cells;
using Aspose.Cells.Properties;

class Program
{
static void Main()
{
// Create a new workbook
Workbook workbook = new Workbook();

// Define an array of tags to categorize the workbook content
string[] tags = new string[] { "Finance", "Quarterly", "Confidential" };

// Convert the string array to a single string (comma‑separated) for storage
string tagsValue = string.Join(",", tags);

// Add a custom document property named "Tags" with the serialized array value
workbook.CustomDocumentProperties.Add("Tags", tagsValue);

// Save the workbook to a file
workbook.Save("WorkbookWithTags.xlsx");
}
}
111 changes: 111 additions & 0 deletions document-properties/agents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
category: document-properties
framework: .NET
parent: ../agents.md
version: v2
---

# Persona

You are a C# developer specializing in document properties and metadata management using Aspose.Cells for .NET.

Generate simple, correct, production-quality examples that demonstrate ONE document-properties scenario at a time.

---

# Scope

- Standalone .cs examples
- One operation per example
- Fully runnable with dotnet run
- No external dependencies

---

# Required Namespaces

using System;
using Aspose.Cells;

---

# Key APIs

- BuiltInDocumentPropertyCollection
- CustomDocumentPropertyCollection
- Workbook.BuiltInDocumentProperties
- Workbook.CustomDocumentProperties

---

# Common Pattern

1. Create workbook
2. Access document properties
3. Add, read, update, or remove properties
4. Save workbook
5. Print success message

---

# Document Properties Rules

- Use BuiltInDocumentProperties for standard metadata
- Use CustomDocumentProperties for user-defined metadata
- Use correct property data types
- One example = one document-properties operation

---

# Input Strategy

- Do NOT rely on external XLSX files
- Create workbook programmatically
- Keep examples self-contained

---

# Output Rules

- Always generate output.xlsx
- Ensure workbook is saved successfully
- Output files are written to the working directory

---

# Common Tasks

- Read built-in properties
- Add custom property
- Update property value
- Remove property
- Enumerate document properties

---

# Common Mistakes

❌ var workbook = new Workbook();
✅ Workbook workbook = new Workbook();

❌ Store all values as strings
✅ Use appropriate property types

❌ Workbook workbook = new Workbook("input.xlsx");
✅ Workbook workbook = new Workbook();

---

# Code Simplicity

- Keep examples concise
- Avoid unnecessary abstractions

---

# General Rules

Refer to the root agents.md for:
- Boundaries
- Testing requirements
- Build and run instructions
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.IO;
using Aspose.Cells;

namespace BatchSetLanguageApp
{
class BatchSetLanguage
{
static void Main()
{
try
{
// Folder containing the workbooks to process
string folderPath = @"C:\Path\To\Folder";

// Verify folder exists
if (!Directory.Exists(folderPath))
{
Console.WriteLine($"Folder not found: {folderPath}");
return;
}

// Retrieve all files in the folder
string[] allFiles = Directory.GetFiles(folderPath, "*.*", SearchOption.TopDirectoryOnly);

foreach (string filePath in allFiles)
{
try
{
// Process only supported Excel formats
string ext = Path.GetExtension(filePath).ToLowerInvariant();
if (ext != ".xls" && ext != ".xlsx" && ext != ".xlsm" && ext != ".xlsb" && ext != ".csv")
continue;

// Ensure the file exists before loading
if (!File.Exists(filePath))
{
Console.WriteLine($"File not found: {filePath}");
continue;
}

// Load the workbook (lifecycle rule: load)
Workbook workbook = new Workbook(filePath);

// Set the built‑in document property "Language" to "en-GB"
workbook.BuiltInDocumentProperties.Language = "en-GB";

// Save the workbook back to the same file (lifecycle rule: save)
workbook.Save(filePath);
}
catch (Exception ex)
{
Console.WriteLine($"Error processing '{filePath}': {ex.Message}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error: {ex.Message}");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.IO;
using Aspose.Cells;
using Aspose.Cells.Properties;

class Program
{
static void Main()
{
// Paths to the two workbooks to compare
string workbookPath1 = "Workbook1.xlsx";
string workbookPath2 = "Workbook2.xlsx";

// Load the workbooks (uses the Workbook(string) constructor)
Workbook wb1 = new Workbook(workbookPath1);
Workbook wb2 = new Workbook(workbookPath2);

// Retrieve the custom document property collections
CustomDocumentPropertyCollection props1 = wb1.CustomDocumentProperties;
CustomDocumentPropertyCollection props2 = wb2.CustomDocumentProperties;

// Prepare a list to hold audit messages
List<string> differences = new List<string>();

// Helper: create a dictionary for quick lookup of properties by name
var dict2 = new Dictionary<string, DocumentProperty>(StringComparer.OrdinalIgnoreCase);
foreach (DocumentProperty p in props2)
{
dict2[p.Name] = p;
}

// Check for removed or modified properties
foreach (DocumentProperty p1 in props1)
{
if (!dict2.TryGetValue(p1.Name, out DocumentProperty p2))
{
differences.Add($"Removed: '{p1.Name}' with value '{p1.Value}'");
}
else
{
// Compare values (null‑safe)
string val1 = p1.Value?.ToString() ?? string.Empty;
string val2 = p2.Value?.ToString() ?? string.Empty;
if (!val1.Equals(val2, StringComparison.Ordinal))
{
differences.Add($"Modified: '{p1.Name}' changed from '{val1}' to '{val2}'");
}
// Remove the entry so that later we can detect additions
dict2.Remove(p1.Name);
}
}

// Remaining entries in dict2 are properties that exist only in workbook2 (added)
foreach (var kvp in dict2)
{
DocumentProperty p = kvp.Value;
differences.Add($"Added: '{p.Name}' with value '{p.Value}'");
}

// Output the differences to console
Console.WriteLine("Custom Document Property Differences:");
foreach (string diff in differences)
{
Console.WriteLine(diff);
}

// Optionally, write the audit report to a text file
string reportPath = "CustomPropertiesAudit.txt";
File.WriteAllLines(reportPath, differences);
Console.WriteLine($"Audit report saved to: {reportPath}");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.IO;
using System.Linq;
using Aspose.Cells;
using Aspose.Cells.Properties;

namespace AsposeCellsTests
{
public class CustomPropertyPersistenceTests
{
public void Run()
{
// Arrange: create a workbook and add a custom property
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
const string propertyName = "TestProp";
const string propertyValue = "TestValue";
sheet.CustomProperties.Add(propertyName, propertyValue);

// Temporary file for saving the workbook
string tempFile = Path.Combine(Path.GetTempPath(), $"CustomProp_{Guid.NewGuid()}.xlsx");

try
{
// Act: save the workbook
workbook.Save(tempFile);

// Ensure the file exists before loading
if (!File.Exists(tempFile))
throw new FileNotFoundException("Saved workbook not found.", tempFile);

// Load the workbook back
Workbook loadedWorkbook = new Workbook(tempFile);
Worksheet loadedSheet = loadedWorkbook.Worksheets[0];

// Retrieve the custom property
CustomProperty loadedProperty = loadedSheet.CustomProperties
.FirstOrDefault(p => p.Name == propertyName);

// Assert: property exists and value matches
if (loadedProperty == null)
throw new InvalidOperationException("Custom property was not found after loading the workbook.");

if (!propertyValue.Equals(loadedProperty.Value?.ToString()))
throw new InvalidOperationException("Custom property value did not persist correctly.");

Console.WriteLine("Custom property persisted successfully.");
}
catch (Exception ex)
{
// Runtime safety: log and rethrow
Console.WriteLine($"Error: {ex.Message}");
throw;
}
finally
{
// Cleanup: delete temporary file if it exists
if (File.Exists(tempFile))
{
try { File.Delete(tempFile); } catch { /* ignore cleanup errors */ }
}
}
}
}

class Program
{
static void Main()
{
try
{
var test = new CustomPropertyPersistenceTests();
test.Run();
}
catch (Exception ex)
{
Console.WriteLine($"Test failed: {ex.Message}");
}
}
}
}
Loading