You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Document-Processing/Excel/Spreadsheet/Blazor/open-and-save.md
+81Lines changed: 81 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -514,6 +514,87 @@ When a protected sheet or workbook is saved or downloaded, all associated settin
514
514
### Supported file formats
515
515
The Spreadsheet component supports saving files in the Microsoft Excel (.xlsx) format.
516
516
517
+
### Save an Excel file programmatically
518
+
519
+
The Blazor Spreadsheet component provides two methods for saving Excel files programmatically:
520
+
521
+
-[SaveAsync()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_SaveAsync_Syncfusion_Blazor_Spreadsheet_SaveOptions_) – Saves the spreadsheet as an Excel file.
522
+
-[SaveAsStreamAsync()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_SaveAsStreamAsync) – Returns the spreadsheet content as a [MemoryStream](https://learn.microsoft.com/dotnet/api/system.io.memorystream) for further processing or storage.
523
+
524
+
#### Save as an Excel file
525
+
526
+
The [SaveAsync()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_SaveAsync_Syncfusion_Blazor_Spreadsheet_SaveOptions_) method saves the spreadsheet content as an Excel file programmatically and supports customization through the [SaveOptions](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SaveOptions.html) parameter.
527
+
528
+
| Parameter | Type | Description |
529
+
| -- | -- | -- |
530
+
| options |[SaveOptions](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SaveOptions.html)| Specifies settings for the save operation, such as the file name and file type (for example, XLSX). |
531
+
532
+
N> If options are not provided, the default settings are **FileName**: `"Spreadsheet"` (the downloaded file will be named `"Spreadsheet.xlsx"`) and **SaveType**: [SaveType.Xlsx](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SaveType.html).
533
+
534
+
{% tabs %}
535
+
{% highlight razor tabtitle="Index.razor" %}
536
+
537
+
@using Syncfusion.Blazor.Spreadsheet
538
+
539
+
<buttonOnClick="SaveWorkbookHandler">Save as Excel</button>
The [SaveAsStreamAsync()](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_SaveAsStreamAsync) method retrieves the spreadsheet content as a [MemoryStream](https://learn.microsoft.com/dotnet/api/system.io.memorystream) for further processing, such as saving to a database or cloud storage.
568
+
569
+
{% tabs %}
570
+
{% highlight razor tabtitle="Index.razor" %}
571
+
572
+
@using Syncfusion.Blazor.Spreadsheet
573
+
574
+
<buttonOnClick="SaveToServer">Save to Server</button>
public SfSpreadsheet SpreadsheetInstance { get; set; }
580
+
581
+
protected override void OnInitialized()
582
+
{
583
+
string filePath = "wwwroot/Sample.xlsx";
584
+
DataSourceBytes = File.ReadAllBytes(filePath);
585
+
}
586
+
587
+
public async Task SaveToServer()
588
+
{
589
+
var stream = await SpreadsheetInstance.SaveAsStreamAsync();
590
+
// Example: Saves the stream to a file named "ServerReport.xlsx"
591
+
using var fileStream = File.Create("wwwroot/ServerReport.xlsx");
592
+
stream.CopyTo(fileStream);
593
+
}
594
+
}
595
+
{% endhighlight %}
596
+
{% endtabs %}
597
+
517
598
## New
518
599
To create a new, blank workbook through the UI, select **File > New** from the **Ribbon**. This action initializes a blank spreadsheet component, ready for data entry or formatting. If unsaved changes are present, a confirmation dialog will appear, indicating that these changes will be lost. The dialog presents options to proceed with creating the new workbook by selecting **OK**, or to cancel the operation by selecting **Cancel**.
0 commit comments