Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add extra header row at top of excel sheet [EPPlus]

Tags:

c#

asp.net

epplus

I am working with a web application. There,i am supposed to export data to excel. For that,i have made use of EPPlus.

I searched alot but cant find out a way to add extra row at top of excel sheet. Please have a look at below image to better understand the idea.

enter image description here

I tried merging the header,but then i wont get other headers,so i think 'add extra row at top' wil be a better phrase for this.

I am not bounded to use EPPlus. If there is other ways available,i will surely approach it.

Can any one help me with this? I really appreciate the response.

like image 740
user2645738 Avatar asked Aug 02 '13 11:08

user2645738


People also ask

How do I make the top row in Excel a header?

Click anywhere in the table. On the Home tab on the ribbon, click the down arrow next to Table and select Toggle Header Row.

How do I create a header at the top row in Excel 2013?

Go to the "Insert" tab on the Excel toolbar, and then click the “Header & Footer” button in the Text group to start the process of adding a header. Excel changes the document view to a Page Layout view. Click on the top of your document where it says “Click to Add Header,” and then type the header for your document.

What is a row header in Excel?

The row heading or row header is the gray-colored column located to the left of column 1 in the worksheet containing the numbers (1, 2, 3, etc.) used to identify each row in the worksheet.


1 Answers

What you want it's merged cells. You can do it like this:

 ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
 ws.Cells["A1:G1"].Merge = true;

And keep using EPPlus. It's very good

Other sample with formatting:

using (ExcelRange Title = Cells[1, 1, 1, dt.Columns.Count]) {
    Title.Merge = true;
    Title.Style.Font.Size = 18;
    Title.Style.Font.Bold = true;
    Title.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
    Title.Style.Fill.BackgroundColor.SetColor(systemColor);
    Title.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
    Title.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
    Title.Style.TextRotation = 90;
    Title.Value = "This is my title";
}
like image 72
Eduardo Molteni Avatar answered Sep 28 '22 00:09

Eduardo Molteni