RadRibbonBar (RadSpreadsheetRibbonBar) and default file name for save

2 Answers 53 Views
RibbonBar Spreadsheet
Andy F.
Top achievements
Rank 1
Iron
Andy F. asked on 02 Oct 2023, 08:53 PM
I'm using RadSpreadsheet with the ribbon bar to display a generated Excel workbook.  Users want to save the workbook via the Save ribbon button, but they want a default filename in the save dialog (not "book1.xlsx").  I can't figure out how to get there from current documentation and other forum questions.  Please advise.  Hoping I can access it without overriding the whole framework that already does most of the work for me.

2 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Oct 2023, 04:58 AM

Hello, Andy,

The following forum thread demonstrates a sample approach how to add a custom button to the backstage view of the ribbon UI for RadSpreadsheet:

https://www.telerik.com/forums/when-using-radspreadsheet-how-do-i-get-filename-that-was-loaded-when-user-uses-file-open#5715473  

A similar approach can be followed for the Save button as well (Name = "backstageButtonSave") and add a button with the default file name or any other custom logic. Please give it a try and see how it works on your end.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Andy F.
Top achievements
Rank 1
Iron
commented on 03 Oct 2023, 01:03 PM

I saw that answer, but didn't want to create a second Save, didn't really want to have to add additional code to get it to do exactly what it already does, just with a different default file name.  Seems like the open/save features need more property exposure for the dialog boxes they open (or at least access to the dialog box controls so that properties can be set on the dialog before it opens).
Dess | Tech Support Engineer, Principal
Telerik team
commented on 05 Oct 2023, 09:20 AM

Hi, Andy,

I understand your point and indeed, it seems to be a reasonable request for the public API to introduce default file names for the Open/Save functionality in the ribbon UI.

I have logged it in our feedback portal by creating a public thread on your behalf. You can track its progress, subscribe for status changes, and add your comments on the following link - feedback item.

I have also updated your Telerik points.

0
Andy F.
Top achievements
Rank 1
Iron
answered on 27 Oct 2023, 03:20 PM

Using that example, I went a slightly different route I want to share.  I rewired the default Save command instead.

In the setup of the form, I added an event handler for the commands as in the example:

AddHandler rsExcel.SpreadsheetElement.ActiveSheetEditor.UICommandExecuting, AddressOf SaveMenuHandler

Then I added this as the Save handler:

Private Sub SaveMenuHandler(sender As Object, e As UICommandExecutingEventArgs)
    If e.Command Is rsExcel.SpreadsheetElement.CommandDescriptors.SaveFile.Command Then
        e.Cancel()
        ' now open the save dialog and get the file name and do the save
        Dim fileName As String = String.Empty
        fileName = String.Empty

        Dim askDlg As New SaveFileDialog()
        askDlg.FileName = Me.DefaultSaveFileName
        askDlg.AddExtension = True
        askDlg.Title = "Select Location and Name the Excel File for the Office Scheduling Sheet"
        askDlg.Filter = "Excel Files (*.xlsx)|*.xlsx"
        askDlg.FilterIndex = 0
        askDlg.CheckPathExists = True
        askDlg.CheckFileExists = False
        askDlg.OverwritePrompt = True
        askDlg.RestoreDirectory = True
        askDlg.CreatePrompt = False
        askDlg.DefaultExt = ".xlsx"
        askDlg.InitialDirectory = DefaultUserDirectory
        If askDlg.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
            fileName = askDlg.FileName
        End If

        If fileName <> String.Empty Then
            Me.Cursor = Cursors.WaitCursor
            Application.DoEvents()
            Dim formatProvider As New XlsxFormatProvider()
            Using output As Stream = New FileStream(fileName, FileMode.Create)
                formatProvider.Export(Me.rsExcel.Workbook, output)
            End Using
        End If
    End If
End Sub
The Save menu does not fire the default Save code because of e.Cancel() call.  This worked and I can use it to override any existing menu instead of adding a new one.
Dess | Tech Support Engineer, Principal
Telerik team
commented on 01 Nov 2023, 01:12 PM

Hi, Andy,

I have reviewed the provided code snippet and it seems OK as a suitable approach for covering the requirement you have. Feel free to use it in your account according to your needs.

Tags
RibbonBar Spreadsheet
Asked by
Andy F.
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Andy F.
Top achievements
Rank 1
Iron
Share this question
or