Skip to content

Commit 6f02960

Browse files
author
SanthanalakshmiSF4847
committed
998433: Added the missed content
1 parent 2a0d6e5 commit 6f02960

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

Document-Processing/Excel/Spreadsheet/Blazor/open-and-save.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,87 @@ When a protected sheet or workbook is saved or downloaded, all associated settin
514514
### Supported file formats
515515
The Spreadsheet component supports saving files in the Microsoft Excel (.xlsx) format.
516516

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+
<button OnClick="SaveWorkbookHandler">Save as Excel</button>
540+
<SfSpreadsheet @ref="SpreadsheetInstance" DataSource="DataSourceBytes"></SfSpreadsheet>
541+
542+
@code {
543+
public byte[] DataSourceBytes { get; set; }
544+
public SfSpreadsheet SpreadsheetInstance { get; set; }
545+
546+
protected override void OnInitialized()
547+
{
548+
string filePath = "wwwroot/Sample.xlsx";
549+
DataSourceBytes = File.ReadAllBytes(filePath);
550+
}
551+
552+
public async Task SaveWorkbookHandler()
553+
{
554+
// Exports the workbook as "MonthlyReport.xlsx"
555+
await SpreadsheetInstance.SaveAsync(new SaveOptions
556+
{
557+
SaveType = SaveType.Xlsx,
558+
FileName = "MonthlyReport"
559+
});
560+
}
561+
}
562+
{% endhighlight %}
563+
{% endtabs %}
564+
565+
#### Save as a MemoryStream
566+
567+
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+
<button OnClick="SaveToServer">Save to Server</button>
575+
<SfSpreadsheet @ref="SpreadsheetInstance" DataSource="DataSourceBytes"></SfSpreadsheet>
576+
577+
@code {
578+
public byte[] DataSourceBytes { get; set; }
579+
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+
517598
## New
518599
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**.
519600

0 commit comments

Comments
 (0)