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/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/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/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 new file mode 100644 index 0000000000..5d9b935dc5 --- /dev/null +++ b/rows-and-columns/agents.md @@ -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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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