Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6e9746c
Add example: load-a-workbook-with-loadoptionsautofitteroptionsonlyaut…
agent-aspose-cells-examples Jun 30, 2026
6e2e57c
Add example: set-the-height-of-a-specific-row-eg-row-5-to-a-defined-p…
agent-aspose-cells-examples Jun 30, 2026
ff3b9b5
Add example: apply-a-uniform-row-height-to-all-rows-in-a-worksheet-by…
agent-aspose-cells-examples Jun 30, 2026
834d6f5
Add example: set-the-width-of-a-specific-column-eg-column-3-using-cel…
agent-aspose-cells-examples Jun 30, 2026
6f1755a
Add example: set-the-width-of-a-specific-column-in-pixels-using-cells…
agent-aspose-cells-examples Jun 30, 2026
e2f89dc
Add example: autofit-a-single-row-based-on-its-content-using-workshee…
agent-aspose-cells-examples Jun 30, 2026
c385d7c
Add example: autofit-a-range-of-rows-eg-rows-1520-using-worksheetauto…
agent-aspose-cells-examples Jun 30, 2026
7a9680b
Add example: autofit-a-single-column-based-on-its-content-using-works…
agent-aspose-cells-examples Jun 30, 2026
7733516
Add example: autofit-a-range-of-columns-eg-columns-cf-using-worksheet…
agent-aspose-cells-examples Jun 30, 2026
0607947
Add example: autofit-rows-that-contain-merged-cells-by-configuring-au…
agent-aspose-cells-examples Jun 30, 2026
f1f619e
Add example: combine-setrowheight-with-autofitrow-to-set-a-minimum-he…
agent-aspose-cells-examples Jun 30, 2026
821a0fd
Add example: after-autofitting-a-column-finetune-its-width-with-setco…
agent-aspose-cells-examples Jun 30, 2026
84fbc9d
Add example: iterate-through-each-worksheet-in-a-workbook-and-set-sta…
agent-aspose-cells-examples Jun 30, 2026
f05f67a
Add example: batch-process-multiple-worksheets-to-apply-standardwidth…
agent-aspose-cells-examples Jun 30, 2026
0e1f7c2
Add example: load-a-workbook-modify-a-cell-value-then-autofit-the-aff…
agent-aspose-cells-examples Jun 30, 2026
7cfa0e9
Add example: apply-setcolumnwidthpixel-to-a-group-of-columns-after-au…
agent-aspose-cells-examples Jun 30, 2026
37d1b32
Add example: create-a-new-workbook-add-data-to-a-column-and-autofit-t…
agent-aspose-cells-examples Jun 30, 2026
657dc98
Add example: use-worksheetautofitrows-overload-with-startrow-and-endr…
agent-aspose-cells-examples Jun 30, 2026
b300cca
Add example: after-loading-a-workbook-set-standardheight-and-then-aut…
agent-aspose-cells-examples Jun 30, 2026
078b864
Add example: adjust-column-width-by-setting-standardwidth-before-popu…
agent-aspose-cells-examples Jun 30, 2026
1c98762
Add example: autofit-rows-that-contain-merged-cells-by-specifying-aut…
agent-aspose-cells-examples Jun 30, 2026
e520648
Add example: programmatically-set-a-row-height-then-autofit-the-next-…
agent-aspose-cells-examples Jun 30, 2026
4b71b2c
Add example: apply-setcolumnwidth-to-a-column-then-autofit-an-adjacen…
agent-aspose-cells-examples Jun 30, 2026
cb781b1
Add example: load-a-workbook-with-onlyauto-enabled-then-iterate-throu…
agent-aspose-cells-examples Jun 30, 2026
a0d962c
Add example: create-a-custom-autofitteroptions-instance-that-disables…
agent-aspose-cells-examples Jun 30, 2026
9dec653
Add example: after-autofitting-rows-export-the-worksheet-to-pdf-and-c…
agent-aspose-cells-examples Jun 30, 2026
8142b66
Add example: set-row-height-for-the-header-row-to-improve-visual-emph…
agent-aspose-cells-examples Jun 30, 2026
655cb22
Add example: autofit-all-rows-in-a-worksheet-by-calling-autofitrows-w…
agent-aspose-cells-examples Jun 30, 2026
6a91dd1
Add example: autofit-all-rows-for-normal-view-using-worksheetautofitr…
agent-aspose-cells-examples Jun 30, 2026
a030eda
Add example: autofit-rows-containing-merged-cells-to-ensure-merged-co…
agent-aspose-cells-examples Jun 30, 2026
885aebe
Add example: enable-automatic-row-height-adjustment-on-workbook-load-…
agent-aspose-cells-examples Jun 30, 2026
d0fa1f8
Add example: convert-commaseparated-values-in-column-b-to-individual-…
agent-aspose-cells-examples Jun 30, 2026
9d9fbaf
Add example: parse-semicolonseparated-strings-in-a-column-using-textt…
agent-aspose-cells-examples Jun 30, 2026
2d0bde6
Add example: apply-fixedwidth-texttocolumns-on-column-c-to-divide-tex…
agent-aspose-cells-examples Jun 30, 2026
913c0e9
Add example: apply-a-uniform-column-width-to-all-columns-by-assigning…
agent-aspose-cells-examples Jun 30, 2026
e2dafcb
Add example: set-row-heights-for-a-series-of-rows-using-a-loop-that-c…
agent-aspose-cells-examples Jun 30, 2026
6b29a39
Add example: enable-onlyauto-loading-then-immediately-save-the-workbo…
agent-aspose-cells-examples Jun 30, 2026
ae0f465
Add example: split-spacedelimited-text-in-column-a-into-separate-colu…
agent-aspose-cells-examples Jun 30, 2026
331c835
Add example: duplicate-multiple-consecutive-rows-using-copyrows-and-v…
agent-aspose-cells-examples Jun 30, 2026
3639e7f
Add example: transfer-a-row-from-a-source-worksheet-to-a-destination-…
agent-aspose-cells-examples Jun 30, 2026
16f45d9
Add example: copy-a-column-from-one-worksheet-to-another-while-mainta…
agent-aspose-cells-examples Jun 30, 2026
2eb09cf
Add example: preserve-updated-formula-references-when-copying-rows-th…
agent-aspose-cells-examples Jun 30, 2026
f3438d6
Add example: disable-formula-adjustment-in-pasteoptions-to-copy-rows-…
agent-aspose-cells-examples Jun 30, 2026
f06bce1
Add example: use-pasteoptions-to-copy-only-formatting-from-source-row…
agent-aspose-cells-examples Jun 30, 2026
713e02a
Add example: copy-rows-between-worksheets-then-autofit-destination-ro…
agent-aspose-cells-examples Jun 30, 2026
05fa550
Add example: retrieve-source-row-height-with-getrowheight-and-explici…
agent-aspose-cells-examples Jun 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,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");
}
}
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
102 changes: 102 additions & 0 deletions rows-and-columns/agents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- retrieve-source-row-height-with-getrowheight-and-explicitly-set-destination-height-using-setrowheight.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
Loading