Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
1ebae8e
Add example: create-a-custom-globalizationsettings-class-overriding-g…
agent-aspose-cells-examples May 21, 2026
a411365
Add example: override-geterrorstring-in-the-custom-class-to-provide-l…
agent-aspose-cells-examples May 21, 2026
d7fc35a
Add example: override-getbooleanstring-to-return-localized-truefalse-…
agent-aspose-cells-examples May 21, 2026
a75d5f1
Add example: assign-the-custom-globalizationsettings-instance-to-work…
agent-aspose-cells-examples May 21, 2026
30d12a4
Add example: load-the-excel-workbook-using-workbookload-after-configu…
agent-aspose-cells-examples May 21, 2026
87f9174
Add example: set-cell-formulas-with-cellformulalocal-to-apply-localiz…
agent-aspose-cells-examples May 21, 2026
e04160d
Add example: verify-that-localized-function-names-are-correctly-recog…
agent-aspose-cells-examples May 21, 2026
f85a8a7
Add example: save-the-localized-workbook-as-xlsx-preserving-original-…
agent-aspose-cells-examples May 21, 2026
3a9c62a
Add example: generate-a-report-listing-processed-workbooks-applied-lo…
agent-aspose-cells-examples May 21, 2026
d3c7b7c
Add example: implement-fallback-to-english-function-names-when-a-requ…
agent-aspose-cells-examples May 21, 2026
1acb59d
Add example: log-each-overridden-method-call-to-a-debug-file-for-trou…
agent-aspose-cells-examples May 21, 2026
55b203e
Add example: create-a-batch-process-that-applies-the-custom-globaliza…
agent-aspose-cells-examples May 21, 2026
d7a6481
Add example: validate-that-boolean-values-display-localized-truefalse…
agent-aspose-cells-examples May 21, 2026
20d75b5
Add example: write-unit-tests-asserting-getlocalfunctionname-returns-…
agent-aspose-cells-examples May 21, 2026
e0b99b4
Add example: write-unit-tests-for-geterrorstring-covering-standard-ex…
agent-aspose-cells-examples May 21, 2026
48b6d28
Add example: write-unit-tests-for-getbooleanstring-covering-true-fals…
agent-aspose-cells-examples May 21, 2026
c8f90a4
Add example: ensure-that-cell-comments-retain-their-original-language…
agent-aspose-cells-examples May 21, 2026
95fda3e
Add example: use-workbooksettings-to-enable-automatic-recalculation-a…
agent-aspose-cells-examples May 21, 2026
a47bfba
Add example: configure-workbook-to-use-a-specific-cultureinfo-object-…
agent-aspose-cells-examples May 21, 2026
9c50240
Add example: test-that-excels-autofilter-works-correctly-with-localiz…
agent-aspose-cells-examples May 21, 2026
dceacb8
Add example: ensure-that-pivot-tables-reflect-localized-subtotal-labe…
agent-aspose-cells-examples May 21, 2026
f73e2ad
Add example: verify-that-chart-titles-and-axis-labels-display-localiz…
agent-aspose-cells-examples May 21, 2026
6fa114b
Add example: implement-a-method-to-reset-globalizationsettings-to-def…
agent-aspose-cells-examples May 21, 2026
9ff5a74
Add example: create-a-configuration-file-mapping-locale-identifiers-t…
agent-aspose-cells-examples May 21, 2026
6a2932a
Add example: load-the-configuration-at-runtime-and-instantiate-the-ap…
agent-aspose-cells-examples May 21, 2026
2ecf686
Add example: develop-a-console-application-that-prompts-users-to-sele…
agent-aspose-cells-examples May 21, 2026
217e065
Add example: implement-a-feature-that-switches-localization-at-runtim…
agent-aspose-cells-examples May 21, 2026
0a8736c
Add example: measure-performance-differences-when-loading-workbooks-w…
agent-aspose-cells-examples May 21, 2026
335a40a
Add example: log-performance-metrics-for-each-localization-step-durin…
agent-aspose-cells-examples May 21, 2026
3c1b798
Add example: create-a-diagnostic-tool-that-compares-original-english-…
agent-aspose-cells-examples May 21, 2026
cdd7bac
Add example: provide-documentation-examples-showing-how-to-toggle-bet…
agent-aspose-cells-examples May 21, 2026
062d25e
Add example: load-an-xlsx-workbook-using-loadoptions-with-cultureinfo…
agent-aspose-cells-examples May 21, 2026
da601ab
Add example: create-a-subclass-of-globalizationsettings-that-override…
agent-aspose-cells-examples May 21, 2026
904d1fd
Add example: create-a-subclass-of-globalizationsettings-overriding-ge…
agent-aspose-cells-examples May 21, 2026
78cd3fe
Add example: develop-a-chartglobalizationsettings-derivative-that-ove…
agent-aspose-cells-examples May 21, 2026
11c43aa
Add example: assign-the-custom-globalizationsettings-to-the-workbook-…
agent-aspose-cells-examples May 21, 2026
156f62b
Add example: add-subtotal-rows-to-the-worksheet-after-assigning-custo…
agent-aspose-cells-examples May 21, 2026
87a9c83
Add example: convert-gregorian-date-cells-to-japanese-calendar-dates-…
agent-aspose-cells-examples May 21, 2026
0cbe75f
Add example: save-the-workbook-containing-japanese-era-dates-as-pdf-c…
agent-aspose-cells-examples May 21, 2026
40b8cc5
Add example: batch-process-a-folder-of-xlsx-files-loading-each-with-s…
agent-aspose-cells-examples May 21, 2026
c38b21d
Add example: implement-error-handling-for-loadoptionscultureinfo-when…
agent-aspose-cells-examples May 21, 2026
18b7c8c
Add example: compare-pdf-output-of-a-workbook-loaded-with-invariant-c…
agent-aspose-cells-examples May 21, 2026
af535f7
Add example: programmatically-set-worksheet-cell-styles-to-display-da…
agent-aspose-cells-examples May 21, 2026
51a308c
Add example: measure-performance-impact-of-applying-custom-globalizat…
agent-aspose-cells-examples May 21, 2026
8387d96
Add example: create-an-application-that-loads-a-workbook-with-italian…
agent-aspose-cells-examples May 21, 2026
d577b3d
Add example: implement-a-method-that-switches-globalizationsettings-a…
agent-aspose-cells-examples May 21, 2026
04412f2
Add example: generate-a-report-listing-all-cells-converted-to-japanes…
agent-aspose-cells-examples May 21, 2026
6f2c608
Add example: apply-custom-number-format-strings-to-percentage-cells-a…
agent-aspose-cells-examples May 21, 2026
2519d0d
Add example: write-a-script-that-extracts-chart-images-applies-a-loca…
agent-aspose-cells-examples May 21, 2026
84bfcb0
Add example: demonstrate-preserving-the-original-thread-culture-while…
agent-aspose-cells-examples May 21, 2026
a07bc2a
Add example: create-a-utility-that-converts-date-columns-in-multiple-…
agent-aspose-cells-examples May 21, 2026
ef0a39b
Add example: test-that-overriding-getgrandtotalname-does-not-affect-s…
agent-aspose-cells-examples May 21, 2026
d5fab52
Add example: implement-logging-to-capture-which-culturespecific-label…
agent-aspose-cells-examples May 21, 2026
3a6faaf
Add example: design-a-workflow-that-loads-a-workbook-with-arabic-cult…
agent-aspose-cells-examples May 21, 2026
1ea4520
Add example: create-a-function-that-returns-a-formatted-japanese-era-…
agent-aspose-cells-examples May 21, 2026
3d92feb
Add example: validate-that-number-formatting-respects-the-loaded-cult…
agent-aspose-cells-examples May 21, 2026
fed0c0c
Add example: implement-a-feature-that-automatically-selects-the-appro…
agent-aspose-cells-examples May 21, 2026
17a2c21
Add example: write-code-to-export-a-workbooks-chart-objects-to-separa…
agent-aspose-cells-examples May 21, 2026
647693c
Add example: create-a-test-suite-that-loads-workbooks-with-various-cu…
agent-aspose-cells-examples May 21, 2026
e573ea0
Add example: program-a-macrolike-routine-that-adds-subtotals-with-loc…
agent-aspose-cells-examples May 21, 2026
83b9641
Add example: configure-chart-rendering-to-use-antialiasing-while-appl…
agent-aspose-cells-examples May 21, 2026
5cb8a91
Add example: implement-a-fallback-mechanism-that-reverts-to-default-g…
agent-aspose-cells-examples May 21, 2026
39924b2
Add example: write-a-script-that-extracts-the-other-label-text-from-r…
agent-aspose-cells-examples May 21, 2026
f802a4a
Update agents.md
agent-aspose-cells-examples May 31, 2026
41cffab
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,80 @@
using System;
using Aspose.Cells;
using Aspose.Cells.Pivot;

