@ankit goel , thanks for the feedback, based on your latest requirement, I make a code example to convert your current excel to list.
Here is a code example you could refer to.
public class Model
{
public BlanaceType type { get; set; }
public string Name { get; set; }
public double Amount { get; set; }
}
static void Main(string[] args)
{
Excel.Application app = new Excel.Application();
Excel.Workbook workbook = app.Workbooks.Open("Example.xlsx");
Excel.Worksheet ws= workbook.Worksheets[1];
int usedrowcount = ws.UsedRange.Rows.Count;
List<Model> models = new List<Model>();
for (int i = 7; i < usedrowcount; i++)
{
string text= ws.Cells[i, 1].Text;
string text1= ws.Cells[i, 2].Text;
string text2 = ws.Cells[i, 3].Text;
if(text1!="")
{
Model model = new Model();
model.Name = text;
model.type = BlanaceType.Debit;
model.Amount = Convert.ToDouble(text1);
models.Add(model);
}
if (text2 != "")
{
Model model = new Model();
model.Name = text;
model.type = BlanaceType.Credit;
model.Amount = Convert.ToDouble(text2);
models.Add(model);
}
}
workbook.Close();
var result = models.OrderBy(i => i.Amount);
foreach (var item in result)
{
Console.WriteLine(item.Name);
Console.WriteLine(item.Amount);
Console.WriteLine(item.type.ToString());
}
}
Please note that you need to start from the 10 row instead of 7 row.
My excel file and tested result:
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.