Files
ClosedXML/ClosedXML_Examples/Misc/MergeMoves.cs
T
Thom Lamb 2cd6df6481 Initial commit of the ClosedXML library
Establishes the foundational structure, core Excel functionality, and tooling.

- Implements base components for cells, ranges, columns, and rows.
- Integrates a custom calculation engine with a wide range of Excel functions.
- Adds comprehensive support for styling, conditional formatting, data validation, comments, pictures, and charts.
- Configures build setup, project metadata (NuGet), and developer guidelines.
- Includes editor and Git attributes for consistent code style and line endings.
2026-06-23 11:02:53 -05:00

54 lines
1.5 KiB
C#

using System.IO;
using ClosedXML.Excel;
namespace ClosedXML_Examples.Misc
{
public class MergeMoves : IXLExample
{
public void Create(string filePath)
{
string tempFile = ExampleHelper.GetTempFilePath(filePath);
try
{
new MergeCells().Create(tempFile);
var workbook = new XLWorkbook(tempFile);
var ws = workbook.Worksheet(1);
ws.Range("B1:F1").InsertRowsBelow(1);
ws.Range("A3:A9").InsertColumnsAfter(1);
ws.Row(1).Delete();
ws.Column(1).Delete();
ws.Range("E8:E9").InsertColumnsAfter(1);
ws.Range("F2:F8").Merge();
ws.Range("E3:E4").InsertColumnsAfter(1);
ws.Range("F2:F8").Merge();
ws.Range("E1:E2").InsertColumnsAfter(1);
ws.Range("G2:G8").Merge();
ws.Range("E1:E2").Delete(XLShiftDeletedCells.ShiftCellsLeft);
ws.Range("D3:E3").InsertRowsBelow(1);
ws.Range("A1:B1").InsertRowsBelow(1);
ws.Range("B3:D3").Merge();
ws.Range("A1:B1").Delete(XLShiftDeletedCells.ShiftCellsUp);
ws.Range("B8:D8").Merge();
ws.Range("D8:D9").Clear();
workbook.SaveAs(filePath);
}
finally
{
if (File.Exists(tempFile))
{
File.Delete(tempFile);
}
}
}
}
}