Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
6e01f5f
Add example: open-an-xlsx-workbook-from-a-local-file-path-using-the-d…
agent-aspose-cells-examples May 21, 2026
4514ba1
Add example: load-a-legacy-xls-file-from-a-stream-object-to-process-i…
agent-aspose-cells-examples May 21, 2026
0567fce
Add example: instantiate-loadoptions-with-loaddataonly-set-true-to-im…
agent-aspose-cells-examples May 21, 2026
164ac77
Add example: create-a-custom-loadfilter-that-skips-invisible-workshee…
agent-aspose-cells-examples May 21, 2026
4eb8cbe
Add example: open-an-encrypted-excel-workbook-by-providing-the-passwo…
agent-aspose-cells-examples May 21, 2026
87d3460
Add example: enable-memorypreferences-in-loadoptions-to-prevent-outof…
agent-aspose-cells-examples May 21, 2026
a182912
Add example: use-lightcells-api-with-loadoptions-to-process-a-large-d…
agent-aspose-cells-examples May 21, 2026
f4befea
Add example: interrupt-a-longrunning-workbook-load-operation-by-confi…
agent-aspose-cells-examples May 21, 2026
e0e758e
Add example: calculate-all-formulas-in-the-loaded-workbook-by-invokin…
agent-aspose-cells-examples May 21, 2026
63e7034
Add example: open-an-excel-95-file-by-setting-loadoptionsversion-to-e…
agent-aspose-cells-examples May 21, 2026
10592a9
Add example: load-an-excel-972003-workbook-by-assigning-loadoptionsve…
agent-aspose-cells-examples May 21, 2026
77331f4
Add example: automatically-detect-the-workbook-format-by-passing-only…
agent-aspose-cells-examples May 21, 2026
91a26fa
Add example: open-a-workbook-from-a-byte-array-by-wrapping-it-in-a-me…
agent-aspose-cells-examples May 21, 2026
7b7923b
Add example: load-a-workbook-from-an-http-response-stream-to-process-…
agent-aspose-cells-examples May 21, 2026
e0069e7
Add example: load-only-defined-names-from-a-workbook-by-setting-loado…
agent-aspose-cells-examples May 21, 2026
d2e6788
Add example: open-a-workbook-with-formulas-preserved-but-not-calculat…
agent-aspose-cells-examples May 21, 2026
cae479b
Add example: read-numeric-cells-as-text-in-load-by-enabling-the-loado…
agent-aspose-cells-examples May 21, 2026
126e452
Add example: open-a-workbook-from-a-network-share-path-while-ensuring…
agent-aspose-cells-examples May 21, 2026
7106a7d
Add example: open-an-xlsb-binary-workbook-by-specifying-the-file-path…
agent-aspose-cells-examples May 21, 2026
9dd144e
Add example: process-a-collection-of-excel-files-in-a-directory-by-it…
agent-aspose-cells-examples May 21, 2026
a2ecc09
Add example: open-a-workbook-with-password-protection-and-then-remove…
agent-aspose-cells-examples May 21, 2026
f196444
Add example: enable-the-useoptimizedmemory-flag-in-loadoptions-to-imp…
agent-aspose-cells-examples May 21, 2026
5306e86
Add example: load-a-workbook-while-ignoring-all-external-links-by-set…
agent-aspose-cells-examples May 21, 2026
d22d830
Add example: open-a-workbook-and-retrieve-the-list-of-defined-names-w…
agent-aspose-cells-examples May 21, 2026
b4a5219
Add example: configure-loadoptions-to-load-only-the-workbooks-custom-…
agent-aspose-cells-examples May 21, 2026
4adb405
Add example: open-a-workbook-from-a-zip-archive-by-extracting-the-str…
agent-aspose-cells-examples May 21, 2026
5cb32d9
Add example: load-a-workbook-with-the-option-to-preserve-original-cel…
agent-aspose-cells-examples May 21, 2026
079bc7c
Add example: apply-a-loadfilter-that-selects-worksheets-based-on-a-us…
agent-aspose-cells-examples May 21, 2026
5e7d0f4
Add example: open-a-workbook-and-immediately-export-its-visible-sheet…
agent-aspose-cells-examples May 21, 2026
4978c4d
Add example: load-only-the-summary-and-data-worksheets-from-the-file-…
agent-aspose-cells-examples May 21, 2026
aae80c2
Add example: exclude-hidden-worksheets-during-load-by-configuring-loa…
agent-aspose-cells-examples May 21, 2026
604c6e4
Add example: filter-out-defined-names-starting-with-_-during-load-and…
agent-aspose-cells-examples May 21, 2026
70ab994
Add example: load-only-chart-objects-by-setting-loadoptionsloadfilter…
agent-aspose-cells-examples May 21, 2026
612d731
Add example: implement-an-interruptmonitor-that-aborts-workbook-loadi…
agent-aspose-cells-examples May 21, 2026
39bd0e7
Add example: create-a-custom-iwarningcallback-class-that-logs-each-lo…
agent-aspose-cells-examples May 21, 2026
ad45d28
Add example: load-a-partially-corrupted-excel-file-while-capturing-wa…
agent-aspose-cells-examples May 21, 2026
3f51d9c
Add example: batch-load-multiple-workbooks-using-the-same-loadoptions…
agent-aspose-cells-examples May 21, 2026
3fb1958
Add example: enumerate-all-loaded-worksheets-after-opening-a-workbook…
agent-aspose-cells-examples May 21, 2026
d7bbb38
Add example: read-cell-values-with-culturespecific-number-formatting-…
agent-aspose-cells-examples May 21, 2026
9187df9
Add example: validate-that-required-worksheets-invoice-and-summary-ex…
agent-aspose-cells-examples May 21, 2026
e21db06
Add example: extract-all-formulas-from-loaded-worksheets-and-store-th…
agent-aspose-cells-examples May 21, 2026
44e3716
Add example: convert-a-loaded-workbook-to-pdf-while-an-interruptmonit…
agent-aspose-cells-examples May 21, 2026
8243aa0
Add example: export-a-loaded-workbook-to-html-and-use-interruptmonito…
agent-aspose-cells-examples May 21, 2026
3454d32
Add example: save-the-workbook-back-to-xlsx-format-after-modifying-ce…
agent-aspose-cells-examples May 21, 2026
1343344
Add example: use-lightcells-to-iterate-rows-and-write-each-rows-data-…
agent-aspose-cells-examples May 21, 2026
447b40a
Add example: load-a-workbook-while-excluding-chart-objects-then-verif…
agent-aspose-cells-examples May 21, 2026
6c86ee8
Add example: capture-load-warnings-about-unsupported-features-and-wri…
agent-aspose-cells-examples May 21, 2026
24a20cc
Add example: configure-interruptmonitor-to-abort-workbook-loading-aft…
agent-aspose-cells-examples May 21, 2026
4e1104c
Add example: read-numeric-cells-from-an-applegenerated-spreadsheet-ca…
agent-aspose-cells-examples May 21, 2026
1558c7b
Add example: load-only-the-first-three-worksheets-by-setting-loadopti…
agent-aspose-cells-examples May 21, 2026
d62028f
Add example: include-worksheets-matching-the-pattern-q0-9-using-loado…
agent-aspose-cells-examples May 21, 2026
079db57
Add example: set-loadoptionsloadfilter-to-load-only-data-cells-skippi…
agent-aspose-cells-examples May 21, 2026
ca5a880
Add example: log-warnings-about-unsupported-formulas-to-a-file-by-imp…
agent-aspose-cells-examples May 21, 2026
b0ab006
Add example: copy-columns-a-through-d-from-the-source-worksheet-to-a-…
agent-aspose-cells-examples May 21, 2026
cd6420c
Add example: filter-rows-where-column-c-equals-active-while-streaming…
agent-aspose-cells-examples May 21, 2026
975b5eb
Add example: set-pdfsaveoptionscompressionlevel-to-high-when-saving-t…
agent-aspose-cells-examples May 21, 2026
0dcb467
Add example: enable-htmlsaveoptionsexportimagesasbase64-to-embed-imag…
agent-aspose-cells-examples May 21, 2026
ad7c069
Add example: limit-pdf-output-to-the-first-ten-pages-by-setting-pdfsa…
agent-aspose-cells-examples May 21, 2026
73e9df0
Add example: set-htmlsaveoptionspagetitle-to-the-workbooks-filename-e…
agent-aspose-cells-examples May 21, 2026
1d135c2
Add example: load-an-xlsx-workbook-using-lightcells-api-while-applyin…
agent-aspose-cells-examples May 21, 2026
29af719
Add example: configure-memorysettingmemorypreference-to-low-before-op…
agent-aspose-cells-examples May 21, 2026
7466fa1
Add example: apply-filterdefinednames-while-loading-a-workbook-to-inc…
agent-aspose-cells-examples May 21, 2026
a09f4b0
Add example: use-interruptmonitor-to-abort-workbook-loading-if-proces…
agent-aspose-cells-examples May 21, 2026
3eaf239
Add example: retrieve-and-log-warning-messages-after-loading-a-workbo…
agent-aspose-cells-examples May 21, 2026
4d9f32e
Add example: exclude-hidden-rows-during-workbook-loading-by-configuri…
agent-aspose-cells-examples May 21, 2026
b2c3078
Add example: read-numeric-cell-values-with-lightcells-api-and-store-t…
agent-aspose-cells-examples May 21, 2026
d029cc2
Add example: save-a-workbook-as-xlsx-while-specifying-a-custom-tempor…
agent-aspose-cells-examples May 21, 2026
6858e15
Add example: load-a-passwordprotected-xlsx-file-using-lightcells-api-…
agent-aspose-cells-examples May 21, 2026
03717f9
Add example: filter-out-all-pictures-from-a-workbook-during-loading-t…
agent-aspose-cells-examples May 21, 2026
4b8f939
Add example: use-lightcells-api-to-export-cell-values-from-a-workbook…
agent-aspose-cells-examples May 21, 2026
efe721a
Add example: apply-filterdatakind-to-load-only-numeric-and-date-cells…
agent-aspose-cells-examples May 21, 2026
f21eda6
Add example: configure-lightcells-to-process-cells-in-rowmajor-order-…
agent-aspose-cells-examples May 21, 2026
be1e3b4
Add example: save-a-workbook-with-a-specific-printer-paper-size-setti…
agent-aspose-cells-examples May 21, 2026
e7b0a6d
Add example: load-a-workbook-without-charts-by-applying-filterobjects…
agent-aspose-cells-examples May 21, 2026
2cbac8f
Add example: implement-lightcellsdatahandler-to-convert-all-text-cell…
agent-aspose-cells-examples May 21, 2026
3987dd6
Add example: set-memorysettingmemorypreference-to-normal-for-a-small-…
agent-aspose-cells-examples May 21, 2026
834f910
Add example: use-lightcells-api-to-copy-data-from-one-worksheet-to-an…
agent-aspose-cells-examples May 21, 2026
2d95c85
Add example: load-a-workbook-with-specific-print-area-defined-then-ex…
agent-aspose-cells-examples May 21, 2026
e8c25a3
Add example: save-a-workbook-as-xls-while-enabling-temporary-folder-s…
agent-aspose-cells-examples May 21, 2026
c610c6e
Add example: apply-filterobjects-to-exclude-data-validation-rules-dur…
agent-aspose-cells-examples May 21, 2026
e44f2c3
Add example: read-cell-comments-using-lightcells-api-and-write-them-t…
agent-aspose-cells-examples May 21, 2026
c6d9543
Add example: write-cell-comments-while-saving-a-workbook-with-lightce…
agent-aspose-cells-examples May 21, 2026
7644177
Add example: load-a-workbook-and-filter-out-all-conditional-formattin…
agent-aspose-cells-examples May 21, 2026
562925a
Add example: export-hyperlinks-from-a-workbook-using-lightcells-api-a…
agent-aspose-cells-examples May 21, 2026
babf6e7
Add example: insert-new-hyperlinks-while-writing-cells-with-lightcell…
agent-aspose-cells-examples May 21, 2026
44238ea
Add example: load-only-visible-worksheets-by-applying-filterobjects-t…
agent-aspose-cells-examples May 21, 2026
ca7909a
Add example: configure-lightcells-to-use-a-custom-buffer-size-for-rea…
agent-aspose-cells-examples May 21, 2026
95cb977
Add example: save-a-workbook-with-culturespecific-number-formats-by-s…
agent-aspose-cells-examples May 21, 2026
16f9792
Add example: load-a-workbook-containing-pivot-tables-using-lightcells…
agent-aspose-cells-examples May 21, 2026
eb32b1c
Add example: write-pivot-table-definitions-while-saving-with-lightcel…
agent-aspose-cells-examples May 21, 2026
5b76f2f
Add example: apply-filterdatakind-to-load-only-string-cells-from-a-te…
agent-aspose-cells-examples May 21, 2026
f59c542
Add example: write-merged-cells-while-streaming-data-with-lightcellsd…
agent-aspose-cells-examples May 21, 2026
9840420
Add example: load-a-workbook-with-a-specific-page-setup-configuration…
agent-aspose-cells-examples May 21, 2026
ab4e597
Add example: save-a-workbook-using-lightcells-api-while-disabling-aut…
agent-aspose-cells-examples May 21, 2026
b769d1d
Add example: implement-lightcellsdatahandler-to-replace-error-values-…
agent-aspose-cells-examples May 21, 2026
1e823d8
Add example: load-an-xlsx-workbook-from-a-file-path-while-excluding-a…
agent-aspose-cells-examples May 21, 2026
f843657
Add example: save-the-chartfree-workbook-to-a-pdf-document-preserving…
agent-aspose-cells-examples May 21, 2026
b466c19
Add example: load-a-workbook-using-loadoptions-with-loadcharts-disabl…
agent-aspose-cells-examples May 21, 2026
e961e72
Add example: apply-printer-paper-size-a5-during-load-and-generate-a-p…
agent-aspose-cells-examples May 21, 2026
bc961d7
Add example: reload-the-same-workbook-with-printer-paper-size-a3-and-…
agent-aspose-cells-examples May 21, 2026
0253385
Add example: load-a-large-workbook-with-lightcells-api-and-save-direc…
agent-aspose-cells-examples May 21, 2026
ba2284d
Add example: load-only-worksheets-with-indexes-0-and-2-using-loadopti…
agent-aspose-cells-examples May 21, 2026
5208112
Add example: filter-defined-names-containing-total-during-load-and-ve…
agent-aspose-cells-examples May 21, 2026
7b9f609
Add example: configure-interruptmonitor-to-abort-loading-if-processin…
agent-aspose-cells-examples May 21, 2026
38b59c2
Add example: after-loading-iterate-through-workbookloadwarnings-colle…
agent-aspose-cells-examples May 21, 2026
4ef4638
Add example: load-a-workbook-set-printer-paper-size-to-letter-via-loa…
agent-aspose-cells-examples May 21, 2026
13d44ec
Add example: load-a-workbook-using-loadoptions-to-disable-charts-set-…
agent-aspose-cells-examples May 21, 2026
9aeaef7
Add example: load-a-workbook-using-loadoptions-to-disable-charts-load…
agent-aspose-cells-examples May 21, 2026
307bc73
Add example: load-a-workbook-using-loadoptions-to-disable-charts-conf…
agent-aspose-cells-examples May 21, 2026
1120d37
Add example: load-a-workbook-using-loadoptions-to-disable-charts-retr…
agent-aspose-cells-examples May 21, 2026
fe6683d
Add example: load-a-workbook-with-lightcells-api-exclude-charts-and-s…
agent-aspose-cells-examples May 21, 2026
20819a3
Add example: load-a-workbook-with-lightcells-api-set-printer-paper-si…
agent-aspose-cells-examples May 21, 2026
4591966
Add example: load-a-workbook-with-lightcells-api-load-only-worksheets…
agent-aspose-cells-examples May 21, 2026
0fbe4a3
Add example: load-a-workbook-with-lightcells-api-configure-interruptm…
agent-aspose-cells-examples May 21, 2026
64325d5
Add example: load-a-workbook-with-lightcells-api-retrieve-loadwarning…
agent-aspose-cells-examples May 21, 2026
e472493
Add example: implement-a-commandline-utility-that-accepts-a-folder-pa…
agent-aspose-cells-examples May 21, 2026
0b33c44
Add example: batch-process-multiple-excel-files-by-loading-them-witho…
agent-aspose-cells-examples May 21, 2026
73152c8
Add example: use-lightcells-api-to-open-a-large-workbook-then-monitor…
agent-aspose-cells-examples May 21, 2026
896a8d6
Add example: load-a-workbook-apply-printer-paper-size-a5-and-verify-t…
agent-aspose-cells-examples May 21, 2026
f89b00d
Add example: load-a-workbook-apply-printer-paper-size-letter-and-ensu…
agent-aspose-cells-examples May 21, 2026
b2013bb
Add example: load-a-workbook-filter-defined-names-containing-total-an…
agent-aspose-cells-examples May 21, 2026
6b3dd02
Update agents.md
agent-aspose-cells-examples May 31, 2026
f8c2456
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
455 changes: 455 additions & 0 deletions index.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.IO;
using Aspose.Cells;