namespace AsposeCellsSubtotalDemo
{
// Custom globalization settings that overrides the total name for the SUM function
public class CustomGlobalizationSettings : SettableGlobalizationSettings
{
public override string GetTotalName(ConsolidationFunction functionType)
{
// Return a custom label for SUM totals; other functions use the base implementation
if (functionType == ConsolidationFunction.Sum)
return "Custom Sum Total";
return base.GetTotalName(functionType);
}
}

public class Program
{
public static void Main()
{
// Create a new workbook and get the first worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;

// Populate sample data (Category | Value)
cells["A1"].PutValue("Category");
cells["B1"].PutValue("Value");
cells["A2"].PutValue("A");
cells["B2"].PutValue(10);
cells["A3"].PutValue("A");
cells["B3"].PutValue(20);
cells["A4"].PutValue("B");
cells["B4"].PutValue(30);
cells["A5"].PutValue("B");
cells["B5"].PutValue(40);
cells["A6"].PutValue("C");
cells["B6"].PutValue(50);

// Assign the custom globalization settings to the workbook
workbook.Settings.GlobalizationSettings = new CustomGlobalizationSettings();

// Define the range that contains the data (including header)
CellArea dataArea = CellArea.CreateCellArea(0, 0, 5, 1); // rows 0-5, columns 0-1

// Add subtotal rows:
// - Group by column 0 (Category)
// - Use SUM function
// - Apply subtotal to column 1 (Value)
// - Replace existing subtotals, no page breaks, place summary below data
cells.Subtotal(
dataArea,
groupBy: 0,
function: ConsolidationFunction.Sum,
totalList: new int[] { 1 },
replace: true,
pageBreaks: false,
summaryBelowData: true);

// Verify that the subtotal label uses the custom total name
// Search for the custom label in the worksheet
string customLabel = "Custom Sum Total";
Cell foundCell = cells.Find(customLabel, null, new FindOptions() { LookInType = LookInType.Values });

if (foundCell != null)
{
Console.WriteLine($"Verified custom total label found at {foundCell.Name}: \"{foundCell.StringValue}\"");
}
else
{
Console.WriteLine("Custom total label not found. Verification failed.");
}

// Save the workbook
workbook.Save("SubtotalWithCustomGlobalization.xlsx");
}
}
}
115 changes: 115 additions & 0 deletions globalization-and-localization/agents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
category: globalization-and-localization
framework: .NET
parent: ../agents.md
version: v2
---

