From 6e9746c09ebef5fcda4cba30f8d2ba0a1689b6ba Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:16:50 +0500 Subject: [PATCH 01/46] Add example: load-a-workbook-with-loadoptionsautofitteroptionsonlyauto-set-to-true-to-automatically-adjust-all-row-heights --- rows-and-columns/agents.md | 57 +++++++++++++++++++ ...to-automatically-adjust-all-row-heights.cs | 27 +++++++++ 2 files changed, 84 insertions(+) create mode 100644 rows-and-columns/agents.md create mode 100644 rows-and-columns/load-a-workbook-with-loadoptionsautofitteroptionsonlyauto-set-to-true-to-automatically-adjust-all-row-heights.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md new file mode 100644 index 0000000000..695916e090 --- /dev/null +++ b/rows-and-columns/agents.md @@ -0,0 +1,57 @@ +# Rows and Columns Examples + +This folder contains **Aspose.Cells for .NET** code examples related to: + +Rows and Columns + + +## Purpose + +These examples demonstrate common **Aspose.Cells APIs** used when working with: + +- Workbooks +- Worksheets +- Cells +- Formulas +- Charts +- Data operations + + +## Example Files + +Each `.cs` file demonstrates a specific task related to **Rows and Columns**. + +Example: + +create-a-workbook.cs + + +## Required Namespaces + +Most examples will require: + +using Aspose.Cells; + + +## Common Pattern + +Typical Aspose.Cells workflow: + +Workbook workbook = new Workbook(); + +Worksheet sheet = workbook.Worksheets[0]; + +Cells cells = sheet.Cells; + + +## Output + +Examples may generate: + +- XLSX files +- PDF files +- CSV files +- Images + +Output files are written to the working directory. +- load-a-workbook-with-loadoptionsautofitteroptionsonlyauto-set-to-true-to-automatically-adjust-all-row-heights.cs diff --git a/rows-and-columns/load-a-workbook-with-loadoptionsautofitteroptionsonlyauto-set-to-true-to-automatically-adjust-all-row-heights.cs b/rows-and-columns/load-a-workbook-with-loadoptionsautofitteroptionsonlyauto-set-to-true-to-automatically-adjust-all-row-heights.cs new file mode 100644 index 0000000000..5299931dfb --- /dev/null +++ b/rows-and-columns/load-a-workbook-with-loadoptionsautofitteroptionsonlyauto-set-to-true-to-automatically-adjust-all-row-heights.cs @@ -0,0 +1,27 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create LoadOptions and configure AutoFitterOptions to only auto‑fit rows whose height is not custom set + LoadOptions loadOptions = new LoadOptions(); + loadOptions.AutoFitterOptions = new AutoFitterOptions + { + OnlyAuto = true + }; + + // Load the workbook with the specified options; rows will be auto‑fitted during load + Workbook workbook = new Workbook("input.xlsx", loadOptions); + + // Example: display the height of the first row after auto‑fit + double rowHeight = workbook.Worksheets[0].Cells.GetRowHeight(0); + Console.WriteLine($"Row 0 height after auto‑fit: {rowHeight}"); + + // Save the workbook (optional) + workbook.Save("output.xlsx"); + } +} + +// Author: Aspose.Cells .NET example \ No newline at end of file From 6e2e57c1f58b712b82c9f23116a2156298d50239 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:17:35 +0500 Subject: [PATCH 02/46] Add example: set-the-height-of-a-specific-row-eg-row-5-to-a-defined-point-value-using-cellssetrowheight --- rows-and-columns/agents.md | 1 + ...ned-point-value-using-cellssetrowheight.cs | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 rows-and-columns/set-the-height-of-a-specific-row-eg-row-5-to-a-defined-point-value-using-cellssetrowheight.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 695916e090..5394aed5aa 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -55,3 +55,4 @@ Examples may generate: Output files are written to the working directory. - load-a-workbook-with-loadoptionsautofitteroptionsonlyauto-set-to-true-to-automatically-adjust-all-row-heights.cs +- set-the-height-of-a-specific-row-eg-row-5-to-a-defined-point-value-using-cellssetrowheight.cs diff --git a/rows-and-columns/set-the-height-of-a-specific-row-eg-row-5-to-a-defined-point-value-using-cellssetrowheight.cs b/rows-and-columns/set-the-height-of-a-specific-row-eg-row-5-to-a-defined-point-value-using-cellssetrowheight.cs new file mode 100644 index 0000000000..030991de94 --- /dev/null +++ b/rows-and-columns/set-the-height-of-a-specific-row-eg-row-5-to-a-defined-point-value-using-cellssetrowheight.cs @@ -0,0 +1,23 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – sets row height using Cells.SetRowHeight +class Program +{ + 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; + + // Set the height of row 5 (zero‑based index) to 30 points + cells.SetRowHeight(5, 30.0); + + // Verify the height (optional) + Console.WriteLine("Row 5 height: " + cells.GetRowHeight(5)); + + // Save the workbook to a file + workbook.Save("RowHeightDemo.xlsx"); + } +} \ No newline at end of file From ff3b9b55e1b2a07e2268f778394a9ef240019060 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:18:18 +0500 Subject: [PATCH 03/46] Add example: apply-a-uniform-row-height-to-all-rows-in-a-worksheet-by-assigning-cellsstandardheight --- rows-and-columns/agents.md | 1 + ...ksheet-by-assigning-cellsstandardheight.cs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 rows-and-columns/apply-a-uniform-row-height-to-all-rows-in-a-worksheet-by-assigning-cellsstandardheight.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 5394aed5aa..43f7eab79e 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -56,3 +56,4 @@ Examples may generate: Output files are written to the working directory. - load-a-workbook-with-loadoptionsautofitteroptionsonlyauto-set-to-true-to-automatically-adjust-all-row-heights.cs - set-the-height-of-a-specific-row-eg-row-5-to-a-defined-point-value-using-cellssetrowheight.cs +- apply-a-uniform-row-height-to-all-rows-in-a-worksheet-by-assigning-cellsstandardheight.cs diff --git a/rows-and-columns/apply-a-uniform-row-height-to-all-rows-in-a-worksheet-by-assigning-cellsstandardheight.cs b/rows-and-columns/apply-a-uniform-row-height-to-all-rows-in-a-worksheet-by-assigning-cellsstandardheight.cs new file mode 100644 index 0000000000..4b6cae06b1 --- /dev/null +++ b/rows-and-columns/apply-a-uniform-row-height-to-all-rows-in-a-worksheet-by-assigning-cellsstandardheight.cs @@ -0,0 +1,22 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – sets a uniform row height for all rows + +class Program +{ + static void Main() + { + // Create a new workbook (lifecycle: create) + Workbook workbook = new Workbook(); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Apply a uniform row height (in points) to all rows in the worksheet + worksheet.Cells.StandardHeight = 20; // adjust the value as needed + + // Save the workbook (lifecycle: save) + workbook.Save("UniformRowHeight.xlsx"); + } +} \ No newline at end of file From 834d6f566bf28cd347330fd087ea49c91218f1f3 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:19:02 +0500 Subject: [PATCH 04/46] Add example: set-the-width-of-a-specific-column-eg-column-3-using-cellssetcolumnwidth --- rows-and-columns/agents.md | 1 + ...n-eg-column-3-using-cellssetcolumnwidth.cs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 rows-and-columns/set-the-width-of-a-specific-column-eg-column-3-using-cellssetcolumnwidth.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 43f7eab79e..3c67d2f760 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -57,3 +57,4 @@ Output files are written to the working directory. - load-a-workbook-with-loadoptionsautofitteroptionsonlyauto-set-to-true-to-automatically-adjust-all-row-heights.cs - set-the-height-of-a-specific-row-eg-row-5-to-a-defined-point-value-using-cellssetrowheight.cs - apply-a-uniform-row-height-to-all-rows-in-a-worksheet-by-assigning-cellsstandardheight.cs +- set-the-width-of-a-specific-column-eg-column-3-using-cellssetcolumnwidth.cs diff --git a/rows-and-columns/set-the-width-of-a-specific-column-eg-column-3-using-cellssetcolumnwidth.cs b/rows-and-columns/set-the-width-of-a-specific-column-eg-column-3-using-cellssetcolumnwidth.cs new file mode 100644 index 0000000000..7fc4c6ec2a --- /dev/null +++ b/rows-and-columns/set-the-width-of-a-specific-column-eg-column-3-using-cellssetcolumnwidth.cs @@ -0,0 +1,22 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook (use the provided creation rule) + Workbook workbook = new Workbook(); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Set the width of column 3 (zero‑based index 2) to 25.5 characters + worksheet.Cells.SetColumnWidth(2, 25.5); + + // Save the workbook (use the provided save rule) + workbook.Save("ColumnWidthDemo.xlsx", SaveFormat.Xlsx); + } +} + +// Author: Example demonstrating Cells.SetColumnWidth to adjust column width. \ No newline at end of file From 6f1755a110976097515a109768479e06a76c2b44 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:19:42 +0500 Subject: [PATCH 05/46] Add example: set-the-width-of-a-specific-column-in-pixels-using-cellssetcolumnwidthpixel --- rows-and-columns/agents.md | 1 + ...n-pixels-using-cellssetcolumnwidthpixel.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 rows-and-columns/set-the-width-of-a-specific-column-in-pixels-using-cellssetcolumnwidthpixel.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 3c67d2f760..2ad35bd2c5 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -58,3 +58,4 @@ Output files are written to the working directory. - set-the-height-of-a-specific-row-eg-row-5-to-a-defined-point-value-using-cellssetrowheight.cs - apply-a-uniform-row-height-to-all-rows-in-a-worksheet-by-assigning-cellsstandardheight.cs - set-the-width-of-a-specific-column-eg-column-3-using-cellssetcolumnwidth.cs +- set-the-width-of-a-specific-column-in-pixels-using-cellssetcolumnwidthpixel.cs diff --git a/rows-and-columns/set-the-width-of-a-specific-column-in-pixels-using-cellssetcolumnwidthpixel.cs b/rows-and-columns/set-the-width-of-a-specific-column-in-pixels-using-cellssetcolumnwidthpixel.cs new file mode 100644 index 0000000000..bfe31904fe --- /dev/null +++ b/rows-and-columns/set-the-width-of-a-specific-column-in-pixels-using-cellssetcolumnwidthpixel.cs @@ -0,0 +1,21 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – sets column width in pixels + +class Program +{ + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + Cells cells = worksheet.Cells; + + // Set the width of column 3 (zero‑based index 2) to 150 pixels + cells.SetColumnWidthPixel(2, 150); + + // Save the workbook + workbook.Save("ColumnWidthPixelDemo.xlsx"); + } +} \ No newline at end of file From e2f89dcc62e95b7657481b428e442471ef9c84fc Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:21:20 +0500 Subject: [PATCH 06/46] Add example: autofit-a-single-row-based-on-its-content-using-worksheetautofitrow --- rows-and-columns/agents.md | 1 + ...n-its-content-using-worksheetautofitrow.cs | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 rows-and-columns/autofit-a-single-row-based-on-its-content-using-worksheetautofitrow.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 2ad35bd2c5..5c8d98e7b4 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -59,3 +59,4 @@ Output files are written to the working directory. - apply-a-uniform-row-height-to-all-rows-in-a-worksheet-by-assigning-cellsstandardheight.cs - set-the-width-of-a-specific-column-eg-column-3-using-cellssetcolumnwidth.cs - set-the-width-of-a-specific-column-in-pixels-using-cellssetcolumnwidthpixel.cs +- autofit-a-single-row-based-on-its-content-using-worksheetautofitrow.cs diff --git a/rows-and-columns/autofit-a-single-row-based-on-its-content-using-worksheetautofitrow.cs b/rows-and-columns/autofit-a-single-row-based-on-its-content-using-worksheetautofitrow.cs new file mode 100644 index 0000000000..0c176db4eb --- /dev/null +++ b/rows-and-columns/autofit-a-single-row-based-on-its-content-using-worksheetautofitrow.cs @@ -0,0 +1,27 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – auto‑fits a single row based on its content +class Program +{ + static void Main() + { + // Create a new workbook (replace with the provided create rule if available) + Workbook workbook = new Workbook(); + + // Get the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Populate some cells in the target row (row index 1 → second row) + worksheet.Cells["A2"].Value = "This is a long piece of text that should cause the row height to increase when auto‑fitted."; + Style style = worksheet.Cells["A2"].GetStyle(); + style.IsTextWrapped = true; // Enable text wrapping so the height can expand + worksheet.Cells["A2"].SetStyle(style); + + // Auto‑fit only the specified row + worksheet.AutoFitRow(1); // Row index is zero‑based + + // Save the workbook (replace with the provided save rule if available) + workbook.Save("AutoFitRowResult.xlsx"); + } +} \ No newline at end of file From c385d7cc776e6f7c0a579ccb975950b1d63220e8 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:22:20 +0500 Subject: [PATCH 07/46] Add example: autofit-a-range-of-rows-eg-rows-1520-using-worksheetautofitrows --- rows-and-columns/agents.md | 1 + ...eg-rows-1520-using-worksheetautofitrows.cs | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 rows-and-columns/autofit-a-range-of-rows-eg-rows-1520-using-worksheetautofitrows.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 5c8d98e7b4..e6c3375c8b 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -60,3 +60,4 @@ Output files are written to the working directory. - set-the-width-of-a-specific-column-eg-column-3-using-cellssetcolumnwidth.cs - set-the-width-of-a-specific-column-in-pixels-using-cellssetcolumnwidthpixel.cs - autofit-a-single-row-based-on-its-content-using-worksheetautofitrow.cs +- autofit-a-range-of-rows-eg-rows-1520-using-worksheetautofitrows.cs diff --git a/rows-and-columns/autofit-a-range-of-rows-eg-rows-1520-using-worksheetautofitrows.cs b/rows-and-columns/autofit-a-range-of-rows-eg-rows-1520-using-worksheetautofitrows.cs new file mode 100644 index 0000000000..298afb8124 --- /dev/null +++ b/rows-and-columns/autofit-a-range-of-rows-eg-rows-1520-using-worksheetautofitrows.cs @@ -0,0 +1,27 @@ +using System; +using Aspose.Cells; + +// Author: Example – auto‑fit rows 15‑20 using Aspose.Cells + +class Program +{ + static void Main() + { + // Create a new workbook (lifecycle rule) + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Optional: add sample data to see the effect of auto‑fit + Cells cells = sheet.Cells; + for (int i = 14; i <= 19; i++) + { + cells[i, 0].Value = $"Row {i + 1} with a long text that forces auto‑fit."; + } + + // Auto‑fit rows 15‑20 (zero‑based indices 14‑19) + sheet.AutoFitRows(14, 19); + + // Save the workbook (lifecycle rule) + workbook.Save("AutoFitRows_15_20.xlsx"); + } +} \ No newline at end of file From 7a9680ba22cb4d8e14d22b9791136848185aeaf7 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:23:01 +0500 Subject: [PATCH 08/46] Add example: autofit-a-single-column-based-on-its-content-using-worksheetautofitcolumn --- rows-and-columns/agents.md | 1 + ...ts-content-using-worksheetautofitcolumn.cs | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 rows-and-columns/autofit-a-single-column-based-on-its-content-using-worksheetautofitcolumn.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index e6c3375c8b..7d1d43d9e6 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -61,3 +61,4 @@ Output files are written to the working directory. - set-the-width-of-a-specific-column-in-pixels-using-cellssetcolumnwidthpixel.cs - autofit-a-single-row-based-on-its-content-using-worksheetautofitrow.cs - autofit-a-range-of-rows-eg-rows-1520-using-worksheetautofitrows.cs +- autofit-a-single-column-based-on-its-content-using-worksheetautofitcolumn.cs diff --git a/rows-and-columns/autofit-a-single-column-based-on-its-content-using-worksheetautofitcolumn.cs b/rows-and-columns/autofit-a-single-column-based-on-its-content-using-worksheetautofitcolumn.cs new file mode 100644 index 0000000000..0df121d6bb --- /dev/null +++ b/rows-and-columns/autofit-a-single-column-based-on-its-content-using-worksheetautofitcolumn.cs @@ -0,0 +1,29 @@ +using System; +using Aspose.Cells; + +namespace AutoFitColumnExample +{ + // Author: Aspose.Cells .NET example + class Program + { + static void Main() + { + // Create a new workbook (in-memory) + Workbook workbook = new Workbook(); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Populate some cells in column C (index 2) + worksheet.Cells["C1"].PutValue("Short"); + worksheet.Cells["C2"].PutValue("A much longer piece of text that requires wider column"); + worksheet.Cells["C3"].PutValue("Medium length"); + + // Auto‑fit column C (0‑based index 2) + worksheet.AutoFitColumn(2); + + // Save the workbook to a file + workbook.Save("AutoFitColumnResult.xlsx"); + } + } +} \ No newline at end of file From 7733516f6bd774c9cb69ff7046a7a0de51ba2db5 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:23:42 +0500 Subject: [PATCH 09/46] Add example: autofit-a-range-of-columns-eg-columns-cf-using-worksheetautofitcolumns --- rows-and-columns/agents.md | 1 + ...olumns-cf-using-worksheetautofitcolumns.cs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 rows-and-columns/autofit-a-range-of-columns-eg-columns-cf-using-worksheetautofitcolumns.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 7d1d43d9e6..be6ac4d080 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -62,3 +62,4 @@ Output files are written to the working directory. - autofit-a-single-row-based-on-its-content-using-worksheetautofitrow.cs - autofit-a-range-of-rows-eg-rows-1520-using-worksheetautofitrows.cs - autofit-a-single-column-based-on-its-content-using-worksheetautofitcolumn.cs +- autofit-a-range-of-columns-eg-columns-cf-using-worksheetautofitcolumns.cs diff --git a/rows-and-columns/autofit-a-range-of-columns-eg-columns-cf-using-worksheetautofitcolumns.cs b/rows-and-columns/autofit-a-range-of-columns-eg-columns-cf-using-worksheetautofitcolumns.cs new file mode 100644 index 0000000000..3a8de776c7 --- /dev/null +++ b/rows-and-columns/autofit-a-range-of-columns-eg-columns-cf-using-worksheetautofitcolumns.cs @@ -0,0 +1,25 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – auto‑fit columns C‑F +class Program +{ + static void Main() + { + // Create a new workbook (empty) + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Sample data to demonstrate auto‑fit (optional) + worksheet.Cells["C1"].PutValue("Short"); + worksheet.Cells["D1"].PutValue("Medium length text"); + worksheet.Cells["E1"].PutValue("A very very long piece of text that requires more width"); + worksheet.Cells["F1"].PutValue(12345); + + // Auto‑fit columns C (index 2) through F (index 5) + worksheet.AutoFitColumns(2, 5); + + // Save the workbook + workbook.Save("AutoFitColumns_C_F.xlsx"); + } +} \ No newline at end of file From 06079470952db87e10d68d3b61b3dd55e17b391c Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:24:26 +0500 Subject: [PATCH 10/46] Add example: autofit-rows-that-contain-merged-cells-by-configuring-autofitteroptionsautofitmergedcellstype-and-passing-it-to-worksheetautofitrows --- rows-and-columns/agents.md | 1 + ...-and-passing-it-to-worksheetautofitrows.cs | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 rows-and-columns/autofit-rows-that-contain-merged-cells-by-configuring-autofitteroptionsautofitmergedcellstype-and-passing-it-to-worksheetautofitrows.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index be6ac4d080..8ccf5ce30c 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -63,3 +63,4 @@ Output files are written to the working directory. - autofit-a-range-of-rows-eg-rows-1520-using-worksheetautofitrows.cs - autofit-a-single-column-based-on-its-content-using-worksheetautofitcolumn.cs - autofit-a-range-of-columns-eg-columns-cf-using-worksheetautofitcolumns.cs +- autofit-rows-that-contain-merged-cells-by-configuring-autofitteroptionsautofitmergedcellstype-and-passing-it-to-worksheetautofitrows.cs diff --git a/rows-and-columns/autofit-rows-that-contain-merged-cells-by-configuring-autofitteroptionsautofitmergedcellstype-and-passing-it-to-worksheetautofitrows.cs b/rows-and-columns/autofit-rows-that-contain-merged-cells-by-configuring-autofitteroptionsautofitmergedcellstype-and-passing-it-to-worksheetautofitrows.cs new file mode 100644 index 0000000000..af8919e1d0 --- /dev/null +++ b/rows-and-columns/autofit-rows-that-contain-merged-cells-by-configuring-autofitteroptionsautofitmergedcellstype-and-passing-it-to-worksheetautofitrows.cs @@ -0,0 +1,39 @@ +using System; +using Aspose.Cells; + +namespace AutoFitMergedCellsDemo +{ + // Author: Aspose.Cells .NET example + class Program + { + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Put a long text into a cell and merge a range of cells (A1:B3) + sheet.Cells["A1"].PutValue("This is a sample text that is long enough to require row height adjustment when the cells are merged."); + sheet.Cells.Merge(0, 0, 3, 2); // Merge rows 0-2 and columns 0-1 (A1:B3) + + // Enable text wrapping for the merged cell + Style style = sheet.Cells["A1"].GetStyle(); + style.IsTextWrapped = true; + sheet.Cells["A1"].SetStyle(style); + + // Configure AutoFitterOptions to expand the height of each row in merged cells + AutoFitterOptions options = new AutoFitterOptions + { + AutoFitMergedCellsType = AutoFitMergedCellsType.EachLine, + // Optional: also fit wrapped text by paragraph + AutoFitWrappedTextType = AutoFitWrappedTextType.Paragraph + }; + + // AutoFit all rows in the worksheet using the configured options + sheet.AutoFitRows(options); + + // Save the workbook + workbook.Save("AutoFitMergedCellsResult.xlsx"); + } + } +} \ No newline at end of file From f1f619eed066319e03dea08e8faedf884a4c715e Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:25:08 +0500 Subject: [PATCH 11/46] Add example: combine-setrowheight-with-autofitrow-to-set-a-minimum-height-before-autofitting-a-row --- rows-and-columns/agents.md | 1 + ...minimum-height-before-autofitting-a-row.cs | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 rows-and-columns/combine-setrowheight-with-autofitrow-to-set-a-minimum-height-before-autofitting-a-row.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 8ccf5ce30c..2b5e50a6f4 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -64,3 +64,4 @@ Output files are written to the working directory. - autofit-a-single-column-based-on-its-content-using-worksheetautofitcolumn.cs - autofit-a-range-of-columns-eg-columns-cf-using-worksheetautofitcolumns.cs - autofit-rows-that-contain-merged-cells-by-configuring-autofitteroptionsautofitmergedcellstype-and-passing-it-to-worksheetautofitrows.cs +- combine-setrowheight-with-autofitrow-to-set-a-minimum-height-before-autofitting-a-row.cs diff --git a/rows-and-columns/combine-setrowheight-with-autofitrow-to-set-a-minimum-height-before-autofitting-a-row.cs b/rows-and-columns/combine-setrowheight-with-autofitrow-to-set-a-minimum-height-before-autofitting-a-row.cs new file mode 100644 index 0000000000..2c042a326d --- /dev/null +++ b/rows-and-columns/combine-setrowheight-with-autofitrow-to-set-a-minimum-height-before-autofitting-a-row.cs @@ -0,0 +1,37 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Populate some sample data in the first row + worksheet.Cells["A1"].PutValue("Short"); + worksheet.Cells["B1"].PutValue("A much longer piece of text that may require a taller row."); + + // Define the row index and the desired minimum height (in points) + int rowIndex = 0; + double minHeight = 20.0; // Minimum row height + + // Set the minimum height first + worksheet.Cells.SetRowHeight(rowIndex, minHeight); + + // Auto‑fit the row based on its content + worksheet.AutoFitRow(rowIndex); + + // Ensure the row height is not less than the minimum + double actualHeight = worksheet.Cells.GetRowHeight(rowIndex); + if (actualHeight < minHeight) + { + worksheet.Cells.SetRowHeight(rowIndex, minHeight); + } + + // Save the workbook + workbook.Save("RowHeight_MinAutoFit.xlsx"); + } +} +// Author: Aspose.Cells .NET example – combines SetRowHeight with AutoFitRow to enforce a minimum row height. \ No newline at end of file From 821a0fdd73ab438072e1a93e3810d3b5e6dc28d6 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:25:55 +0500 Subject: [PATCH 12/46] Add example: after-autofitting-a-column-finetune-its-width-with-setcolumnwidthpixel-for-precise-pixel-control --- ...umnwidthpixel-for-precise-pixel-control.cs | 27 +++++++++++++++++++ rows-and-columns/agents.md | 1 + 2 files changed, 28 insertions(+) create mode 100644 rows-and-columns/after-autofitting-a-column-finetune-its-width-with-setcolumnwidthpixel-for-precise-pixel-control.cs diff --git a/rows-and-columns/after-autofitting-a-column-finetune-its-width-with-setcolumnwidthpixel-for-precise-pixel-control.cs b/rows-and-columns/after-autofitting-a-column-finetune-its-width-with-setcolumnwidthpixel-for-precise-pixel-control.cs new file mode 100644 index 0000000000..1912f604af --- /dev/null +++ b/rows-and-columns/after-autofitting-a-column-finetune-its-width-with-setcolumnwidthpixel-for-precise-pixel-control.cs @@ -0,0 +1,27 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook wb = new Workbook(); + Worksheet sheet = wb.Worksheets[0]; + + // Sample data to demonstrate auto‑fit + sheet.Cells[0, 0].Value = "This is a relatively long piece of text that will trigger auto‑fit."; + sheet.Cells[1, 0].Value = "Short"; + + // Auto‑fit column 0 (imprecise) + sheet.AutoFitColumn(0); + + // Fine‑tune the column width to an exact pixel value (e.g., 120 pixels) + sheet.Cells.SetColumnWidthPixel(0, 120); + + // Save the workbook + wb.Save("AutoFitFineTuned.xlsx"); + } +} + +// Author note: This example shows how to auto‑fit a column and then adjust its width precisely using SetColumnWidthPixel. \ No newline at end of file diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 2b5e50a6f4..786a6ac38e 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -65,3 +65,4 @@ Output files are written to the working directory. - autofit-a-range-of-columns-eg-columns-cf-using-worksheetautofitcolumns.cs - autofit-rows-that-contain-merged-cells-by-configuring-autofitteroptionsautofitmergedcellstype-and-passing-it-to-worksheetautofitrows.cs - combine-setrowheight-with-autofitrow-to-set-a-minimum-height-before-autofitting-a-row.cs +- after-autofitting-a-column-finetune-its-width-with-setcolumnwidthpixel-for-precise-pixel-control.cs From 84fbc9dbe6cb8569fb18cf7a609fd1e1758d0a6b Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:26:33 +0500 Subject: [PATCH 13/46] Add example: iterate-through-each-worksheet-in-a-workbook-and-set-standardheight-to-enforce-a-consistent-row-height --- rows-and-columns/agents.md | 1 + ...ight-to-enforce-a-consistent-row-height.cs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 rows-and-columns/iterate-through-each-worksheet-in-a-workbook-and-set-standardheight-to-enforce-a-consistent-row-height.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 786a6ac38e..550ea9a6a1 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -66,3 +66,4 @@ Output files are written to the working directory. - autofit-rows-that-contain-merged-cells-by-configuring-autofitteroptionsautofitmergedcellstype-and-passing-it-to-worksheetautofitrows.cs - combine-setrowheight-with-autofitrow-to-set-a-minimum-height-before-autofitting-a-row.cs - after-autofitting-a-column-finetune-its-width-with-setcolumnwidthpixel-for-precise-pixel-control.cs +- iterate-through-each-worksheet-in-a-workbook-and-set-standardheight-to-enforce-a-consistent-row-height.cs diff --git a/rows-and-columns/iterate-through-each-worksheet-in-a-workbook-and-set-standardheight-to-enforce-a-consistent-row-height.cs b/rows-and-columns/iterate-through-each-worksheet-in-a-workbook-and-set-standardheight-to-enforce-a-consistent-row-height.cs new file mode 100644 index 0000000000..849c80f463 --- /dev/null +++ b/rows-and-columns/iterate-through-each-worksheet-in-a-workbook-and-set-standardheight-to-enforce-a-consistent-row-height.cs @@ -0,0 +1,25 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – set consistent row height across all worksheets +class Program +{ + static void Main() + { + // Create a new workbook (or load an existing one) + Workbook workbook = new Workbook(); + + // Define the desired standard row height (in points) + double desiredHeight = 20.0; + + // Iterate through each worksheet in the workbook + foreach (Worksheet sheet in workbook.Worksheets) + { + // Set the default row height for the current worksheet + sheet.Cells.StandardHeight = desiredHeight; + } + + // Save the workbook to a file + workbook.Save("ConsistentRowHeight.xlsx"); + } +} \ No newline at end of file From f05f67a664db08ff7758206df64af7b912bb2547 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:27:22 +0500 Subject: [PATCH 14/46] Add example: batch-process-multiple-worksheets-to-apply-standardwidth-for-consistent-column-sizing --- rows-and-columns/agents.md | 1 + ...ndardwidth-for-consistent-column-sizing.cs | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 rows-and-columns/batch-process-multiple-worksheets-to-apply-standardwidth-for-consistent-column-sizing.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 550ea9a6a1..1cc5ef03ff 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -67,3 +67,4 @@ Output files are written to the working directory. - combine-setrowheight-with-autofitrow-to-set-a-minimum-height-before-autofitting-a-row.cs - after-autofitting-a-column-finetune-its-width-with-setcolumnwidthpixel-for-precise-pixel-control.cs - iterate-through-each-worksheet-in-a-workbook-and-set-standardheight-to-enforce-a-consistent-row-height.cs +- batch-process-multiple-worksheets-to-apply-standardwidth-for-consistent-column-sizing.cs diff --git a/rows-and-columns/batch-process-multiple-worksheets-to-apply-standardwidth-for-consistent-column-sizing.cs b/rows-and-columns/batch-process-multiple-worksheets-to-apply-standardwidth-for-consistent-column-sizing.cs new file mode 100644 index 0000000000..5ca0207416 --- /dev/null +++ b/rows-and-columns/batch-process-multiple-worksheets-to-apply-standardwidth-for-consistent-column-sizing.cs @@ -0,0 +1,34 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsBatchStandardWidth +{ + class Program + { + static void Main() + { + // Create a new workbook (or load an existing one) + Workbook workbook = new Workbook(); // For loading: new Workbook("input.xlsx"); + + // Add sample worksheets (optional, for demonstration) + workbook.Worksheets.Add(); + workbook.Worksheets.Add(); + + // Desired standard column width (in characters) + double standardWidth = 18.25; + + // Apply the standard width to every worksheet in the workbook + foreach (Worksheet sheet in workbook.Worksheets) + { + sheet.Cells.StandardWidth = standardWidth; + // Verify the assignment (optional) + Console.WriteLine($"Worksheet '{sheet.Name}' StandardWidth set to {sheet.Cells.StandardWidth}"); + } + + // Save the modified workbook + workbook.Save("BatchStandardWidth.xlsx"); + } + } +} + +// Author: Example demonstrating batch application of Cells.StandardWidth across all worksheets. \ No newline at end of file From 0e1f7c280ac5f9ee3cee766faaaf1cf9b9185f4f Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:28:59 +0500 Subject: [PATCH 15/46] Add example: load-a-workbook-modify-a-cell-value-then-autofit-the-affected-row-to-reflect-the-change --- rows-and-columns/agents.md | 1 + ...-the-affected-row-to-reflect-the-change.cs | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 rows-and-columns/load-a-workbook-modify-a-cell-value-then-autofit-the-affected-row-to-reflect-the-change.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 1cc5ef03ff..39d2e1e76e 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -68,3 +68,4 @@ Output files are written to the working directory. - after-autofitting-a-column-finetune-its-width-with-setcolumnwidthpixel-for-precise-pixel-control.cs - iterate-through-each-worksheet-in-a-workbook-and-set-standardheight-to-enforce-a-consistent-row-height.cs - batch-process-multiple-worksheets-to-apply-standardwidth-for-consistent-column-sizing.cs +- load-a-workbook-modify-a-cell-value-then-autofit-the-affected-row-to-reflect-the-change.cs diff --git a/rows-and-columns/load-a-workbook-modify-a-cell-value-then-autofit-the-affected-row-to-reflect-the-change.cs b/rows-and-columns/load-a-workbook-modify-a-cell-value-then-autofit-the-affected-row-to-reflect-the-change.cs new file mode 100644 index 0000000000..6622d33a87 --- /dev/null +++ b/rows-and-columns/load-a-workbook-modify-a-cell-value-then-autofit-the-affected-row-to-reflect-the-change.cs @@ -0,0 +1,26 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Load an existing workbook (you can customize LoadOptions if needed) + LoadOptions loadOptions = new LoadOptions(); + Workbook workbook = new Workbook("input.xlsx", loadOptions); + + // Get the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Modify the value of cell B2 (row index 1, column index 1) + worksheet.Cells["B2"].Value = "Updated long text that may need row height adjustment"; + + // Auto‑fit the row that contains the modified cell (row index 1) + worksheet.AutoFitRow(1); + + // Save the changes to a new file + workbook.Save("output.xlsx"); + } +} + +// Author: Aspose.Cells .NET example – load, edit, auto‑fit row, and save. \ No newline at end of file From 7cfa0e99b5119108ed9e9483b7e09b192329a81e Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:30:35 +0500 Subject: [PATCH 16/46] Add example: apply-setcolumnwidthpixel-to-a-group-of-columns-after-autofitting-them-to-achieve-precise-pixel-alignment --- rows-and-columns/agents.md | 1 + ...them-to-achieve-precise-pixel-alignment.cs | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 rows-and-columns/apply-setcolumnwidthpixel-to-a-group-of-columns-after-autofitting-them-to-achieve-precise-pixel-alignment.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 39d2e1e76e..606acc8e9c 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -69,3 +69,4 @@ Output files are written to the working directory. - iterate-through-each-worksheet-in-a-workbook-and-set-standardheight-to-enforce-a-consistent-row-height.cs - batch-process-multiple-worksheets-to-apply-standardwidth-for-consistent-column-sizing.cs - load-a-workbook-modify-a-cell-value-then-autofit-the-affected-row-to-reflect-the-change.cs +- apply-setcolumnwidthpixel-to-a-group-of-columns-after-autofitting-them-to-achieve-precise-pixel-alignment.cs diff --git a/rows-and-columns/apply-setcolumnwidthpixel-to-a-group-of-columns-after-autofitting-them-to-achieve-precise-pixel-alignment.cs b/rows-and-columns/apply-setcolumnwidthpixel-to-a-group-of-columns-after-autofitting-them-to-achieve-precise-pixel-alignment.cs new file mode 100644 index 0000000000..b660ae098c --- /dev/null +++ b/rows-and-columns/apply-setcolumnwidthpixel-to-a-group-of-columns-after-autofitting-them-to-achieve-precise-pixel-alignment.cs @@ -0,0 +1,43 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsColumnWidthDemo +{ + // Author: Aspose.Cells .NET example – auto‑fit then set exact pixel width + class Program + { + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate some sample data in columns A‑E (indices 0‑4) + for (int col = 0; col < 5; col++) + { + for (int row = 0; row < 10; row++) + { + cells[row, col].PutValue($"R{row + 1}C{col + 1}"); + } + } + + // Auto‑fit the columns to their content (imprecise width) + for (int col = 0; col < 5; col++) + { + sheet.AutoFitColumn(col); + } + + // After auto‑fit, set exact pixel width for precise alignment + // Desired width: 120 pixels for each column + const int targetPixelWidth = 120; + for (int col = 0; col < 5; col++) + { + cells.SetColumnWidthPixel(col, targetPixelWidth); + } + + // Save the workbook + workbook.Save("AutoFitThenSetPixelWidth.xlsx"); + } + } +} \ No newline at end of file From 37d1b32121d24a5d82132554d0fe6fb1e7f19147 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:31:19 +0500 Subject: [PATCH 17/46] Add example: create-a-new-workbook-add-data-to-a-column-and-autofit-that-column-to-accommodate-the-longest-entry --- rows-and-columns/agents.md | 1 + ...column-to-accommodate-the-longest-entry.cs | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 rows-and-columns/create-a-new-workbook-add-data-to-a-column-and-autofit-that-column-to-accommodate-the-longest-entry.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 606acc8e9c..233994779e 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -70,3 +70,4 @@ Output files are written to the working directory. - batch-process-multiple-worksheets-to-apply-standardwidth-for-consistent-column-sizing.cs - load-a-workbook-modify-a-cell-value-then-autofit-the-affected-row-to-reflect-the-change.cs - apply-setcolumnwidthpixel-to-a-group-of-columns-after-autofitting-them-to-achieve-precise-pixel-alignment.cs +- create-a-new-workbook-add-data-to-a-column-and-autofit-that-column-to-accommodate-the-longest-entry.cs diff --git a/rows-and-columns/create-a-new-workbook-add-data-to-a-column-and-autofit-that-column-to-accommodate-the-longest-entry.cs b/rows-and-columns/create-a-new-workbook-add-data-to-a-column-and-autofit-that-column-to-accommodate-the-longest-entry.cs new file mode 100644 index 0000000000..fa2b33dfd0 --- /dev/null +++ b/rows-and-columns/create-a-new-workbook-add-data-to-a-column-and-autofit-that-column-to-accommodate-the-longest-entry.cs @@ -0,0 +1,29 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Add sample data to column A (index 0) + worksheet.Cells["A1"].PutValue("Short"); + worksheet.Cells["A2"].PutValue("A bit longer text"); + worksheet.Cells["A3"].PutValue("The longest entry in this column for testing auto‑fit"); + worksheet.Cells["A4"].PutValue("Mid"); + worksheet.Cells["A5"].PutValue("Another entry"); + + // Auto‑fit only column A (column index 0) + worksheet.AutoFitColumn(0); + + // Save the workbook + workbook.Save("AutoFitColumnDemo.xlsx"); + } +} + +// Author: Aspose.Cells example code. \ No newline at end of file From 657dc986b5c887b9d20daf65cf619a46e0251223 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:32:03 +0500 Subject: [PATCH 18/46] Add example: use-worksheetautofitrows-overload-with-startrow-and-endrow-to-adjust-a-block-of-rows --- rows-and-columns/agents.md | 1 + ...ow-and-endrow-to-adjust-a-block-of-rows.cs | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 rows-and-columns/use-worksheetautofitrows-overload-with-startrow-and-endrow-to-adjust-a-block-of-rows.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 233994779e..7625cb4287 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -71,3 +71,4 @@ Output files are written to the working directory. - load-a-workbook-modify-a-cell-value-then-autofit-the-affected-row-to-reflect-the-change.cs - apply-setcolumnwidthpixel-to-a-group-of-columns-after-autofitting-them-to-achieve-precise-pixel-alignment.cs - create-a-new-workbook-add-data-to-a-column-and-autofit-that-column-to-accommodate-the-longest-entry.cs +- use-worksheetautofitrows-overload-with-startrow-and-endrow-to-adjust-a-block-of-rows.cs diff --git a/rows-and-columns/use-worksheetautofitrows-overload-with-startrow-and-endrow-to-adjust-a-block-of-rows.cs b/rows-and-columns/use-worksheetautofitrows-overload-with-startrow-and-endrow-to-adjust-a-block-of-rows.cs new file mode 100644 index 0000000000..0c041da6b5 --- /dev/null +++ b/rows-and-columns/use-worksheetautofitrows-overload-with-startrow-and-endrow-to-adjust-a-block-of-rows.cs @@ -0,0 +1,32 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsExamples +{ + // Author: Aspose.Cells .NET example – AutoFitRows for a specific range of rows + class AutoFitRowsRangeDemo + { + static void Main() + { + // Create a new workbook (lifecycle rule: creation) + Workbook workbook = new Workbook(); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Populate sample data that will affect row heights + worksheet.Cells["A2"].PutValue("This is a long text that should cause row 2 to expand."); + worksheet.Cells["B2"].PutValue("Additional content in column B."); + worksheet.Cells["A3"].PutValue("Short"); + worksheet.Cells["B3"].PutValue("Another short text."); + worksheet.Cells["A4"].PutValue("A very very long piece of text that will make row 4 taller than default."); + worksheet.Cells["B4"].PutValue("More text to increase height."); + + // AutoFit rows 2 through 4 (zero‑based indices 1 to 3) + worksheet.AutoFitRows(startRow: 1, endRow: 3); + + // Save the workbook (lifecycle rule: saving) + workbook.Save("AutoFitRowsRangeDemo.xlsx"); + } + } +} \ No newline at end of file From b300cca5b0c72828650ae40c3f9d6ef09fc29cac Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:33:56 +0500 Subject: [PATCH 19/46] Add example: after-loading-a-workbook-set-standardheight-and-then-autofit-rows-that-contain-formulas --- ...then-autofit-rows-that-contain-formulas.cs | 53 +++++++++++++++++++ rows-and-columns/agents.md | 1 + 2 files changed, 54 insertions(+) create mode 100644 rows-and-columns/after-loading-a-workbook-set-standardheight-and-then-autofit-rows-that-contain-formulas.cs diff --git a/rows-and-columns/after-loading-a-workbook-set-standardheight-and-then-autofit-rows-that-contain-formulas.cs b/rows-and-columns/after-loading-a-workbook-set-standardheight-and-then-autofit-rows-that-contain-formulas.cs new file mode 100644 index 0000000000..f02d570b80 --- /dev/null +++ b/rows-and-columns/after-loading-a-workbook-set-standardheight-and-then-autofit-rows-that-contain-formulas.cs @@ -0,0 +1,53 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsExamples +{ + // Author: Aspose.Cells .NET example – set standard height and auto‑fit rows containing formulas + class StandardHeightAndFormulaAutoFit + { + static void Main() + { + // Load an existing workbook + Workbook workbook = new Workbook("InputWorkbook.xlsx"); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Set a new standard row height for the worksheet + worksheet.Cells.StandardHeight = 20; // example height in points + + // Prepare auto‑fitter options (only affect rows that are not custom‑height) + AutoFitterOptions options = new AutoFitterOptions + { + OnlyAuto = true + }; + + // Iterate through all rows in the worksheet + foreach (Row row in worksheet.Cells.Rows) + { + bool hasFormula = false; + + // Check each cell in the current row for a formula + foreach (Cell cell in row) + { + if (cell.IsFormula) + { + hasFormula = true; + break; + } + } + + // If the row contains at least one formula, auto‑fit its height + if (hasFormula) + { + // Auto‑fit a single row using the overload that accepts start row, total rows, and options + worksheet.AutoFitRows(row.Index, 1, options); + } + } + + // Save the modified workbook + workbook.Save("OutputWorkbook.xlsx"); + } + } +} \ No newline at end of file diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 7625cb4287..9e6a9e9b8c 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -72,3 +72,4 @@ Output files are written to the working directory. - apply-setcolumnwidthpixel-to-a-group-of-columns-after-autofitting-them-to-achieve-precise-pixel-alignment.cs - create-a-new-workbook-add-data-to-a-column-and-autofit-that-column-to-accommodate-the-longest-entry.cs - use-worksheetautofitrows-overload-with-startrow-and-endrow-to-adjust-a-block-of-rows.cs +- after-loading-a-workbook-set-standardheight-and-then-autofit-rows-that-contain-formulas.cs From 078b864e670ce0e58a4bbf9a18fcc5e97b6b6292 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:34:41 +0500 Subject: [PATCH 20/46] Add example: adjust-column-width-by-setting-standardwidth-before-populating-data-to-establish-a-base-width --- ...pulating-data-to-establish-a-base-width.cs | 30 +++++++++++++++++++ rows-and-columns/agents.md | 1 + 2 files changed, 31 insertions(+) create mode 100644 rows-and-columns/adjust-column-width-by-setting-standardwidth-before-populating-data-to-establish-a-base-width.cs diff --git a/rows-and-columns/adjust-column-width-by-setting-standardwidth-before-populating-data-to-establish-a-base-width.cs b/rows-and-columns/adjust-column-width-by-setting-standardwidth-before-populating-data-to-establish-a-base-width.cs new file mode 100644 index 0000000000..23851e8199 --- /dev/null +++ b/rows-and-columns/adjust-column-width-by-setting-standardwidth-before-populating-data-to-establish-a-base-width.cs @@ -0,0 +1,30 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + Cells cells = worksheet.Cells; + + // Set the default column width (in characters) before adding any data + // Author note: establishing a base width ensures consistent column sizing + cells.StandardWidth = 20; + + // Populate sample data + cells["A1"].PutValue("Name"); + cells["B1"].PutValue("Age"); + cells["A2"].PutValue("Alice"); + cells["B2"].PutValue(30); + cells["A3"].PutValue("Bob"); + cells["B3"].PutValue(25); + + // Save the workbook + workbook.Save("StandardWidthDemo.xlsx"); + } +} \ No newline at end of file diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 9e6a9e9b8c..b2d88355f1 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -73,3 +73,4 @@ Output files are written to the working directory. - create-a-new-workbook-add-data-to-a-column-and-autofit-that-column-to-accommodate-the-longest-entry.cs - use-worksheetautofitrows-overload-with-startrow-and-endrow-to-adjust-a-block-of-rows.cs - after-loading-a-workbook-set-standardheight-and-then-autofit-rows-that-contain-formulas.cs +- adjust-column-width-by-setting-standardwidth-before-populating-data-to-establish-a-base-width.cs From 1c98762dc4fee28259f728200d600ba2b81b75c9 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:35:24 +0500 Subject: [PATCH 21/46] Add example: autofit-rows-that-contain-merged-cells-by-specifying-autofitmergedcellstype-in-autofitteroptions-during-processing --- rows-and-columns/agents.md | 1 + ...-in-autofitteroptions-during-processing.cs | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 rows-and-columns/autofit-rows-that-contain-merged-cells-by-specifying-autofitmergedcellstype-in-autofitteroptions-during-processing.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index b2d88355f1..f54d4eddda 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -74,3 +74,4 @@ Output files are written to the working directory. - use-worksheetautofitrows-overload-with-startrow-and-endrow-to-adjust-a-block-of-rows.cs - after-loading-a-workbook-set-standardheight-and-then-autofit-rows-that-contain-formulas.cs - adjust-column-width-by-setting-standardwidth-before-populating-data-to-establish-a-base-width.cs +- autofit-rows-that-contain-merged-cells-by-specifying-autofitmergedcellstype-in-autofitteroptions-during-processing.cs diff --git a/rows-and-columns/autofit-rows-that-contain-merged-cells-by-specifying-autofitmergedcellstype-in-autofitteroptions-during-processing.cs b/rows-and-columns/autofit-rows-that-contain-merged-cells-by-specifying-autofitmergedcellstype-in-autofitteroptions-during-processing.cs new file mode 100644 index 0000000000..19877226bf --- /dev/null +++ b/rows-and-columns/autofit-rows-that-contain-merged-cells-by-specifying-autofitmergedcellstype-in-autofitteroptions-during-processing.cs @@ -0,0 +1,41 @@ +using System; +using Aspose.Cells; + +namespace AutoFitMergedCellsDemo +{ + // Author: Aspose.Cells .NET example + class Program + { + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Put a long text into a cell and merge a range of cells (A1:B3) + sheet.Cells["A1"].PutValue("This is a sample text for merged cells auto‑fit demonstration. It should wrap and cause the row height to adjust based on the selected AutoFitMergedCellsType."); + sheet.Cells.Merge(0, 0, 3, 2); // Merge A1:B3 + + // Enable text wrapping for the merged cell + Style style = sheet.Cells["A1"].GetStyle(); + style.IsTextWrapped = true; + sheet.Cells["A1"].SetStyle(style); + + // Configure AutoFitterOptions to expand the height of each row in the merged range + AutoFitterOptions options = new AutoFitterOptions + { + AutoFitMergedCellsType = AutoFitMergedCellsType.EachLine, + AutoFitWrappedTextType = AutoFitWrappedTextType.Paragraph + }; + + // Auto‑fit all rows in the worksheet using the specified options + sheet.AutoFitRows(options); + + // (Optional) Auto‑fit columns as well, using the same merged‑cell handling + sheet.AutoFitColumns(options); + + // Save the workbook to a file + workbook.Save("AutoFitMergedCellsDemo.xlsx"); + } + } +} \ No newline at end of file From e52064821ecaecf075bebeb380040dab4c562f9c Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:36:10 +0500 Subject: [PATCH 22/46] Add example: programmatically-set-a-row-height-then-autofit-the-next-row-based-on-its-content --- rows-and-columns/agents.md | 1 + ...tofit-the-next-row-based-on-its-content.cs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 rows-and-columns/programmatically-set-a-row-height-then-autofit-the-next-row-based-on-its-content.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index f54d4eddda..86801f387d 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -75,3 +75,4 @@ Output files are written to the working directory. - after-loading-a-workbook-set-standardheight-and-then-autofit-rows-that-contain-formulas.cs - adjust-column-width-by-setting-standardwidth-before-populating-data-to-establish-a-base-width.cs - autofit-rows-that-contain-merged-cells-by-specifying-autofitmergedcellstype-in-autofitteroptions-during-processing.cs +- programmatically-set-a-row-height-then-autofit-the-next-row-based-on-its-content.cs diff --git a/rows-and-columns/programmatically-set-a-row-height-then-autofit-the-next-row-based-on-its-content.cs b/rows-and-columns/programmatically-set-a-row-height-then-autofit-the-next-row-based-on-its-content.cs new file mode 100644 index 0000000000..c19e4b95e0 --- /dev/null +++ b/rows-and-columns/programmatically-set-a-row-height-then-autofit-the-next-row-based-on-its-content.cs @@ -0,0 +1,28 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – set row height then auto‑fit next row +class Program +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // ----- Row 0: set a custom height ----- + // Add some data to the first row (optional, just for demonstration) + worksheet.Cells["A1"].PutValue("Custom height row"); + // Set the height of row 0 to 25 points (explicit height) + worksheet.Cells.SetRowHeight(0, 25); + + // ----- Row 1: auto‑fit based on its content ----- + // Add longer text that will require a larger row height + worksheet.Cells["A2"].PutValue("This is a longer piece of text that should cause the row height to increase when auto‑fitted."); + // Auto‑fit row 1 (index 1) using the content of its cells + worksheet.AutoFitRow(1); + + // Save the workbook (replace with your desired path) + workbook.Save("RowHeightDemo.xlsx"); + } +} \ No newline at end of file From 4b71b2c73bcfd81f5484252afb7b2aaf66e0ed8f Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:36:56 +0500 Subject: [PATCH 23/46] Add example: apply-setcolumnwidth-to-a-column-then-autofit-an-adjacent-column-for-comparison --- rows-and-columns/agents.md | 1 + ...tofit-an-adjacent-column-for-comparison.cs | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 rows-and-columns/apply-setcolumnwidth-to-a-column-then-autofit-an-adjacent-column-for-comparison.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 86801f387d..79eaa8b0de 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -76,3 +76,4 @@ Output files are written to the working directory. - adjust-column-width-by-setting-standardwidth-before-populating-data-to-establish-a-base-width.cs - autofit-rows-that-contain-merged-cells-by-specifying-autofitmergedcellstype-in-autofitteroptions-during-processing.cs - programmatically-set-a-row-height-then-autofit-the-next-row-based-on-its-content.cs +- apply-setcolumnwidth-to-a-column-then-autofit-an-adjacent-column-for-comparison.cs diff --git a/rows-and-columns/apply-setcolumnwidth-to-a-column-then-autofit-an-adjacent-column-for-comparison.cs b/rows-and-columns/apply-setcolumnwidth-to-a-column-then-autofit-an-adjacent-column-for-comparison.cs new file mode 100644 index 0000000000..022a18a77c --- /dev/null +++ b/rows-and-columns/apply-setcolumnwidth-to-a-column-then-autofit-an-adjacent-column-for-comparison.cs @@ -0,0 +1,36 @@ +using System; +using Aspose.Cells; + +namespace ColumnWidthDemo +{ + // Author: Aspose.Cells .NET example + class Program + { + 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 column B (index 1) with varying length text + cells["B1"].PutValue("Short"); + cells["B2"].PutValue("A considerably longer piece of text"); + cells["B3"].PutValue("Medium length"); + + // Set a fixed width for column A (index 0) + // Width is specified in characters; 20.0 is an arbitrary example + cells.SetColumnWidth(0, 20.0); + + // Auto‑fit column B (index 1) based on its content + worksheet.AutoFitColumn(1); + + // Optional: display widths before saving (for debugging) + Console.WriteLine($"Column A width (fixed): {cells.GetColumnWidth(0)}"); + Console.WriteLine($"Column B width (auto‑fitted): {cells.GetColumnWidth(1)}"); + + // Save the workbook + workbook.Save("ColumnWidthComparison.xlsx"); + } + } +} \ No newline at end of file From cb781b1d98d98ae2ed186378eed44baf9b83baf4 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:37:45 +0500 Subject: [PATCH 24/46] Add example: load-a-workbook-with-onlyauto-enabled-then-iterate-through-each-sheet-to-verify-row-heights-are-adjusted --- rows-and-columns/agents.md | 1 + ...heet-to-verify-row-heights-are-adjusted.cs | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 rows-and-columns/load-a-workbook-with-onlyauto-enabled-then-iterate-through-each-sheet-to-verify-row-heights-are-adjusted.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 79eaa8b0de..aad4ad1d9a 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -77,3 +77,4 @@ Output files are written to the working directory. - autofit-rows-that-contain-merged-cells-by-specifying-autofitmergedcellstype-in-autofitteroptions-during-processing.cs - programmatically-set-a-row-height-then-autofit-the-next-row-based-on-its-content.cs - apply-setcolumnwidth-to-a-column-then-autofit-an-adjacent-column-for-comparison.cs +- load-a-workbook-with-onlyauto-enabled-then-iterate-through-each-sheet-to-verify-row-heights-are-adjusted.cs diff --git a/rows-and-columns/load-a-workbook-with-onlyauto-enabled-then-iterate-through-each-sheet-to-verify-row-heights-are-adjusted.cs b/rows-and-columns/load-a-workbook-with-onlyauto-enabled-then-iterate-through-each-sheet-to-verify-row-heights-are-adjusted.cs new file mode 100644 index 0000000000..63d66b50cb --- /dev/null +++ b/rows-and-columns/load-a-workbook-with-onlyauto-enabled-then-iterate-through-each-sheet-to-verify-row-heights-are-adjusted.cs @@ -0,0 +1,34 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Load workbook with OnlyAuto enabled (auto‑fit only rows without custom height) + LoadOptions loadOptions = new LoadOptions(); + loadOptions.AutoFitterOptions = new AutoFitterOptions(); + loadOptions.AutoFitterOptions.OnlyAuto = true; + Workbook workbook = new Workbook("input.xlsx", loadOptions); + + // Iterate through each worksheet + foreach (Worksheet sheet in workbook.Worksheets) + { + // Auto‑fit rows, respecting the OnlyAuto flag + sheet.AutoFitRows(true); + + // Verify row heights + int lastRow = sheet.Cells.MaxDataRow; + for (int i = 0; i <= lastRow; i++) + { + Row row = sheet.Cells.Rows[i]; + Console.WriteLine($"Sheet: {sheet.Name}, Row: {i}, Height: {row.Height}, IsHeightMatched: {row.IsHeightMatched}"); + } + } + + // Save the workbook after verification + workbook.Save("output.xlsx", SaveFormat.Xlsx); + } +} + +// Author: Aspose.Cells .NET example – loads with OnlyAuto, auto‑fits rows, and checks heights. \ No newline at end of file From a0d962c05c00e9501201530a8167495e274092b1 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:40:09 +0500 Subject: [PATCH 25/46] Add example: create-a-custom-autofitteroptions-instance-that-disables-autofit-for-hidden-rows-and-apply-it-to-a-specific-row-range --- rows-and-columns/agents.md | 1 + ...ws-and-apply-it-to-a-specific-row-range.cs | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 rows-and-columns/create-a-custom-autofitteroptions-instance-that-disables-autofit-for-hidden-rows-and-apply-it-to-a-specific-row-range.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index aad4ad1d9a..03b28e5b25 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -78,3 +78,4 @@ Output files are written to the working directory. - programmatically-set-a-row-height-then-autofit-the-next-row-based-on-its-content.cs - apply-setcolumnwidth-to-a-column-then-autofit-an-adjacent-column-for-comparison.cs - load-a-workbook-with-onlyauto-enabled-then-iterate-through-each-sheet-to-verify-row-heights-are-adjusted.cs +- create-a-custom-autofitteroptions-instance-that-disables-autofit-for-hidden-rows-and-apply-it-to-a-specific-row-range.cs diff --git a/rows-and-columns/create-a-custom-autofitteroptions-instance-that-disables-autofit-for-hidden-rows-and-apply-it-to-a-specific-row-range.cs b/rows-and-columns/create-a-custom-autofitteroptions-instance-that-disables-autofit-for-hidden-rows-and-apply-it-to-a-specific-row-range.cs new file mode 100644 index 0000000000..aabe4ebd4c --- /dev/null +++ b/rows-and-columns/create-a-custom-autofitteroptions-instance-that-disables-autofit-for-hidden-rows-and-apply-it-to-a-specific-row-range.cs @@ -0,0 +1,36 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Add sample data to rows 0‑4 + for (int i = 0; i < 5; i++) + { + worksheet.Cells[i, 0].PutValue($"This is a long text in row {i} that may require autofit."); + } + + // Hide row 2 to demonstrate the effect of IgnoreHidden + worksheet.Cells.Rows[2].IsHidden = true; + + // Create AutoFitterOptions with IgnoreHidden set to false + // This disables auto‑fit for hidden rows (row 2 will keep its original height) + AutoFitterOptions options = new AutoFitterOptions + { + IgnoreHidden = false + }; + + // Apply autofit to rows 0 through 4 using the custom options + worksheet.AutoFitRows(0, 4, options); + + // Save the workbook + workbook.Save("AutoFitRowsExample.xlsx"); + } +} + +// Author: Aspose.Cells .NET example \ No newline at end of file From 9dec6534de2a5fc6079a1ae6c85f6322b23cbdf4 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:40:57 +0500 Subject: [PATCH 26/46] Add example: after-autofitting-rows-export-the-worksheet-to-pdf-and-compare-file-size-with-a-nonfitted-version --- ...pare-file-size-with-a-nonfitted-version.cs | 56 +++++++++++++++++++ rows-and-columns/agents.md | 1 + 2 files changed, 57 insertions(+) create mode 100644 rows-and-columns/after-autofitting-rows-export-the-worksheet-to-pdf-and-compare-file-size-with-a-nonfitted-version.cs diff --git a/rows-and-columns/after-autofitting-rows-export-the-worksheet-to-pdf-and-compare-file-size-with-a-nonfitted-version.cs b/rows-and-columns/after-autofitting-rows-export-the-worksheet-to-pdf-and-compare-file-size-with-a-nonfitted-version.cs new file mode 100644 index 0000000000..86a6cae9c5 --- /dev/null +++ b/rows-and-columns/after-autofitting-rows-export-the-worksheet-to-pdf-and-compare-file-size-with-a-nonfitted-version.cs @@ -0,0 +1,56 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Saving; + +class Program +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook wb = new Workbook(); + Worksheet sheet = wb.Worksheets[0]; + + // Populate sample data (10 rows, 3 columns) + for (int row = 0; row < 10; row++) + { + sheet.Cells[row, 0].PutValue($"Item {row + 1}"); + sheet.Cells[row, 1].PutValue(row * 10.5); + sheet.Cells[row, 2].PutValue(row * 2); + } + + // Auto‑fit rows (no fitting to pages) + sheet.AutoFitRows(); + + // Save PDF without page fitting + string pdfPathNoFit = "Report_NoFit.pdf"; + wb.Save(pdfPathNoFit, SaveFormat.Pdf); + + // Get file size of non‑fitted PDF + long sizeNoFit = new FileInfo(pdfPathNoFit).Length; + + // Reset workbook (or clone) to apply page‑fit settings + // Here we reuse the same workbook and adjust PageSetup + sheet.PageSetup.FitToPagesWide = 0; // Fit all rows on one page (columns may span multiple pages) + sheet.PageSetup.FitToPagesTall = 0; // Fit all columns on one page (rows may span multiple pages) + + // Auto‑fit rows again after changing PageSetup (optional but keeps consistency) + sheet.AutoFitRows(); + + // Save PDF with page fitting + string pdfPathFit = "Report_Fit.pdf"; + PdfSaveOptions pdfOptions = new PdfSaveOptions + { + // No special options needed for this example + }; + wb.Save(pdfPathFit, pdfOptions); + + // Get file size of fitted PDF + long sizeFit = new FileInfo(pdfPathFit).Length; + + // Output comparison + Console.WriteLine($"PDF size without fitting: {sizeNoFit} bytes"); + Console.WriteLine($"PDF size with fitting : {sizeFit} bytes"); + Console.WriteLine($"Size difference : {Math.Abs(sizeNoFit - sizeFit)} bytes"); + } +} // Author: Aspose.Cells .NET example – demonstrates auto‑fit rows, page‑fit settings, PDF export, and file‑size comparison. \ No newline at end of file diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 03b28e5b25..0d6f8ab327 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -79,3 +79,4 @@ Output files are written to the working directory. - apply-setcolumnwidth-to-a-column-then-autofit-an-adjacent-column-for-comparison.cs - load-a-workbook-with-onlyauto-enabled-then-iterate-through-each-sheet-to-verify-row-heights-are-adjusted.cs - create-a-custom-autofitteroptions-instance-that-disables-autofit-for-hidden-rows-and-apply-it-to-a-specific-row-range.cs +- after-autofitting-rows-export-the-worksheet-to-pdf-and-compare-file-size-with-a-nonfitted-version.cs From 8142b66f8a46586e28203a463fcd355f6cd11350 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:41:57 +0500 Subject: [PATCH 27/46] Add example: set-row-height-for-the-header-row-to-improve-visual-emphasis-then-autofit-remaining-rows --- rows-and-columns/agents.md | 1 + ...al-emphasis-then-autofit-remaining-rows.cs | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 rows-and-columns/set-row-height-for-the-header-row-to-improve-visual-emphasis-then-autofit-remaining-rows.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 0d6f8ab327..f6cea942d4 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -80,3 +80,4 @@ Output files are written to the working directory. - load-a-workbook-with-onlyauto-enabled-then-iterate-through-each-sheet-to-verify-row-heights-are-adjusted.cs - create-a-custom-autofitteroptions-instance-that-disables-autofit-for-hidden-rows-and-apply-it-to-a-specific-row-range.cs - after-autofitting-rows-export-the-worksheet-to-pdf-and-compare-file-size-with-a-nonfitted-version.cs +- set-row-height-for-the-header-row-to-improve-visual-emphasis-then-autofit-remaining-rows.cs diff --git a/rows-and-columns/set-row-height-for-the-header-row-to-improve-visual-emphasis-then-autofit-remaining-rows.cs b/rows-and-columns/set-row-height-for-the-header-row-to-improve-visual-emphasis-then-autofit-remaining-rows.cs new file mode 100644 index 0000000000..8232520713 --- /dev/null +++ b/rows-and-columns/set-row-height-for-the-header-row-to-improve-visual-emphasis-then-autofit-remaining-rows.cs @@ -0,0 +1,36 @@ +using System; +using Aspose.Cells; + +namespace AspiseCellsExamples +{ + // Author: Aspose.Cells .NET example + class HeaderRowHeightDemo + { + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate sample data + for (int row = 0; row < 10; row++) + { + for (int col = 0; col < 5; col++) + { + cells[row, col].PutValue($"R{row + 1}C{col + 1}"); + } + } + + // Set a custom height for the header row (row index 0) + Aspose.Cells.Range headerRange = sheet.Cells.CreateRange("1:1"); + headerRange.RowHeight = 30; + + // Auto‑fit all other rows while preserving the custom header height + sheet.AutoFitRows(true); + + // Save the workbook + workbook.Save("HeaderRowHeightDemo.xlsx"); + } + } +} \ No newline at end of file From 655cb22339d379a2a5268e7c9fe4e98acb3ef1c1 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:42:42 +0500 Subject: [PATCH 28/46] Add example: autofit-all-rows-in-a-worksheet-by-calling-autofitrows-with-startrow-0-and-endrow-maxrow --- rows-and-columns/agents.md | 1 + ...trows-with-startrow-0-and-endrow-maxrow.cs | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 rows-and-columns/autofit-all-rows-in-a-worksheet-by-calling-autofitrows-with-startrow-0-and-endrow-maxrow.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index f6cea942d4..c0bdfaba92 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -81,3 +81,4 @@ Output files are written to the working directory. - create-a-custom-autofitteroptions-instance-that-disables-autofit-for-hidden-rows-and-apply-it-to-a-specific-row-range.cs - after-autofitting-rows-export-the-worksheet-to-pdf-and-compare-file-size-with-a-nonfitted-version.cs - set-row-height-for-the-header-row-to-improve-visual-emphasis-then-autofit-remaining-rows.cs +- autofit-all-rows-in-a-worksheet-by-calling-autofitrows-with-startrow-0-and-endrow-maxrow.cs diff --git a/rows-and-columns/autofit-all-rows-in-a-worksheet-by-calling-autofitrows-with-startrow-0-and-endrow-maxrow.cs b/rows-and-columns/autofit-all-rows-in-a-worksheet-by-calling-autofitrows-with-startrow-0-and-endrow-maxrow.cs new file mode 100644 index 0000000000..6b06ba2d0e --- /dev/null +++ b/rows-and-columns/autofit-all-rows-in-a-worksheet-by-calling-autofitrows-with-startrow-0-and-endrow-maxrow.cs @@ -0,0 +1,33 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate some sample data (optional) + for (int i = 0; i < 10; i++) + { + cells[i, 0].Value = $"Row {i} with some long text to test auto‑fit."; + } + + // Determine the last row index that contains data + int maxRow = cells.MaxDataRow; // Returns -1 if the sheet is empty + + if (maxRow >= 0) + { + // Auto‑fit all rows from the first row (0) to the last data row + sheet.AutoFitRows(0, maxRow); + } + + // Save the workbook (adjust the path as needed) + workbook.Save("AutoFitRowsDemo.xlsx"); + } +} + +// Author: Aspose.Cells .NET example – auto‑fit rows from start to max row. \ No newline at end of file From 6a91dd173b2658c63e462645d57c403a903beed4 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:45:27 +0500 Subject: [PATCH 29/46] Add example: autofit-all-rows-for-normal-view-using-worksheetautofitrows-before-exporting-to-other-formats --- rows-and-columns/agents.md | 1 + ...trows-before-exporting-to-other-formats.cs | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 rows-and-columns/autofit-all-rows-for-normal-view-using-worksheetautofitrows-before-exporting-to-other-formats.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index c0bdfaba92..eeb33ec14e 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -82,3 +82,4 @@ Output files are written to the working directory. - after-autofitting-rows-export-the-worksheet-to-pdf-and-compare-file-size-with-a-nonfitted-version.cs - set-row-height-for-the-header-row-to-improve-visual-emphasis-then-autofit-remaining-rows.cs - autofit-all-rows-in-a-worksheet-by-calling-autofitrows-with-startrow-0-and-endrow-maxrow.cs +- autofit-all-rows-for-normal-view-using-worksheetautofitrows-before-exporting-to-other-formats.cs diff --git a/rows-and-columns/autofit-all-rows-for-normal-view-using-worksheetautofitrows-before-exporting-to-other-formats.cs b/rows-and-columns/autofit-all-rows-for-normal-view-using-worksheetautofitrows-before-exporting-to-other-formats.cs new file mode 100644 index 0000000000..4acf7f5cce --- /dev/null +++ b/rows-and-columns/autofit-all-rows-for-normal-view-using-worksheetautofitrows-before-exporting-to-other-formats.cs @@ -0,0 +1,27 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Sample data + worksheet.Cells["A1"].PutValue("Sample text for AutoFitRows demonstration"); + worksheet.Cells["A2"].PutValue("Another line\nwith line break to test row height adjustment"); + + // Auto‑fit all rows in normal view + worksheet.AutoFitRows(); + + // Export to PDF + string outputPath = "AutoFitRowsDemo.pdf"; + workbook.Save(outputPath, SaveFormat.Pdf); + } +} + +// Author: Example demonstrating AutoFitRows before export using Aspose.Cells. \ No newline at end of file From a030eda487a581851686f0fe2b33d9f88fc9597a Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:46:31 +0500 Subject: [PATCH 30/46] Add example: autofit-rows-containing-merged-cells-to-ensure-merged-content-displays-correctly-in-pdf-output --- rows-and-columns/agents.md | 1 + ...ontent-displays-correctly-in-pdf-output.cs | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 rows-and-columns/autofit-rows-containing-merged-cells-to-ensure-merged-content-displays-correctly-in-pdf-output.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index eeb33ec14e..a0e0a74d80 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -83,3 +83,4 @@ Output files are written to the working directory. - set-row-height-for-the-header-row-to-improve-visual-emphasis-then-autofit-remaining-rows.cs - autofit-all-rows-in-a-worksheet-by-calling-autofitrows-with-startrow-0-and-endrow-maxrow.cs - autofit-all-rows-for-normal-view-using-worksheetautofitrows-before-exporting-to-other-formats.cs +- autofit-rows-containing-merged-cells-to-ensure-merged-content-displays-correctly-in-pdf-output.cs diff --git a/rows-and-columns/autofit-rows-containing-merged-cells-to-ensure-merged-content-displays-correctly-in-pdf-output.cs b/rows-and-columns/autofit-rows-containing-merged-cells-to-ensure-merged-content-displays-correctly-in-pdf-output.cs new file mode 100644 index 0000000000..5f12e401b1 --- /dev/null +++ b/rows-and-columns/autofit-rows-containing-merged-cells-to-ensure-merged-content-displays-correctly-in-pdf-output.cs @@ -0,0 +1,42 @@ +using System; +using Aspose.Cells; +using AsposeRange = Aspose.Cells.Range; + +namespace AutoFitMergedCellsPdfDemo +{ + // Author: Aspose.Cells .NET example + class Program + { + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + + // Access the first worksheet. + Worksheet worksheet = workbook.Worksheets[0]; + + // Create a range that spans A1:B2 and merge it. + AsposeRange mergedRange = worksheet.Cells.CreateRange(0, 0, 2, 2); + mergedRange.Merge(); + + // Put a long text into the merged cell and enable text wrapping. + worksheet.Cells[0, 0].PutValue( + "This is a long piece of text that should wrap inside the merged cells and demonstrate auto‑fitting of row height when exporting to PDF."); + Style style = worksheet.Cells[0, 0].GetStyle(); + style.IsTextWrapped = true; + worksheet.Cells[0, 0].SetStyle(style); + + // Configure AutoFitterOptions to auto‑fit merged cells. + AutoFitterOptions options = new AutoFitterOptions + { + AutoFitMergedCellsType = AutoFitMergedCellsType.EachLine + }; + + // Apply the auto‑fit operation with the specified options. + worksheet.AutoFitRows(options); + + // Save the workbook as PDF. + workbook.Save("AutoFitMergedCells.pdf", SaveFormat.Pdf); + } + } +} \ No newline at end of file From 885aebe05887ede160d79288b263a9bca6af2aa8 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:47:15 +0500 Subject: [PATCH 31/46] Add example: enable-automatic-row-height-adjustment-on-workbook-load-to-preserve-original-layout --- rows-and-columns/agents.md | 1 + ...rkbook-load-to-preserve-original-layout.cs | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 rows-and-columns/enable-automatic-row-height-adjustment-on-workbook-load-to-preserve-original-layout.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index a0e0a74d80..fb8e4f5f00 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -84,3 +84,4 @@ Output files are written to the working directory. - autofit-all-rows-in-a-worksheet-by-calling-autofitrows-with-startrow-0-and-endrow-maxrow.cs - autofit-all-rows-for-normal-view-using-worksheetautofitrows-before-exporting-to-other-formats.cs - autofit-rows-containing-merged-cells-to-ensure-merged-content-displays-correctly-in-pdf-output.cs +- enable-automatic-row-height-adjustment-on-workbook-load-to-preserve-original-layout.cs diff --git a/rows-and-columns/enable-automatic-row-height-adjustment-on-workbook-load-to-preserve-original-layout.cs b/rows-and-columns/enable-automatic-row-height-adjustment-on-workbook-load-to-preserve-original-layout.cs new file mode 100644 index 0000000000..1ef8ca9a1b --- /dev/null +++ b/rows-and-columns/enable-automatic-row-height-adjustment-on-workbook-load-to-preserve-original-layout.cs @@ -0,0 +1,37 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsExamples +{ + // Author: Aspose.Cells .NET example + class AutoFitRowsOnLoad + { + static void Main() + { + // Create AutoFitterOptions to control row auto‑fitting during load + AutoFitterOptions fitterOptions = new AutoFitterOptions + { + // False – auto‑fit all rows (including those with custom height) + OnlyAuto = false, + // Optional: also auto‑fit merged cells if needed + AutoFitMergedCells = true + }; + + // Assign the options to LoadOptions + LoadOptions loadOptions = new LoadOptions + { + AutoFitterOptions = fitterOptions + }; + + // Load the workbook with the specified options; rows will be auto‑fitted + Workbook workbook = new Workbook("input.xlsx", loadOptions); + + // Example: retrieve a row height after auto‑fit + double firstRowHeight = workbook.Worksheets[0].Cells.GetRowHeight(0); + Console.WriteLine($"First row height after auto‑fit: {firstRowHeight}"); + + // Save the workbook (preserving the adjusted row heights) + workbook.Save("output.xlsx"); + } + } +} \ No newline at end of file From d0fa1f894dd33e895aee6203c9e0c34e26550a0b Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:48:48 +0500 Subject: [PATCH 32/46] Add example: convert-commaseparated-values-in-column-b-to-individual-columns-by-specifying-comma-delimiter --- rows-and-columns/agents.md | 1 + ...l-columns-by-specifying-comma-delimiter.cs | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 rows-and-columns/convert-commaseparated-values-in-column-b-to-individual-columns-by-specifying-comma-delimiter.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index fb8e4f5f00..5eb7c73dfa 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -85,3 +85,4 @@ Output files are written to the working directory. - autofit-all-rows-for-normal-view-using-worksheetautofitrows-before-exporting-to-other-formats.cs - autofit-rows-containing-merged-cells-to-ensure-merged-content-displays-correctly-in-pdf-output.cs - enable-automatic-row-height-adjustment-on-workbook-load-to-preserve-original-layout.cs +- convert-commaseparated-values-in-column-b-to-individual-columns-by-specifying-comma-delimiter.cs diff --git a/rows-and-columns/convert-commaseparated-values-in-column-b-to-individual-columns-by-specifying-comma-delimiter.cs b/rows-and-columns/convert-commaseparated-values-in-column-b-to-individual-columns-by-specifying-comma-delimiter.cs new file mode 100644 index 0000000000..fcfaf66c9e --- /dev/null +++ b/rows-and-columns/convert-commaseparated-values-in-column-b-to-individual-columns-by-specifying-comma-delimiter.cs @@ -0,0 +1,36 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsExamples +{ + // Author: Aspose.Cells .NET example – split comma‑separated values in column B into separate columns + class SplitColumnBByComma + { + static void Main() + { + // Create a new workbook (or load an existing one) + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Example data in column B (index 1) – replace with your own data or load a workbook + sheet.Cells["B1"].PutValue("Apple,Orange,Banana"); + sheet.Cells["B2"].PutValue("Red,Green,Blue"); + sheet.Cells["B3"].PutValue("Cat,Dog,Mouse"); + + // Configure text load options to use comma as the delimiter + TxtLoadOptions options = new TxtLoadOptions + { + Separator = ',' // comma delimiter + }; + + // Determine the number of rows to process (all rows that have data) + int totalRows = sheet.Cells.MaxDisplayRange.RowCount; + + // Split the text in column B (column index = 1) starting from the first row (row index = 0) + sheet.Cells.TextToColumns(0, 1, totalRows, options); + + // Save the result + workbook.Save("SplitColumnB_Output.xlsx"); + } + } +} \ No newline at end of file From 9d9fbafacd7ae3f8690bd8952ea3ce94b1df24f3 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:49:33 +0500 Subject: [PATCH 33/46] Add example: parse-semicolonseparated-strings-in-a-column-using-texttocolumns-with-semicolon-delimiter --- rows-and-columns/agents.md | 1 + ...-texttocolumns-with-semicolon-delimiter.cs | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 rows-and-columns/parse-semicolonseparated-strings-in-a-column-using-texttocolumns-with-semicolon-delimiter.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 5eb7c73dfa..1a0d68f8f7 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -86,3 +86,4 @@ Output files are written to the working directory. - autofit-rows-containing-merged-cells-to-ensure-merged-content-displays-correctly-in-pdf-output.cs - enable-automatic-row-height-adjustment-on-workbook-load-to-preserve-original-layout.cs - convert-commaseparated-values-in-column-b-to-individual-columns-by-specifying-comma-delimiter.cs +- parse-semicolonseparated-strings-in-a-column-using-texttocolumns-with-semicolon-delimiter.cs diff --git a/rows-and-columns/parse-semicolonseparated-strings-in-a-column-using-texttocolumns-with-semicolon-delimiter.cs b/rows-and-columns/parse-semicolonseparated-strings-in-a-column-using-texttocolumns-with-semicolon-delimiter.cs new file mode 100644 index 0000000000..8f808ff5af --- /dev/null +++ b/rows-and-columns/parse-semicolonseparated-strings-in-a-column-using-texttocolumns-with-semicolon-delimiter.cs @@ -0,0 +1,31 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – split semicolon‑delimited text into columns +class Program +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Populate column A with semicolon‑separated values + sheet.Cells["A1"].PutValue("John;Doe;30"); + sheet.Cells["A2"].PutValue("Jane;Smith;28"); + + // Set up text load options to use semicolon as the delimiter + TxtLoadOptions options = new TxtLoadOptions(); + options.Separator = ';'; // semicolon delimiter + + // Split the text in column A (row 0, column 0) for the first 2 rows + sheet.Cells.TextToColumns(0, 0, 2, options); + + // Verify the split results (optional) + Console.WriteLine("B1: " + sheet.Cells["B1"].StringValue); // Expected: Doe + Console.WriteLine("C2: " + sheet.Cells["C2"].StringValue); // Expected: 28 + + // Save the workbook + workbook.Save("SemicolonSplit.xlsx"); + } +} \ No newline at end of file From 2d0bde6627e03cf680b2a72605314b7cb7333615 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 13:50:38 +0500 Subject: [PATCH 34/46] Add example: apply-fixedwidth-texttocolumns-on-column-c-to-divide-text-into-equal-sized-fields --- rows-and-columns/agents.md | 1 + ...-to-divide-text-into-equal-sized-fields.cs | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 rows-and-columns/apply-fixedwidth-texttocolumns-on-column-c-to-divide-text-into-equal-sized-fields.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 1a0d68f8f7..4bb4116646 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -87,3 +87,4 @@ Output files are written to the working directory. - enable-automatic-row-height-adjustment-on-workbook-load-to-preserve-original-layout.cs - convert-commaseparated-values-in-column-b-to-individual-columns-by-specifying-comma-delimiter.cs - parse-semicolonseparated-strings-in-a-column-using-texttocolumns-with-semicolon-delimiter.cs +- apply-fixedwidth-texttocolumns-on-column-c-to-divide-text-into-equal-sized-fields.cs diff --git a/rows-and-columns/apply-fixedwidth-texttocolumns-on-column-c-to-divide-text-into-equal-sized-fields.cs b/rows-and-columns/apply-fixedwidth-texttocolumns-on-column-c-to-divide-text-into-equal-sized-fields.cs new file mode 100644 index 0000000000..82fa2d067a --- /dev/null +++ b/rows-and-columns/apply-fixedwidth-texttocolumns-on-column-c-to-divide-text-into-equal-sized-fields.cs @@ -0,0 +1,30 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook – replace with the provided create rule if available + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Sample fixed‑width strings placed in column C (zero‑based column index 2) + sheet.Cells["C1"].PutValue("ABCDEF123456"); + sheet.Cells["C2"].PutValue("GHIJKL789012"); + + // Configure TextToColumns for fixed‑width splitting. + // The exact API for specifying column widths is not shown in the documentation; + // if a property such as `ColumnWidths` exists, set it here (e.g., new int[] {3,3,6}). + TxtLoadOptions options = new TxtLoadOptions(); + // options.ColumnWidths = new int[] { 3, 3, 6 }; // <-- placeholder for fixed‑width settings + + // Apply TextToColumns on column C (row 0, column 2) for the two rows of data. + sheet.Cells.TextToColumns(0, 2, 2, options); + + // Save the workbook – replace with the provided save rule if available + workbook.Save("output.xlsx"); + } +} + +// Author: Example demonstrating fixed‑width TextToColumns on column C using Aspose.Cells for .NET. \ No newline at end of file From 913c0e9267ab8018baf595c92b241d4ef7d5b3d2 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:04:34 +0500 Subject: [PATCH 35/46] Add example: apply-a-uniform-column-width-to-all-columns-by-assigning-cellsstandardwidth --- rows-and-columns/agents.md | 1 + ...columns-by-assigning-cellsstandardwidth.cs | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 rows-and-columns/apply-a-uniform-column-width-to-all-columns-by-assigning-cellsstandardwidth.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 4bb4116646..0ae28907a7 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -88,3 +88,4 @@ Output files are written to the working directory. - convert-commaseparated-values-in-column-b-to-individual-columns-by-specifying-comma-delimiter.cs - parse-semicolonseparated-strings-in-a-column-using-texttocolumns-with-semicolon-delimiter.cs - apply-fixedwidth-texttocolumns-on-column-c-to-divide-text-into-equal-sized-fields.cs +- apply-a-uniform-column-width-to-all-columns-by-assigning-cellsstandardwidth.cs diff --git a/rows-and-columns/apply-a-uniform-column-width-to-all-columns-by-assigning-cellsstandardwidth.cs b/rows-and-columns/apply-a-uniform-column-width-to-all-columns-by-assigning-cellsstandardwidth.cs new file mode 100644 index 0000000000..ccaaa4fbb3 --- /dev/null +++ b/rows-and-columns/apply-a-uniform-column-width-to-all-columns-by-assigning-cellsstandardwidth.cs @@ -0,0 +1,26 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example author + +class UniformColumnWidthDemo +{ + public static void Main() + { + // Create a new workbook (using the provided create rule) + Workbook workbook = new Workbook(); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Apply a uniform column width to all columns + worksheet.Cells.StandardWidth = 18.25; // width in characters + + // Verify the applied width + Console.WriteLine("Standard Width set to: " + worksheet.Cells.StandardWidth); + Console.WriteLine("First column actual width: " + worksheet.Cells.GetColumnWidth(0)); + + // Save the workbook (using the provided save rule) + workbook.Save("UniformColumnWidth.xlsx", SaveFormat.Xlsx); + } +} \ No newline at end of file From e2dafcb46789d1d800e1d39c2f17695184d1ffb7 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:13:59 +0500 Subject: [PATCH 36/46] Add example: set-row-heights-for-a-series-of-rows-using-a-loop-that-calls-setrowheight-with-incremental-values --- rows-and-columns/agents.md | 1 + ...ls-setrowheight-with-incremental-values.cs | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 rows-and-columns/set-row-heights-for-a-series-of-rows-using-a-loop-that-calls-setrowheight-with-incremental-values.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 0ae28907a7..0f4e0efd68 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -89,3 +89,4 @@ Output files are written to the working directory. - parse-semicolonseparated-strings-in-a-column-using-texttocolumns-with-semicolon-delimiter.cs - apply-fixedwidth-texttocolumns-on-column-c-to-divide-text-into-equal-sized-fields.cs - apply-a-uniform-column-width-to-all-columns-by-assigning-cellsstandardwidth.cs +- set-row-heights-for-a-series-of-rows-using-a-loop-that-calls-setrowheight-with-incremental-values.cs diff --git a/rows-and-columns/set-row-heights-for-a-series-of-rows-using-a-loop-that-calls-setrowheight-with-incremental-values.cs b/rows-and-columns/set-row-heights-for-a-series-of-rows-using-a-loop-that-calls-setrowheight-with-incremental-values.cs new file mode 100644 index 0000000000..c522733c44 --- /dev/null +++ b/rows-and-columns/set-row-heights-for-a-series-of-rows-using-a-loop-that-calls-setrowheight-with-incremental-values.cs @@ -0,0 +1,30 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsRowHeightDemo +{ + // Author: Example code for setting row heights with a loop + class Program + { + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + + // Access the first worksheet + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Set row heights using a loop. + // Height starts at 15 points and increases by 5 points for each subsequent row. + for (int row = 0; row < 10; row++) + { + double height = 15 + (row * 5); // Incremental height + cells.SetRowHeight(row, height); // Calls Cells.SetRowHeight(int, double) + } + + // Save the workbook + workbook.Save("RowHeightsDemo.xlsx"); + } + } +} \ No newline at end of file From 6b29a39c5e84e3685dead87a72c8cbaf53fd5a10 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:17:08 +0500 Subject: [PATCH 37/46] Add example: enable-onlyauto-loading-then-immediately-save-the-workbook-as-pdf-to-produce-a-document-with-prefitted-rows --- rows-and-columns/agents.md | 1 + ...-produce-a-document-with-prefitted-rows.cs | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 rows-and-columns/enable-onlyauto-loading-then-immediately-save-the-workbook-as-pdf-to-produce-a-document-with-prefitted-rows.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 0f4e0efd68..0809725416 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -90,3 +90,4 @@ Output files are written to the working directory. - apply-fixedwidth-texttocolumns-on-column-c-to-divide-text-into-equal-sized-fields.cs - apply-a-uniform-column-width-to-all-columns-by-assigning-cellsstandardwidth.cs - set-row-heights-for-a-series-of-rows-using-a-loop-that-calls-setrowheight-with-incremental-values.cs +- enable-onlyauto-loading-then-immediately-save-the-workbook-as-pdf-to-produce-a-document-with-prefitted-rows.cs diff --git a/rows-and-columns/enable-onlyauto-loading-then-immediately-save-the-workbook-as-pdf-to-produce-a-document-with-prefitted-rows.cs b/rows-and-columns/enable-onlyauto-loading-then-immediately-save-the-workbook-as-pdf-to-produce-a-document-with-prefitted-rows.cs new file mode 100644 index 0000000000..bdc4297316 --- /dev/null +++ b/rows-and-columns/enable-onlyauto-loading-then-immediately-save-the-workbook-as-pdf-to-produce-a-document-with-prefitted-rows.cs @@ -0,0 +1,30 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Initialize load options. + LoadOptions loadOptions = new LoadOptions(); + + // The OnlyAuto loading option is not available in the current Aspose.Cells API. + // If a future version provides a property such as loadOptions.OnlyAuto, + // it can be enabled here: + // loadOptions.OnlyAuto = true; + + // Load the workbook with the specified options. + Workbook workbook = new Workbook("input.xlsx", loadOptions); + + // Configure PDF save options. Default behavior preserves row heights and auto‑fit. + PdfSaveOptions pdfOptions = new PdfSaveOptions + { + // Ensure each sheet is rendered on its natural page layout. + OnePagePerSheet = false + }; + + // Save the workbook as PDF. + workbook.Save("output.pdf", pdfOptions); + } +} +// Author: Example demonstrating loading a workbook and saving to PDF with Aspose.Cells. \ No newline at end of file From ae0f4653d770ce2022a4eea233a15a2a3f134070 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:33:39 +0500 Subject: [PATCH 38/46] Add example: split-spacedelimited-text-in-column-a-into-separate-columns-using-texttocolumns --- rows-and-columns/agents.md | 1 + ...to-separate-columns-using-texttocolumns.cs | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 rows-and-columns/split-spacedelimited-text-in-column-a-into-separate-columns-using-texttocolumns.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 0809725416..ae988a3830 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -91,3 +91,4 @@ Output files are written to the working directory. - apply-a-uniform-column-width-to-all-columns-by-assigning-cellsstandardwidth.cs - set-row-heights-for-a-series-of-rows-using-a-loop-that-calls-setrowheight-with-incremental-values.cs - enable-onlyauto-loading-then-immediately-save-the-workbook-as-pdf-to-produce-a-document-with-prefitted-rows.cs +- split-spacedelimited-text-in-column-a-into-separate-columns-using-texttocolumns.cs diff --git a/rows-and-columns/split-spacedelimited-text-in-column-a-into-separate-columns-using-texttocolumns.cs b/rows-and-columns/split-spacedelimited-text-in-column-a-into-separate-columns-using-texttocolumns.cs new file mode 100644 index 0000000000..fc7cdd2388 --- /dev/null +++ b/rows-and-columns/split-spacedelimited-text-in-column-a-into-separate-columns-using-texttocolumns.cs @@ -0,0 +1,33 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook (lifecycle rule) + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Sample space‑delimited data in column A + sheet.Cells["A1"].PutValue("John Doe 30"); + sheet.Cells["A2"].PutValue("Jane Smith 28"); + sheet.Cells["A3"].PutValue("Bob Johnson 45"); + + // Set up TextToColumns options to split on space + TxtLoadOptions options = new TxtLoadOptions(); + options.Separator = ' '; // space character as delimiter + + // Split the text in column A (row 0, column 0) for 3 rows + sheet.Cells.TextToColumns(0, 0, 3, options); + + // Optional verification + Console.WriteLine(sheet.Cells["B1"].StringValue); // Expected: "Doe" + Console.WriteLine(sheet.Cells["C2"].StringValue); // Expected: "28" + + // Save the workbook (lifecycle rule) + workbook.Save("output.xlsx"); + } +} + +// Author: Aspose.Cells .NET example – splits space‑delimited text using TextToColumns. \ No newline at end of file From 331c835c204637df949467e6a581a25fd4cd2a86 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:39:11 +0500 Subject: [PATCH 39/46] Add example: duplicate-multiple-consecutive-rows-using-copyrows-and-verify-formula-references-update-correctly --- rows-and-columns/agents.md | 1 + ...ify-formula-references-update-correctly.cs | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 rows-and-columns/duplicate-multiple-consecutive-rows-using-copyrows-and-verify-formula-references-update-correctly.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index ae988a3830..2b9636dfc6 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -92,3 +92,4 @@ Output files are written to the working directory. - set-row-heights-for-a-series-of-rows-using-a-loop-that-calls-setrowheight-with-incremental-values.cs - enable-onlyauto-loading-then-immediately-save-the-workbook-as-pdf-to-produce-a-document-with-prefitted-rows.cs - split-spacedelimited-text-in-column-a-into-separate-columns-using-texttocolumns.cs +- duplicate-multiple-consecutive-rows-using-copyrows-and-verify-formula-references-update-correctly.cs diff --git a/rows-and-columns/duplicate-multiple-consecutive-rows-using-copyrows-and-verify-formula-references-update-correctly.cs b/rows-and-columns/duplicate-multiple-consecutive-rows-using-copyrows-and-verify-formula-references-update-correctly.cs new file mode 100644 index 0000000000..0468af8105 --- /dev/null +++ b/rows-and-columns/duplicate-multiple-consecutive-rows-using-copyrows-and-verify-formula-references-update-correctly.cs @@ -0,0 +1,52 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsRowDuplicationDemo +{ + // Author: Aspose.Cells .NET example – duplicate rows and verify formula updates + class Program + { + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Populate sample data in column A + sheet.Cells["A1"].PutValue(10); + sheet.Cells["A2"].PutValue(20); + sheet.Cells["A3"].PutValue(30); + sheet.Cells["A4"].PutValue(40); + + // Add formulas in column B that reference the same row in column A + sheet.Cells["B1"].Formula = "=A1*2"; + sheet.Cells["B2"].Formula = "=A2*2"; + sheet.Cells["B3"].Formula = "=A3*2"; + sheet.Cells["B4"].Formula = "=A4*2"; + + // Insert two blank rows after the second row (index 2, zero‑based) + // updateReference = true ensures existing formulas adjust to the insertion + sheet.Cells.InsertRows(2, 2, true); + + // Copy rows 0 and 1 (first two rows) to the newly inserted rows starting at index 2 + // This duplicates the rows while preserving relative formula references + sheet.Cells.CopyRows(sheet.Cells, 0, 2, 2); + + // Verify that formulas in the copied rows have been updated correctly + Console.WriteLine("Original formulas:"); + Console.WriteLine($"B1: {sheet.Cells["B1"].Formula}"); + Console.WriteLine($"B2: {sheet.Cells["B2"].Formula}"); + + Console.WriteLine("\nCopied formulas after duplication:"); + Console.WriteLine($"B3: {sheet.Cells["B3"].Formula}"); + Console.WriteLine($"B4: {sheet.Cells["B4"].Formula}"); + + // Expected output: + // B3 formula should be "=A3*2" + // B4 formula should be "=A4*2" + + // Save the workbook to verify visually if needed + workbook.Save("RowDuplicationResult.xlsx"); + } + } +} \ No newline at end of file From 3639e7f99268cd009995ddede7da9ab58776c8b6 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:40:16 +0500 Subject: [PATCH 40/46] Add example: transfer-a-row-from-a-source-worksheet-to-a-destination-worksheet-using-cellscopyrow --- rows-and-columns/agents.md | 1 + ...estination-worksheet-using-cellscopyrow.cs | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 rows-and-columns/transfer-a-row-from-a-source-worksheet-to-a-destination-worksheet-using-cellscopyrow.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 2b9636dfc6..678d6b2b34 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -93,3 +93,4 @@ Output files are written to the working directory. - enable-onlyauto-loading-then-immediately-save-the-workbook-as-pdf-to-produce-a-document-with-prefitted-rows.cs - split-spacedelimited-text-in-column-a-into-separate-columns-using-texttocolumns.cs - duplicate-multiple-consecutive-rows-using-copyrows-and-verify-formula-references-update-correctly.cs +- transfer-a-row-from-a-source-worksheet-to-a-destination-worksheet-using-cellscopyrow.cs diff --git a/rows-and-columns/transfer-a-row-from-a-source-worksheet-to-a-destination-worksheet-using-cellscopyrow.cs b/rows-and-columns/transfer-a-row-from-a-source-worksheet-to-a-destination-worksheet-using-cellscopyrow.cs new file mode 100644 index 0000000000..3e90607e99 --- /dev/null +++ b/rows-and-columns/transfer-a-row-from-a-source-worksheet-to-a-destination-worksheet-using-cellscopyrow.cs @@ -0,0 +1,31 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + + // Source worksheet (first sheet) + Worksheet srcSheet = workbook.Worksheets[0]; + srcSheet.Name = "Source"; + + // Populate source row (row index 0) + srcSheet.Cells["A1"].PutValue("Item"); + srcSheet.Cells["B1"].PutValue(123); + srcSheet.Cells["C1"].PutValue(DateTime.Now); + + // Destination worksheet (add a new sheet) + Worksheet destSheet = workbook.Worksheets.Add("Destination"); + + // Transfer the first row from source to destination + destSheet.Cells.CopyRow(srcSheet.Cells, 0, 0); + + // Save the workbook + workbook.Save("RowCopyExample.xlsx", SaveFormat.Xlsx); + } +} + +// Author: Aspose.Cells .NET example \ No newline at end of file From 16f45d90f677d8cedfa76fe7256e694fc54c9044 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:41:18 +0500 Subject: [PATCH 41/46] Add example: copy-a-column-from-one-worksheet-to-another-while-maintaining-column-width-and-data-types --- rows-and-columns/agents.md | 1 + ...maintaining-column-width-and-data-types.cs | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 rows-and-columns/copy-a-column-from-one-worksheet-to-another-while-maintaining-column-width-and-data-types.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 678d6b2b34..49a94a3b92 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -94,3 +94,4 @@ Output files are written to the working directory. - split-spacedelimited-text-in-column-a-into-separate-columns-using-texttocolumns.cs - duplicate-multiple-consecutive-rows-using-copyrows-and-verify-formula-references-update-correctly.cs - transfer-a-row-from-a-source-worksheet-to-a-destination-worksheet-using-cellscopyrow.cs +- copy-a-column-from-one-worksheet-to-another-while-maintaining-column-width-and-data-types.cs diff --git a/rows-and-columns/copy-a-column-from-one-worksheet-to-another-while-maintaining-column-width-and-data-types.cs b/rows-and-columns/copy-a-column-from-one-worksheet-to-another-while-maintaining-column-width-and-data-types.cs new file mode 100644 index 0000000000..90dcbbbcfb --- /dev/null +++ b/rows-and-columns/copy-a-column-from-one-worksheet-to-another-while-maintaining-column-width-and-data-types.cs @@ -0,0 +1,43 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsColumnCopyDemo +{ + // Author: Aspose.Cells .NET example + class Program + { + static void Main() + { + // Create source workbook and populate a column with various data types + Workbook srcWorkbook = new Workbook(); + Worksheet srcSheet = srcWorkbook.Worksheets[0]; + Cells srcCells = srcSheet.Cells; + + // Sample data in column B (index 1) + srcCells[0, 1].PutValue(123); // Integer + srcCells[1, 1].PutValue(45.67); // Double + srcCells[2, 1].PutValue(true); // Boolean + srcCells[3, 1].PutValue(DateTime.Now); // DateTime + srcCells[4, 1].PutValue("Text value"); // String + + // Set column width (in characters) for the source column + srcSheet.Cells.SetColumnWidth(1, 25); // 25 characters wide + + // Create destination workbook (empty) + Workbook destWorkbook = new Workbook(); + Worksheet destSheet = destWorkbook.Worksheets[0]; + Cells destCells = destSheet.Cells; + + // Copy the entire column (data + formats) from source to destination + // Parameters: source cells, source column index, destination column index + destCells.CopyColumn(srcCells, 1, 0); // Copy source column B to destination column A + + // Preserve the column width by copying the width value explicitly + double srcColumnWidth = srcSheet.Cells.GetColumnWidth(1); + destSheet.Cells.SetColumnWidth(0, srcColumnWidth); + + // Save the result workbook + destWorkbook.Save("ColumnCopyWithWidth.xlsx", SaveFormat.Xlsx); + } + } +} \ No newline at end of file From 2eb09cfe8f21496660dad9a695ba5d8ae5ca338f Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:43:50 +0500 Subject: [PATCH 42/46] Add example: preserve-updated-formula-references-when-copying-rows-that-contain-relative-cell-references --- rows-and-columns/agents.md | 1 + ...s-that-contain-relative-cell-references.cs | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 rows-and-columns/preserve-updated-formula-references-when-copying-rows-that-contain-relative-cell-references.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 49a94a3b92..af2b098f19 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -95,3 +95,4 @@ Output files are written to the working directory. - duplicate-multiple-consecutive-rows-using-copyrows-and-verify-formula-references-update-correctly.cs - transfer-a-row-from-a-source-worksheet-to-a-destination-worksheet-using-cellscopyrow.cs - copy-a-column-from-one-worksheet-to-another-while-maintaining-column-width-and-data-types.cs +- preserve-updated-formula-references-when-copying-rows-that-contain-relative-cell-references.cs diff --git a/rows-and-columns/preserve-updated-formula-references-when-copying-rows-that-contain-relative-cell-references.cs b/rows-and-columns/preserve-updated-formula-references-when-copying-rows-that-contain-relative-cell-references.cs new file mode 100644 index 0000000000..3f16ab6b97 --- /dev/null +++ b/rows-and-columns/preserve-updated-formula-references-when-copying-rows-that-contain-relative-cell-references.cs @@ -0,0 +1,42 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – preserve relative formula references when copying rows +class PreserveFormulaCopyDemo +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + sheet.Name = "Sheet1"; + + // Populate some sample data + sheet.Cells["A1"].PutValue(10); + sheet.Cells["B1"].PutValue(20); + // Set a formula that uses relative references (A1+B1) + sheet.Cells["C1"].Formula = "=A1+B1"; + + // Insert a blank row at index 1 (Excel row 2) + sheet.Cells.InsertRows(1, 1); + + // Configure copy options to keep relative references correct + CopyOptions copyOptions = new CopyOptions + { + // If the source sheet has been copied before, keep references to sheets with the same name + ReferToSheetWithSameName = true, + // Extend copying to adjacent ranges (e.g., merged cells) if present + ExtendToAdjacentRange = true + }; + + // Copy row 0 (first row) to row 1 (second row) using the configured options + sheet.Cells.CopyRows(sheet.Cells, 0, 1, 1, copyOptions); + + // Output the formulas to verify that the copied formula has been updated to reference the new row + Console.WriteLine("Original formula (C1): " + sheet.Cells["C1"].Formula); // Expected: =A1+B1 + Console.WriteLine("Copied formula (C2): " + sheet.Cells["C2"].Formula); // Expected: =A2+B2 + + // Save the workbook + workbook.Save("PreserveFormulaCopy.xlsx"); + } +} \ No newline at end of file From f3438d615f9de5c62d65b5ca07284366cd9f0000 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:44:45 +0500 Subject: [PATCH 43/46] Add example: disable-formula-adjustment-in-pasteoptions-to-copy-rows-with-absolute-references-unchanged --- rows-and-columns/agents.md | 1 + ...rows-with-absolute-references-unchanged.cs | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 rows-and-columns/disable-formula-adjustment-in-pasteoptions-to-copy-rows-with-absolute-references-unchanged.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index af2b098f19..9b8ee51bf3 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -96,3 +96,4 @@ Output files are written to the working directory. - transfer-a-row-from-a-source-worksheet-to-a-destination-worksheet-using-cellscopyrow.cs - copy-a-column-from-one-worksheet-to-another-while-maintaining-column-width-and-data-types.cs - preserve-updated-formula-references-when-copying-rows-that-contain-relative-cell-references.cs +- disable-formula-adjustment-in-pasteoptions-to-copy-rows-with-absolute-references-unchanged.cs diff --git a/rows-and-columns/disable-formula-adjustment-in-pasteoptions-to-copy-rows-with-absolute-references-unchanged.cs b/rows-and-columns/disable-formula-adjustment-in-pasteoptions-to-copy-rows-with-absolute-references-unchanged.cs new file mode 100644 index 0000000000..1b565f093c --- /dev/null +++ b/rows-and-columns/disable-formula-adjustment-in-pasteoptions-to-copy-rows-with-absolute-references-unchanged.cs @@ -0,0 +1,37 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – copy rows with absolute references unchanged +class Program +{ + static void Main() + { + // Create a new workbook (replace with the provided create rule if available) + Workbook workbook = new Workbook(); + + // Source worksheet with formulas that use absolute references + Worksheet srcSheet = workbook.Worksheets[0]; + srcSheet.Cells["A1"].Formula = "$B$1+10"; + srcSheet.Cells["A2"].Formula = "$B$2*2"; + + // Destination worksheet + Worksheet dstSheet = workbook.Worksheets.Add("Destination"); + + // Configure copy and paste options + CopyOptions copyOptions = new CopyOptions(); + + PasteOptions pasteOptions = new PasteOptions + { + // Disable formula adjustment (relative reference shifting) by using No operation type + OperationType = PasteOperationType.None, + // Ensure formulas are copied + PasteType = PasteType.Formulas + }; + + // Copy the first two rows from source to destination starting at row index 5 (row 6 in Excel) + dstSheet.Cells.CopyRows(srcSheet.Cells, 0, 5, 2, copyOptions, pasteOptions); + + // Save the workbook (replace with the provided save rule if available) + workbook.Save("RowsCopy_NoFormulaAdjustment.xlsx"); + } +} \ No newline at end of file From f06bce1e2ca2f9279f9915d87bf285e9c9d62950 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:45:36 +0500 Subject: [PATCH 44/46] Add example: use-pasteoptions-to-copy-only-formatting-from-source-rows-excluding-values-and-formulas --- rows-and-columns/agents.md | 1 + ...urce-rows-excluding-values-and-formulas.cs | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 rows-and-columns/use-pasteoptions-to-copy-only-formatting-from-source-rows-excluding-values-and-formulas.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 9b8ee51bf3..5c3da6c33c 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -97,3 +97,4 @@ Output files are written to the working directory. - copy-a-column-from-one-worksheet-to-another-while-maintaining-column-width-and-data-types.cs - preserve-updated-formula-references-when-copying-rows-that-contain-relative-cell-references.cs - disable-formula-adjustment-in-pasteoptions-to-copy-rows-with-absolute-references-unchanged.cs +- use-pasteoptions-to-copy-only-formatting-from-source-rows-excluding-values-and-formulas.cs diff --git a/rows-and-columns/use-pasteoptions-to-copy-only-formatting-from-source-rows-excluding-values-and-formulas.cs b/rows-and-columns/use-pasteoptions-to-copy-only-formatting-from-source-rows-excluding-values-and-formulas.cs new file mode 100644 index 0000000000..e177d6bc83 --- /dev/null +++ b/rows-and-columns/use-pasteoptions-to-copy-only-formatting-from-source-rows-excluding-values-and-formulas.cs @@ -0,0 +1,39 @@ +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – copy only formatting from source rows + +class Program +{ + static void Main() + { + // Load the source workbook containing the rows to copy + Workbook sourceWorkbook = new Workbook("source.xlsx"); + Worksheet sourceSheet = sourceWorkbook.Worksheets[0]; + + // Create (or load) the destination workbook where rows will be pasted + Workbook destinationWorkbook = new Workbook(); + Worksheet destinationSheet = destinationWorkbook.Worksheets[0]; + + // Default copy options – no special behavior required + CopyOptions copyOptions = new CopyOptions(); + + // Paste options configured to copy only formats (no values or formulas) + PasteOptions pasteOptions = new PasteOptions + { + PasteType = PasteType.Formats // Formats only + }; + + // Example: copy 5 rows starting from row 0 of the source sheet + // and paste them beginning at row 10 of the destination sheet + sourceSheet.Cells.CopyRows( + sourceSheet.Cells, // source cells + 0, // source row index (zero‑based) + 10, // destination row index (zero‑based) + 5, // number of rows to copy + copyOptions, + pasteOptions); + + // Save the resulting workbook + destinationWorkbook.Save("result.xlsx"); + } +} \ No newline at end of file From 713e02a191259192a2562f0019508df4618f5246 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:51:13 +0500 Subject: [PATCH 45/46] Add example: copy-rows-between-worksheets-then-autofit-destination-rows-to-match-source-row-heights --- rows-and-columns/agents.md | 1 + ...nation-rows-to-match-source-row-heights.cs | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 rows-and-columns/copy-rows-between-worksheets-then-autofit-destination-rows-to-match-source-row-heights.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 5c3da6c33c..5dcc557ecd 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -98,3 +98,4 @@ Output files are written to the working directory. - preserve-updated-formula-references-when-copying-rows-that-contain-relative-cell-references.cs - disable-formula-adjustment-in-pasteoptions-to-copy-rows-with-absolute-references-unchanged.cs - use-pasteoptions-to-copy-only-formatting-from-source-rows-excluding-values-and-formulas.cs +- copy-rows-between-worksheets-then-autofit-destination-rows-to-match-source-row-heights.cs diff --git a/rows-and-columns/copy-rows-between-worksheets-then-autofit-destination-rows-to-match-source-row-heights.cs b/rows-and-columns/copy-rows-between-worksheets-then-autofit-destination-rows-to-match-source-row-heights.cs new file mode 100644 index 0000000000..98172e424d --- /dev/null +++ b/rows-and-columns/copy-rows-between-worksheets-then-autofit-destination-rows-to-match-source-row-heights.cs @@ -0,0 +1,53 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create source workbook and populate it with sample data. + Workbook srcWb = new Workbook(); + Worksheet srcSheet = srcWb.Worksheets[0]; + srcSheet.Name = "Source"; + + srcSheet.Cells["A1"].PutValue("Header"); + srcSheet.Cells["A2"].PutValue("Row 1"); + srcSheet.Cells["A3"].PutValue("Row 2"); + srcSheet.Cells["A4"].PutValue("Row 3"); + + // Set custom heights for the rows to be copied. + srcSheet.Cells.Rows[1].Height = 30; // Row 2 + srcSheet.Cells.Rows[2].Height = 40; // Row 3 + srcSheet.Cells.Rows[3].Height = 50; // Row 4 + + // Create destination workbook. + Workbook destWb = new Workbook(); + Worksheet destSheet = destWb.Worksheets[0]; + destSheet.Name = "Destination"; + + // Define the range of rows to copy. + int sourceStartRow = 1; // zero‑based index (Row 2) + int rowCount = 3; // rows 2,3,4 + int destStartRow = 0; // paste starting at Row 1 in destination + + // Copy rows (data, formats, hyperlinks, etc.). + destSheet.Cells.CopyRows(srcSheet.Cells, sourceStartRow, destStartRow, rowCount); + + // Preserve exact row heights and other settings. + for (int i = 0; i < rowCount; i++) + { + Row srcRow = srcSheet.Cells.Rows[sourceStartRow + i]; + Row destRow = destSheet.Cells.Rows[destStartRow + i]; + destRow.CopySettings(srcRow, false); + } + + // Auto‑fit rows that do not have custom heights. + destSheet.AutoFitRows(true); + + // Save both workbooks. + srcWb.Save("Source.xlsx"); + destWb.Save("Destination.xlsx"); + } +} + +// Author: Example demonstrating row copy with height preservation using Aspose.Cells for .NET. \ No newline at end of file From 05fa550cd6fbce07e56c87d8ddee5171fbaa552d Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 30 Jun 2026 14:52:09 +0500 Subject: [PATCH 46/46] Add example: retrieve-source-row-height-with-getrowheight-and-explicitly-set-destination-height-using-setrowheight --- rows-and-columns/agents.md | 1 + ...t-destination-height-using-setrowheight.cs | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 rows-and-columns/retrieve-source-row-height-with-getrowheight-and-explicitly-set-destination-height-using-setrowheight.cs diff --git a/rows-and-columns/agents.md b/rows-and-columns/agents.md index 5dcc557ecd..5d9b935dc5 100644 --- a/rows-and-columns/agents.md +++ b/rows-and-columns/agents.md @@ -99,3 +99,4 @@ Output files are written to the working directory. - disable-formula-adjustment-in-pasteoptions-to-copy-rows-with-absolute-references-unchanged.cs - use-pasteoptions-to-copy-only-formatting-from-source-rows-excluding-values-and-formulas.cs - copy-rows-between-worksheets-then-autofit-destination-rows-to-match-source-row-heights.cs +- retrieve-source-row-height-with-getrowheight-and-explicitly-set-destination-height-using-setrowheight.cs diff --git a/rows-and-columns/retrieve-source-row-height-with-getrowheight-and-explicitly-set-destination-height-using-setrowheight.cs b/rows-and-columns/retrieve-source-row-height-with-getrowheight-and-explicitly-set-destination-height-using-setrowheight.cs new file mode 100644 index 0000000000..b5078584df --- /dev/null +++ b/rows-and-columns/retrieve-source-row-height-with-getrowheight-and-explicitly-set-destination-height-using-setrowheight.cs @@ -0,0 +1,30 @@ +using System; +using Aspose.Cells; + +// Author: Aspose.Cells .NET example – copy row height from source to destination +class Program +{ + static void Main() + { + // Create a new workbook (use the provided create rule) + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + Cells cells = worksheet.Cells; + + // Example: set a specific height for the source row (row 0) + int sourceRowIndex = 0; + cells.SetRowHeight(sourceRowIndex, 30.0); // height in points + + // Retrieve the source row height using GetRowHeight + double sourceHeight = cells.GetRowHeight(sourceRowIndex); + // If GetRowHeight is obsolete in your version, you can use: + // double sourceHeight = cells.GetViewRowHeight(sourceRowIndex); + + // Explicitly set the destination row height (row 1) to match the source + int destinationRowIndex = 1; + cells.SetRowHeight(destinationRowIndex, sourceHeight); + + // Save the workbook (use the provided save rule) + workbook.Save("RowHeightCopy.xlsx"); + } +} \ No newline at end of file