Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8565421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:25:23+00:00 2026-06-11T17:25:23+00:00

I have an Excel 97-2003 .xls spreadsheet converted from .dbf using C#-4.0 and Excel.Interop.

  • 0

I have an Excel 97-2003 .xls spreadsheet converted from .dbf using C#-4.0 and Excel.Interop. The data is sorted by date according to column D.

http://www.tiikoni.com/tis/view/?id=af4cf69

Now I would need to sort the selected range (shown in the image), by column G so that blank cells get to be on the bottom of the selected range.

The image shows it correctly, but just because the data retrieved from the input source was entered in the proper order. If data wouldn’t have been entered in the right order, then blank cells might not be at the bottom in column G from the start.

This is what I have, to do that sorting for each D date range (a day).

    Range incasariSortRange;
    Range sRange;
    int startDateRowIndex = 6; // index of row where a D date starts
    int endDateRowIndex = 6; // index of row where the same D date ends

    public void selectGroupRange()
    {
        for (int r = startDateRowIndex; r < rowIndex; r++)
        {
            if (worksheet.Cells[endDateRowIndex, 4].Value == worksheet.Cells[r, 4].Value)
            {
                endDateRowIndex = r;
            }
            else
            {
                incasariSortRange = worksheet.get_Range("B" + startDateRowIndex, "H" + endDateRowIndex);
                sRange = incasariSortRange.get_Range("G" + startDateRowIndex, "G" + endDateRowIndex);

                // Sort the first 'D' date range's row by wether the cells in column 'G' 
                //of that range have any values (to be the first ones) or not (to be the last ones).
                incasariSortRange.Sort(sRange, XlSortOrder.xlAscending,
                    Type.Missing, Type.Missing, XlSortOrder.xlAscending,
                    Type.Missing, XlSortOrder.xlAscending, XlYesNoGuess.xlNo, Type.Missing,
                    Type.Missing, XlSortOrientation.xlSortColumns, XlSortMethod.xlPinYin, XlSortDataOption.xlSortNormal,
                    XlSortDataOption.xlSortNormal, XlSortDataOption.xlSortNormal);

                // Set the start and end (date) row indexes to the same so the incasariSortRange will be one row only.
                startDateRowIndex = r; // set the start to a new date
                endDateRowIndex = r; // set the end to the same new date
            }
        }
    }

‘rowIndex’ is the index number of the row after the last row with data in the spreadsheet.

But as shown here, it sorts the rows so that blank cells in column G get to the top of the selected range.

http://www.tiikoni.com/tis/view/?id=ea48320

My second question would be, after doing this sorting, how can I select from the selected range only the rows where the cells in column G are not blank? -so that I can sort those again.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:25:25+00:00Added an answer on June 11, 2026 at 5:25 pm

    In the end I managed to do it like this.

    A “datagroup” is a group of rows which have the same values in column(D) DATE, grouped by days. “type” is not really relevant, it is just because in my DataSet.Table[0]’s I have a column in which there are two possible values, and according to the value in the row, the row will be written in either the first or the second worksheet in the workbook.

    The “Incasari” is the column which I use to sort by. Like this, Symbols, numbers, lower case letters, uppercase letters, then blank spaces or empty strings come; and that column has only symbols, numbers, lower case letters and blank spaces/ empty strings.

    var sortedDataGroup = datagroup.OrderBy(row =>
    {
        var wrapper = new DataRowWrapper(row, type);
    
        if (wrapper.Incasari != null)
            return wrapper.ContCor.ToLower();
        else
            return "A"; // Capital letters are after lower case letters
    });
    

    It might not be the best way to solve this sorting problem, but I could not find better methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using OleDb to select data from excel spreadsheets. Each spreadsheet can contain many
I'm working on VS2008 .NET3.5 with a Office 2003 doc (.xls). I'm using Microsoft.Office.Interop.Excel
I have written a few Excel 2003/2007 add-ins using VSTO, and I usually end
I have an excel workbook which needs to query data from an HTTP server.
I want to import data from an Excel file - assume Excel 2003 /
I have an Excel 2003 worksheet with protection enabled being used for data entry
I am trying to extract a table of values from an excel (2003) spreadsheet
I have an Excel 2003 Spreadsheet which reference other add-ins. The add-ins are installed
I have an excel 2003 vsto workbook that I would like to make available
I Have an Excel 2003 file with a line similar to this: I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.