# Persona

You are a C# developer specializing in globalization, localization, regional settings, and culture-specific workbook processing using Aspose.Cells for .NET.

Generate simple, correct, production-quality examples that demonstrate ONE globalization or localization 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 System.Globalization;
using Aspose.Cells;

---

# Key APIs

- GlobalizationSettings
- Workbook.Settings
- CultureInfo
- Style.Custom
- Cell.PutValue()

---

# Common Pattern

1. Create workbook
2. Configure culture or globalization settings
3. Add localized data
4. Format values using regional settings
5. Save workbook
6. Print success message

---

# Globalization and Localization Rules

- Demonstrate one localization feature per example
- Use CultureInfo when culture-specific behavior is required
- Use deterministic sample data
- Clearly show the effect of regional settings

---

# Input Strategy

- Do NOT rely on external XLSX files
- Generate workbook content 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

- Apply culture-specific formatting
- Localize dates and numbers
- Configure globalization settings
- Work with regional formats
- Customize language-specific workbook behavior

---

# Common Mistakes

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

❌ Assume formatting behaves the same across cultures
✅ Explicitly configure culture settings

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

---

# Code Simplicity

- Keep examples concise
- Avoid unnecessary abstractions
- Focus on one localization 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,41 @@
using System;
using System.Globalization;
using Aspose.Cells;

