The frontend is in Angular. The backend is in .net Core.
- trying to develop an import excel sheet functionality so in the frontend, I am using angular where I want to import the file and I need to convert that excel data into array format or in JSON
- for convert excel into an array I want one rest API in .net core ( i don't want to use XSLX PAckage from angular)
this method I developed, here I am passing FILE as bsae64 in request body to these API
public async Task<dynamic> converexceltotAray()
{
using (StreamReader steamread = new StreamReader(Request.Body, System.Text.Encoding.UTF8))
{
string s = await steamread.ReadToEndAsync();
byte[] newBytes = Convert.FromBase64String(s);
using (MemoryStream stream = new MemoryStream(newBytes)) {
byte[] bytes = stream.ToArray();
var reader = ExcelReaderFactory.CreateReader(stream);
var result = reader.AsDataSet(new ExcelDataSetConfiguration()
{
ConfigureDataTable = (_) => new ExcelDataTableConfiguration()
{
//ReadHeaderRow = (rowReader) => {
// for(int i=0;i<3;i++)
// {
// rowReader.Read();
// }
//},
UseHeaderRow = true,
}
});
DataTable table = result.Tables[1];
//dataGridView1.DataSource = table;
string json = JsonConvert.SerializeObject(table, Formatting.Indented);
//rtxtOutPut.Text = json;
//stream.Close();
return json;
}
}
}