简体   繁体   中英

Read EPPlus DataTable in Excel from specific colums

Hi Im new to using EPPlus Excel Uploader and Datatable, My question is, is it possible to finish the rows from Male (AD column) after proceeding to the Female Rows (EH) ? Sorry in Advance because I cant find any code or how to ask this question that can solve my problem

在此处输入图片说明

You can loop all the rows of the Males and then the Females.

using (ExcelPackage package = new ExcelPackage(fi))
{
    ExcelWorksheet worksheet = package.Workbook.Worksheets[1];

    //set the column start positions for both sexes
    int startMale = 1;
    int startFemale = 5;

    //first the males. start at row 2 to skip the header
    for (int row = 2; row <= worksheet.Dimension.End.Row; row++)
    {
        string FirstName = worksheet.Cells[row, startMale].Value.ToString();
        string LastName = worksheet.Cells[row, startMale + 1].Value.ToString();
        string Sex = worksheet.Cells[row, startMale + 2].Value.ToString();
        string Age = worksheet.Cells[row, startMale + 3].Value.ToString();
    }

    //then the females
    for (int row = 2; row <= worksheet.Dimension.End.Row; row++)
    {
        string FirstName = worksheet.Cells[row, startFemale].Value.ToString();
        string LastName = worksheet.Cells[row, startFemale + 1].Value.ToString();
        string Sex = worksheet.Cells[row, startFemale + 2].Value.ToString();
        string Age = worksheet.Cells[row, startFemale + 3].Value.ToString();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM