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.