43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using OfficeOpenXml;
|
|
using QuizMaster.Response;
|
|
|
|
namespace QuizMaster.Service
|
|
{
|
|
public static class ExecuteExcelService
|
|
{
|
|
public static List<Quiz> ReadExcelFile(string filePath)
|
|
{
|
|
var result = new List<Quiz>();
|
|
|
|
using (var package = new ExcelPackage(new FileInfo(filePath)))
|
|
{
|
|
var worksheet = package.Workbook.Worksheets[0]; // Sheet đầu tiên
|
|
int rowCount = worksheet.Dimension.Rows;
|
|
|
|
for (int row = 2; row <= rowCount; row++) // Bắt đầu từ dòng 2, bỏ dòng tiêu đề
|
|
{
|
|
var ch = new Quiz
|
|
{
|
|
LinhVuc = worksheet.Cells[row, 1].Text,
|
|
CauHoi = worksheet.Cells[row, 2].Text,
|
|
A = worksheet.Cells[row, 3].Text,
|
|
B = worksheet.Cells[row, 4].Text,
|
|
C = worksheet.Cells[row, 5].Text,
|
|
D = worksheet.Cells[row, 6].Text,
|
|
DapAn = worksheet.Cells[row, 7].Text
|
|
};
|
|
|
|
result.Add(ch);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|