The SaveExcel button on the CommandBar allows users to export spreadsheets into excel files. This button handles user actions by making use of the SaveExcelToResponse() method to save into excel file.
By default, the SaveExcel button is not displayed on the CommandBar. To work with the SaveExcel button, users must ensure that the ShowExcelButton property in the CommandBarInfo class is set to true.
The following image displays the SaveExcel button on the CommandBar.
While exporting to an excel file using the SaveExcel button, you can set password to enforce additional access security.
The ShowExcelSecurityPopup property gets or sets whether to display the Set password popup after a user clicks on the SaveExcel button. The following image displays the Set Password pop up.
After you set password, your excel file will be saved. If any other user wants to open the file, he/she has to enter a password and the file will be opened only after the password authetication is successful.
1. Set the FpSpread component’s ShowExcelButton property to true.
2. Set the FpSpread component’s ShowExcelSecurityPopup property to true.
3. Modify the default filename, password and the save flag.
The first example code displays the SaveExcel button on the CommandBar. The second example code shows a Set Password popup when a user clicks on the SaveExcel button. The third example code modifies the default filename, password and the save flag.
C# |
Copy Code
|
---|---|
// Display the SaveExcel button on the CommandBar. FpSpread1.CommandBar.ShowExcelButton = true; // Show the Set Password popup FpSpread1.CommandBar.ShowExcelSecurityPopup = true; // Change the default filename, password and the save flag. private void SaveExcelHandler(object sender, FarPoint.Web.Spread.SaveExcelEventArgs e) { e.FileName = "MyFile.xlsx"; e.Password = "MyPassword"; e.Flag = FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat; } |
VB |
Copy Code
|
---|---|
' Display the SaveExcel button on the CommandBar. FpSpread1.CommandBar.ShowExcelButton = true; ' Show the Set Password popup FpSpread1.CommandBar.ShowExcelSecurityPopup = true; ' Change the default filename, password and the save flag Private Sub SaveExcelHandler(sender As Object, e As FarPoint.Web.Spread.SaveExcelEventArgs) e.FileName = "MyFile.xlsx" e.Password = "MyPassword" e.Flag = FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat End Sub |
A file with the default name MyFile.xlsx will be saved to your computer. The saved excel file will be password protected.
Note: The Export to Excel feature has the following limitation:
The SaveExcelToResponse() method doesn't work when Spread is placed in an UpdatePanel control.