negin motalebi
negin motalebi

Reputation: 393

How can I merge cells of Excel package worksheet in C#?

I just want to merge number of cells in one column using worksheet of ExcelPackage; There is the way that I create my worksheet:

        var excelFile = new FileInfo(fileName);
        var package = new ExcelPackage(excelFile);
        var workSheet = package.Workbook.Worksheets.Add(sheetName);

So How can I merge cells in this worksheet? I will be thankful for any solution.

Upvotes: 0

Views: 1253

Answers (1)

Edward
Edward

Reputation: 8596

// Place data in cells
worksheet.Cells["A1"].Value = "Cell A1";
// Or [row, column] notation:
worksheet.Cells[2,1].Value = "Cell A2";

// Merge cells
worksheet.Cells["A1:B1"].Merge = true;
// Or [row, column] notation:
worksheet.Cells[FromRow, FromColumn, ToRow, ToColumn].Merge = true;

Upvotes: 1

Related Questions