namespace AsposeCellsPercentageFormatting
{
class Program
{
static void Main()
{
// Load the workbook with Brazilian Portuguese culture (pt-BR)
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
loadOptions.CultureInfo = new CultureInfo("pt-BR");
Workbook workbook = new Workbook("input.xlsx", loadOptions);

// Iterate through all cells in the first worksheet
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

foreach (Cell cell in cells)
{
// Retrieve the cell's style
Style style = cell.GetStyle();

// Check if the current style is a percentage format
if (style.IsPercent)
{
// Apply a custom percentage format that respects the culture
// "#,##0.00%" will use the culture's decimal and group separators
style.SetCustom("#,##0.00%", true);

// Re-apply the modified style to the cell
cell.SetStyle(style);
}
}

// Save the modified workbook
workbook.Save("output.xlsx");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using Aspose.Cells;

// Custom globalization settings derived from GlobalizationSettings
class CustomGlobalizationSettings : GlobalizationSettings
{
// Override boolean display strings
public override string GetBooleanValueString(bool value)
{
return value ? "ИСТИНА" : "ЛОЖЬ";
}

// Override error value strings
public override string GetErrorValueString(string error)
{
return error switch
{
"#NAME?" => "#ИМЯ?",
"#DIV/0!" => "#ДЕЛ/0!",
"#REF!" => "#ССЫЛКА!",
"#VALUE!" => "#ЗНАЧ!",
"#N/A" => "#Н/Д",
"#NUM!" => "#ЧИСЛО!",
"#NULL!" => "#ПУСТО!",
_ => base.GetErrorValueString(error)
};
}
}

class Program
{
static void Main()
{
// Create LoadOptions (no special options needed for this example)
LoadOptions loadOptions = new LoadOptions();

// Load the workbook; at this point no worksheet has been accessed yet
Workbook workbook = new Workbook("input.xlsx", loadOptions);

// Assign the custom globalization settings BEFORE any worksheet is accessed
workbook.Settings.GlobalizationSettings = new CustomGlobalizationSettings();

// Now worksheets can be used safely with the custom settings applied
Worksheet sheet = workbook.Worksheets[0];
Cell cell = sheet.Cells["A1"];
Console.WriteLine($"Cell[0,0] value: {cell.StringValue}");

// Save the workbook if needed
workbook.Save("output.xlsx");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using Aspose.Cells;
using Aspose.Cells.Pivot;

class Program
{
static void Main()
{
// Create a new workbook
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

// Populate sample data
cells["A1"].PutValue("Category");
cells["B1"].PutValue("Amount");
cells["A2"].PutValue("A");
cells["B2"].PutValue(10);
cells["A3"].PutValue("A");
cells["B3"].PutValue(20);
cells["A4"].PutValue("B");
cells["B4"].PutValue(30);
cells["A5"].PutValue("B");
cells["B5"].PutValue(40);

// Assign custom globalization settings before adding subtotals
workbook.Settings.GlobalizationSettings = new CustomGlobalizationSettings();

// Define the range for subtotal (rows 0‑4, columns 0‑1)
CellArea area = CellArea.CreateCellArea(0, 0, 4, 1);

// Add subtotal: group by column 0 (Category) and calculate Sum on column 1 (Amount)
// Parameters: area, columnIndexToGroup, function, columnsToSubtotal, replace, pageBreaks, summaryBelowData
cells.Subtotal(area, 0, ConsolidationFunction.Sum, new int[] { 1 }, true, false, true);

// Save the workbook
workbook.Save("CustomGlobalizationSubtotal.xlsx");
}

// Custom globalization settings to provide localized total label
class CustomGlobalizationSettings : GlobalizationSettings
{
public override string GetTotalName(ConsolidationFunction functionType)
{
// Return a custom label for the Sum total; fall back to default for others
return functionType == ConsolidationFunction.Sum
? "Custom Sum Total"
: base.GetTotalName(functionType);
}
}
}
Loading