class Program
{
static void Main()
{
const string inputPath = "input.xlsx";

// Ensure the input file exists before attempting to load it
if (!File.Exists(inputPath))
{
Console.WriteLine($"Error: File \"{inputPath}\" not found.");
return;
}

try
{
// Load the workbook from the specified file
Workbook workbook = new Workbook(inputPath);

// NOTE: In some Aspose.Cells versions the LoadWarnings collection is not available.
// If needed, warnings can be retrieved via other mechanisms provided by the library.

Console.WriteLine("Workbook loaded successfully.");

// (Optional) Save the workbook if further processing is needed
// workbook.Save("output.xlsx");
}
catch (Exception ex)
{
// Catch any runtime exceptions and display a friendly message
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
115 changes: 115 additions & 0 deletions open-workbook/agents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
category: open-workbook
framework: .NET
parent: ../agents.md
version: v2
---

# Persona

You are a C# developer specializing in workbook loading and opening operations using Aspose.Cells for .NET.

Generate simple, correct, production-quality examples that demonstrate ONE workbook-opening 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

- Workbook
- LoadOptions
- TxtLoadOptions
- HtmlLoadOptions
- PdfSaveOptions

---

# Common Pattern

1. Create or prepare workbook source
2. Configure load options if needed
3. Open workbook
4. Access workbook content
5. Save workbook or verify results
6. Print success message

---

# Open Workbook Rules

- Demonstrate one loading feature per example
- Use LoadOptions only when relevant
- Show how workbook content is accessed after loading
- Keep examples focused and easy to understand

---

# Input Strategy

- Avoid dependency on unknown external files
- Create source content programmatically when possible
- Keep examples self-contained

---

# Output Rules

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

---

# Common Tasks

- Open workbook
- Open CSV file
- Open HTML file
- Configure LoadOptions
- Detect file format
- Access workbook metadata after loading

---

# Common Mistakes

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

❌ Use incorrect LoadOptions type
✅ Match LoadOptions to source format

❌ Assume workbook contains worksheets without validation
✅ Verify workbook content before processing

---

# Code Simplicity

- Keep examples concise
- Avoid unnecessary abstractions
- Focus on one workbook-loading capability per example

---

# 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,49 @@
using System;
using Aspose.Cells;

namespace AsposeCellsLoadFilterExample
{
// Custom LoadFilter that returns a specific sheet loading order
public class CustomLoadFilter : LoadFilter
{
private readonly int[] _sheetsOrder;

// Accept the desired sheet indices via constructor
public CustomLoadFilter(int[] sheetsOrder) : base(LoadDataFilterOptions.All)
{
_sheetsOrder = sheetsOrder;
}

// Override the read‑only property to supply the indices
public override int[] SheetsInLoadingOrder => _sheetsOrder;
}

class Program
{
static void Main()
{
// User‑provided list of sheet indexes to load (e.g., load sheet 0 and sheet 2)
int[] selectedSheetIndexes = new int[] { 0, 2 };

// Create the custom filter with the desired order
LoadFilter filter = new CustomLoadFilter(selectedSheetIndexes);

// Configure load options to use the filter
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFilter = filter;

// Load the workbook using the filter – only the specified sheets will be loaded
Workbook workbook = new Workbook("Template.xlsx", loadOptions);

// Demonstrate which sheets were loaded
Console.WriteLine("Loaded worksheets count: " + workbook.Worksheets.Count);
foreach (Worksheet ws in workbook.Worksheets)
{
Console.WriteLine($"- Index: {ws.Index}, Name: {ws.Name}");
}

// Save the workbook (optional, demonstrates that saving works with filtered sheets)
workbook.Save("FilteredOutput.xlsx");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using Aspose.Cells;

namespace AsposeCellsFilterExample
{
class Program
{
static void Main()
{
// Path to the template workbook
string templatePath = "TemplateWorkbook.xlsx";

// Create LoadOptions and set a LoadFilter that loads only numeric (including date/time) cells
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFilter = new LoadFilter(LoadDataFilterOptions.CellNumeric);

// Load the workbook using the specified load options
Workbook workbook = new Workbook(templatePath, loadOptions);

// At this point, only cells with numeric or date values are loaded.
// Perform any statistical analysis here, e.g., iterate through worksheets and cells.

// Example: Count numeric cells in the first worksheet
Worksheet sheet = workbook.Worksheets[0];
int numericCellCount = 0;
foreach (Cell cell in sheet.Cells)
{
if (cell.Type == CellValueType.IsNumeric) // includes dates
{
numericCellCount++;
}
}
Console.WriteLine($"Numeric/Date cells loaded: {numericCellCount}");

// Save the filtered workbook (optional, for verification)
workbook.Save("FilteredWorkbook.xlsx");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Text;
using Aspose.Cells;

class Program
{
static void Main()
{
// Paths to the template and the output summary workbook
string templatePath = "template.xlsx";
string outputPath = "summary.xlsx";

// Configure load options to load only cells that contain string values
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFilter = new LoadFilter(LoadDataFilterOptions.CellString);

// Load the workbook from the template using the specified filter
Workbook sourceWorkbook = new Workbook(templatePath, loadOptions);

// StringBuilder to accumulate all string values from the loaded workbook
StringBuilder concatenatedStrings = new StringBuilder();

// Iterate through each worksheet and its used cells
foreach (Worksheet sheet in sourceWorkbook.Worksheets)
{
Cells cells = sheet.Cells;
int maxRow = cells.MaxDataRow;
int maxCol = cells.MaxDataColumn;

for (int row = 0; row <= maxRow; row++)
{
for (int col = 0; col <= maxCol; col++)
{
Cell cell = cells[row, col];
// After applying the filter, only string cells are loaded,
// but we still verify the cell type for safety.
if (cell != null && cell.Type == CellValueType.IsString)
{
concatenatedStrings.Append(cell.StringValue);
concatenatedStrings.Append(' '); // separator between values
}
}
}
}

// Create a new workbook that will hold the summary report
Workbook summaryWorkbook = new Workbook();
Worksheet summarySheet = summaryWorkbook.Worksheets[0];
summarySheet.Name = "Summary";

// Write the concatenated string into cell A1 of the summary sheet
summarySheet.Cells["A1"].PutValue(concatenatedStrings.ToString().Trim());

// Save the summary workbook to the specified output path
summaryWorkbook.Save(outputPath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using Aspose.Cells;

class FilterDefinedNamesDemo
{
static void Main()
{
// Path to the source workbook (replace with your actual file)
string sourcePath = "Source.xlsx";

// Path where the processed workbook will be saved
string outputPath = "FilteredNames.xlsx";

// Create LoadOptions and assign a custom LoadFilter that loads only defined names
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFilter = new DefinedNamesOnlyLoadFilter();

// Load the workbook using the specified LoadOptions
Workbook workbook = new Workbook(sourcePath, loadOptions);

// Retrieve all defined names (both workbook‑scoped and worksheet‑scoped)
Name[] allNames = workbook.Worksheets.Names.Filter(NameScopeType.All, -1);

// Output information about the loaded names
Console.WriteLine($"Loaded {allNames.Length} defined name(s):");
foreach (Name name in allNames)
{
Console.WriteLine($"Name: {name.Text}, RefersTo: {name.RefersTo}");
}

// Save the workbook (structure and names are preserved)
workbook.Save(outputPath);
}

// Custom LoadFilter that restricts loading to defined name objects only
private class DefinedNamesOnlyLoadFilter : LoadFilter
{
public override void StartSheet(Worksheet sheet)
{
// Load only the defined names; other data (cells, formats, etc.) is ignored
LoadDataFilterOptions = LoadDataFilterOptions.DefinedNames;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using Aspose.Cells;

class Program
{
static void Main()
{
// Path to the source workbook
string sourcePath = "input.xlsx";

// Create a LoadFilter that loads everything except data validations
// LoadDataFilterOptions.All includes all data; we remove DataValidation using bitwise NOT
LoadDataFilterOptions filterOptions = LoadDataFilterOptions.All & ~LoadDataFilterOptions.DataValidation;
LoadFilter loadFilter = new LoadFilter(filterOptions);

// Assign the filter to LoadOptions
LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFilter = loadFilter;

// Load the workbook with the specified filter
Workbook workbook = new Workbook(sourcePath, loadOptions);

// Demonstrate that worksheets are loaded and data validations are excluded
Console.WriteLine("Number of worksheets loaded: " + workbook.Worksheets.Count);
foreach (Worksheet sheet in workbook.Worksheets)
{
Console.WriteLine($"Worksheet '{sheet.Name}' - Cells: {sheet.Cells.Count}, Validations: {sheet.Validations.Count}");
}

// Save the workbook (optional, shows lifecycle usage)
workbook.Save("output.xlsx");
}
}
Loading