Exporting the Xlsx file directly to my server

Hi,

I am trying to export the Xlsx file in a post request to my server. I am using a Python processing library at the backend. I cannot seem to use the saveAsJson method as the lib doesn't accept. To make it work I would have to write a wrapper which I am trying to avoid for not reinventing the wheel. I need to send that file to the server for further processing.

Any help would be appreciated.


5 Replies

SP Sangeetha Priya Murugan Syncfusion Team August 4, 2023 01:48 PM UTC

Hi Umair,


We have done the Open/ Save (server side) functionality in ASP.NET only. we are using the Syncfusion XLSIO library for open/save action in spreadsheet. We don’t have open/save server-side functionality for spreadsheet in Python. So, we suggest you use the local ASP.NET web service for open/save action to achieve your requirement in your end.


For save action please refer the below link:


https://ej2.syncfusion.com/angular/documentation/api/spreadsheet/#save


To save/open the excel file in server, please refer the below link.


https://www.syncfusion.com/kb/11970/how-to-open-and-save-an-excel-file-to-server-in-the-spreadsheet


And we have published our API services in the GitHub location, for more details please refer the below links.


Service sample Location: https://github.com/SyncfusionExamples/EJ2-Spreadsheet-WebServices/


https://ej2.syncfusion.com/angular/documentation/spreadsheet/open-save


Based on your scenario we suspect that you need to save the modified spreadsheet content as excel file in the server location. And it can be achievable by using the saveAsJson method as shown below.


Code Block:


 

 

  save() {

    this.spreadsheetObj.saveAsJson().then((Json) =>

      fetch('https://localhost:44354/api/spreadsheet/SaveExcel', {

        method: 'POST', // or 'PUT'

        headers: {

          'Content-Type': 'application/json',

        },

        body: JSON.stringify({

          FileName: 'SavedSampleFile.xlsx',

          JSONData: JSON.stringify((Json as any).jsonObject.Workbook),

          PDFLayoutSettings: JSON.stringify({ FitSheetOnOnePage: false }),

        }),

      }).then((basePath) => {

        console.log('file saved');

      })

    );

  }

 

 

        [HttpPost]

        [Route("SaveExcel")]

        public string SaveExcel([FromBody] SaveSettings saveSettings)

        {

            ExcelEngine excelEngine = new ExcelEngine();

            IApplication application = excelEngine.Excel;

            try

            {

                string basePath = Path.GetFullPath("Files//" + saveSettings.FileName);

                saveSettings.FileContentType = ContentType.Xlsx;

                saveSettings.VersionType = VersionType.Xlsx;

                Stream fileStream = Workbook.Save<Stream>(saveSettings); // save the file in the server

                IWorkbook workbook = application.Workbooks.Open(fileStream);

                var file = System.IO.File.Create(basePath);

                fileStream.Seek(0, SeekOrigin.Begin);

                fileStream.CopyTo(file); // to convert the stream to file options

                file.Dispose();

                fileStream.Dispose();

                fileStream.Close();

                return "Saved in Server";

            }

            catch (Exception ex)

            {

                return "Failer";

            }

        }


For your convenience, we have created sample that saves the excel file in the server location in a button click event using ASP.Net Core Web API. Please find the sample and service below.


Sample Link: https://stackblitz.com/edit/angular-ugzorn?file=src%2Fapp.component.html,src%2Fapp.component.ts


API Link:

https://ej2.syncfusion.com/angular/documentation/api/spreadsheet/#saveasjson


Note: launch the service first and then open the stackblitz sample for save action.



Attachment: WebAPI_e46e3c88.zip


UM Umair Mirza August 9, 2023 09:41 PM UTC

Can I deploy your open save service in-house and add up there a call that sends the prepared excel back to my own server? As the data cannot be sent to the third-party server?



VR Vasanth Ravi Syncfusion Team August 10, 2023 02:20 PM UTC

Hi Umair,

 

Yes. You can use our service for import and export functionality to send your prepared excel back to your server. We have written the server in C# with ASP .Net MVC and ASP .Net Core framework and we will not keep the track or trace of the files that are being managed from this service.

 

We have some limitations on the web platform, so we convert the whole workbook model to JSON data when the export action is triggered. And send that whole JSON from the client side to the server side. On the server side, we have used our Syncfusion XLSIO library to convert the workbook model to an XLSIO-supported format to export it as an Excel file. On execution of this process, the server will not keep any trace of the data within it thus by restricting the data leak.

 

Therefore, you can deploy the service provided by us for importing and exporting functionalities. Get back to us for further clarifications.




UM Umair Mirza August 13, 2023 06:50 PM UTC

Thank you so much. 



VR Vasanth Ravi Syncfusion Team August 14, 2023 05:56 AM UTC

You're welcome, Umair. Get back to us if you need any other assistance.

NOTE: If that post is helpful, please mark it as an answer so that other members can locate it more quickly.



Loader.
Up arrow icon