Divyesh
Divyesh

Reputation: 438

How to set border from A1:M30 in OpenXML using C#

I am new in OpenXML using C#. I don't know how to set border style from the range of A1:M30. Using OpenXML in C#

enter image description here

Can any one please help me !!

Upvotes: 1

Views: 2725

Answers (1)

Jack Miller
Jack Miller

Reputation: 325

See: https://blogs.msdn.microsoft.com/chrisquon/2009/11/30/stylizing-your-excel-worksheets-with-open-xml-2-0/

For your specific problem I would loop through the cells in each row untill you have found the ones that need borders, then apply the formatting: (Note that DesiredCell is for you to add your cell reference checking)

foreach(Row row in sheetData.Elements<Row>)
{
    foreach(Cell cell in row.Elements<Cell>)
    {
    if(cell.CellReference == DesiredCell)
        {
        cell = new Cell(new CellValue(“ ”)) { DataType = CellValues.String, StyleIndex = 1 };
        }
    }
}

You will also have to add the style index from the link above.

Upvotes: 2

Related Questions