Is it possible we can export Blazor Grid targetting to a Server Folder location?
Hello,
Thanks for the response. I am looking a path local to Server not browser. I use below code to get server path.
string rootPath = env.ContentRootPath;
If you also Ref. same path and not a future at present, you suggesting syncfusion Excel component for this requirement to meet?
Yes. That would help, From browser, selected Grid data Memory Stream to send to an API would do my requirement.. I need this data to attach as a file from my API during a mail send. How data reaching to API not a matter.
|
@using Syncfusion.XlsIO;
@using System.IO;
<SfButton OnClick="CsvExport" Content="CSV Export"></SfButton>
<SfGrid @ref="DefaultGrid" DataSource="@Orders" AllowSorting="true" AllowExcelExport="true" AllowPaging="true">
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
private SfGrid<Order> DefaultGrid;
public List<Order> Orders { get; set; }
. . .
public async void CsvExport()
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Import the data to worksheet
IList<Order> reports = Orders; // pass the datasoruce to csvexport
worksheet.ImportData(reports, 2, 1, true);
MemoryStream stream = new MemoryStream();
workbook.SaveAs(stream,";"); // save the workbook with different delimiter
}
}
} |