ClosedXML Sort(3); does not work

Home Forums Open-Xml-Sdk ClosedXML Sort(3); does not work


This topic contains 3 replies, has 2 voices, and was last updated by  rogersb 8 months, 1 week ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #3785


    open/closed xml, same thing,

    ws.Cell("A" + c).Value = Projinfo1
    ws.Cell("B" + c).Value = Projinfo2
    ws.Cell("C" + c).Value = Name123
    ws.Cell("D" + c).Value = p
    ws.Cell("E" + c).Value = S
    ws.Cell("F" + c).Value = S
    ws.Cell("G" + c).Value =  
    ws.Cell("H" + c).Value = P
    ws.Cell("I" + c).Value = P
    ws.Cell("J" + c).Value = N

    There is the worksheet ws that gets filled in a foreach iteration thru all of the database elements (variable names not shown) and it builds the excel page, works fine.

    c =3 but then gets incremented

    at the top of the excel page you write in headers and column names

     // Here we make the Columns and speci
     ws.Cell("A1").Value = "Data for Summary
     ws.Cell("A2").Value = DateTime.Today;
     ws.Cell("A3").Value = "Proj Number
     ws.Cell("B2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right;
     ws.Cell("B2").Value = "Unit Date";
     ws.Cell("B3").Value = "Proj t Name";
     ws.Cell("C2").Value =  "01/30/2016";
     ws.Cell("C3").Value = "Pint size";
     ws.Cell("D3").Value = "Program Sales dept";
     ws.Cell("E3").Value = "Start Sell Date";
     ws.Cell("F3").Value = "Sch End of 
     ws.Cell("G3").Value = "Total pint cost
     ws.Cell("H3").Value = "Past Sell Date;
     ws.Cell("I3").Value = "How Far short
     ws.Cell("J3").Value = "# of Bins Beh

    But the problem comes with the Sort() command

    should cause the sheet to sort on column “D”. but 2 things happen depending on where the sort command is placed, either no sort takes place or if it does sort? it pushes all the data to the top of the worksheet and those headers/column names appear at the bottom

    Colors were added to various rows based on variable values, if the date.year == “2009” then the row color is light blue. It worked at one time, it would sort and rows would be colored nicely in order. Now? it sorts by column 1 so row 1’s values are a specific color but then the columns 2 – end are which ever color they were. so it colored in the rows correctly, and later resorted by column 1, so column 1’s colors dont match all the time, its a mess

    when it works, the entire row is the single color, grouped as expected but it begins on row 1 instead of row3 where they were first put, what is telling them to fill in on row 1?



    right… so deleting closedXML on nuget and re installing? I took the latest build. could be the problem

    • This reply was modified 8 months, 1 week ago by  rogersb.

    Eric White


    I have no experience about the closedXML library, although I have heard good things about it. Maybe someone else has an answer…

    Cheers, Eric



    its so incredibly easy to make an Excel file, and it will accept the variables that come right out of the database

    but I found out the indexing for the Sort() was 0th based not 1-based, so doing ws.Sort(5) had it sort on column F not column E; and col. F was just Y or N, so looking at the dates being out of order it seemed not to sort, plus its got colored rows that are mixed.

    But it has another problem where it sorts good now using ws.Sort(4) gets sorting on col “E”

    then it goes back and sorts col. 1 on those values splitting up the row data, which to me seems like its never supposed to do because now the row data is corrupt.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.