Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Addressing a worksheet

Jan Källman edited this page Sep 15, 2017 · 1 revision

Cell addressing in EPPlus works pretty much as it works in Excel. Addressing cells is made in the indexer of the ExcelWorksheet.Cells property (the ExcelRange class). Here´s a few examples of how you can address ranges.

ws.Cells["B1"].Value = "This is cell B1"; // Sets the value of Cell B1
ws.Cells[1, 2].Value = "This is cell B1"; // Also sets the value of Cell B1

worksheet.Cells["A1:B3"].Style.NumberFormat.Format = "#,##0"; //Sets the numberformat for a range
worksheet.Cells[1,1,3,2].Style.NumberFormat.Format = "#,##0"; //Same as above,A1:B3

worksheet.Cells["A1:B3,D1:E57"].Style.NumberFormat.Format = "#,##0"; //Sets the numberformat for a range containing two addresses.
worksheet.Cells["A:B"].Style.Font.Bold = true; //Sets font-bold to true for column A & B
worksheet.Cells["1:1,A:A,C3"].Style.Font.Bold = true; //Sets font-bold to true for row 1,column A and cell C3
worksheet.Cells["A:XFD"].Style.Font.Name = "Arial"; //Sets font to Arial for all cells in a worksheet.
worksheet.Cells.Style.Font.Name = "Arial"; //This is equal to the above.