fix : conversion to csv

Multiplayer_Php
jeducourth 1 year ago
parent df6b0d6046
commit c01615c9d1

@ -27,6 +27,7 @@
<PackageReference Include="ChoETL.NETStandard" Version="1.2.1.64" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
<PackageReference Include="SuperConvert" Version="1.0.4.9" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>

@ -13,6 +13,7 @@ using Blazored.Modal;
using System.Text.RegularExpressions;
using Blazor.Components;
using Microsoft.Extensions.Localization;
using SuperConvert.Extensions;
namespace Blazor.Pages.Questions;
@ -110,15 +111,9 @@ public partial class Questions
StringBuilder sb = new StringBuilder();
HttpResponseMessage response = await Http.GetAsync(API.API_URL+"questionsExport/"+API.TOKEN);
var json = await response.Content.ReadAsStringAsync();
using (var jsonFile = ChoJSONReader.LoadText(json))
{
using (var csvFile = new ChoCSVWriter(sb).WithFirstLineHeader())
{
csvFile.Write(jsonFile);
}
}
var sentFile = new MemoryStream(Encoding.Unicode.GetBytes(sb.ToString()));
byte[] csv = json.ToCsv(';');
string csvString = Encoding.Unicode.GetString(csv);
var sentFile = new MemoryStream(Encoding.Unicode.GetBytes(csvString));
using (var streamRef = new DotNetStreamReference(stream: sentFile))
{
await IJSRuntime.InvokeVoidAsync("downloadFileFromStream", "data.csv", streamRef);
@ -131,9 +126,10 @@ public partial class Questions
{
await e.File.OpenReadStream().CopyToAsync(ms);
var bytes = ms.ToArray();
string s = Encoding.UTF8.GetString(bytes);
string s = Encoding.Unicode.GetString(bytes);
s = s.Replace("\r\n", "\n");
s = s.Replace("\0", "");
var rows = s.Split('\n');
rows = rows.Skip(1).ToArray();

Loading…
Cancel
Save