Current filter:
                                You should refresh the page.
                                  • HI 

                                    I use Spreadsheet Document API to create a Workbook and save it to MemoryStream.
                                    Then Fetch MemoryStream to spread sheet component for display.
                                    In this case how to change download file name when user click export excel button

                                1 Solution

                                Creation Date Importance Sort by
                                Hello,

                                To accomplish this task and change the resulting exported Excel file's name, you can set the Document.Options.Save.CurrentFileName property in the PreRender event handler:
                                [C#]
                                settings.PreRender = (s, e) => { MVCxSpreadsheet sh = (MVCxSpreadsheet)s; sh.Document.Options.Save.CurrentFileName = "Custom name"; ... };
                                Let us know if this helps.

                                Updated by Marina


                                Thank you for the patience. I have reviewed your sample. You don't open a stream/document initially. So, we create a new document every time a page is open. These documents are stored in the server memory. When you call the Open method and pass a  stream to this method, another new document is open and the CurrentFileName property is not assigned for this document as it was assigned once for the first open document. In your case, the best solution is to add your data to the active worksheet rather than open a new document:

                                [C#]
                                public ActionResult CustomSpreadsheetPartial() { IWorkbook wb = SpreadsheetExtension.GetCurrentDocument("Spreadsheet"); Worksheet worksheet = wb.Worksheets.ActiveWorksheet; ChangeWorksheet(worksheet); return PartialView("_SpreadsheetPartial"); } private void ChangeWorksheet(Worksheet worksheet) { worksheet.Name = "Test Report"; Cell cell = worksheet.Cells["A1"]; cell.Value = 1; worksheet.Range["A2:A10"].Formula = "=SUM(A1+1)"; worksheet.Range["B1:B10"].Formula = "=A1+2"; worksheet.Range["C1:C10"].ArrayFormula = "=A1:A10*B1:B10"; }

                                In this case, your Excel file will have a name assigned to the CurrentFileName property. See the attached sample and video. Let me know if you need further assistance.

                                Show all comments
                                • ActWeis 01.24.2019
                                  It works for the first time but when I click "Generate Report" button then save again the save dialog still shows Spreadsheet1.
                                • Marina (DevExpress Support) 01.25.2019

                                  Hi, 

                                  In the Open method, you use a new document id. That's why a new document is open and previous settings are reset as these settings were assigned to another document. To make your scenario work, you need to assign a unique id to your document and use this id. To get your document id, use the SpreadsheetExtension.GetDocumentId method. To provide you with more steps, I need to understand your scenario better. Would you please clarify what you plan to do with your document further? How will your users use Spreadsheet? I look forward to hearing from you.

                                • ActWeis 02.10.2019
                                  I was following Spreadsheet - How to open file created by Spreadsheet Document API sample.
                                  In my case users need to specify date range and click button to generate report(trigger callback and return SpreadsheetExtension.Open with stream file).
                                  After that users can see the report on page. If user want to download the report they need to press download RibbonButton to get the file.
                                • Marina (DevExpress Support) 02.11.2019
                                  Hi, 

                                  Thank you for the clarification. I am researching your project. Please bear with me.
                                • Marina (DevExpress Support) 02.12.2019

                                  HI, 

                                  Thank you for the patience. I have reviewed your sample. You don't open a stream/document initially. So, we create a new document every time a page is open. These documents are stored in the server memory. When you call the Open method and pass a  stream to this method, another new document is open and the CurrentFileName property is not assigned for this document as it was assigned once for the first open document. In your case, the best solution is to add your data to the active worksheet rather than open a new document:

                                  [C#]
                                  public ActionResult CustomSpreadsheetPartial() { IWorkbook wb = SpreadsheetExtension.GetCurrentDocument("Spreadsheet"); Worksheet worksheet = wb.Worksheets.ActiveWorksheet; ChangeWorksheet(worksheet); return PartialView("_SpreadsheetPartial"); } private void ChangeWorksheet(Worksheet worksheet) { worksheet.Name = "Test Report"; Cell cell = worksheet.Cells["A1"]; cell.Value = 1; worksheet.Range["A2:A10"].Formula = "=SUM(A1+1)"; worksheet.Range["B1:B10"].Formula = "=A1+2"; worksheet.Range["C1:C10"].ArrayFormula = "=A1:A10*B1:B10"; }

                                  In this case, your Excel file will have a name assigned to the CurrentFileName property. See the attached sample and video. Let me know if you need further assistance.

                                • ActWeis 02.12.2019
                                  Thanks for your help.
                                  Much appreciated. 
                                • Marina (DevExpress Support) 02.12.2019
                                  You are welcome!