We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Urgent : Excel file (.xlsm) is getting corrupted when save as .xls and upload to server

Hi Team,

Our requirement is as below.

  • We have an excel template with file extension as .xlsm.
  • User can also download this template as .xlsm or .xls
    -User will upload this after providing data to server.

Issue :

  • User downloaded the template as .xls
  • User uploaded the template to the server.
  • User access and try to open the uploaded excel file.
  • User found the file has been corrupted.

The code has been used as below.

Downloading excel ( .xls from .xlsm)

		if (excelVersion == "XLS")
        {
            Workbook.Save(Response,fileName + ".xls", ContentDisposition.Attachment,
                              new XlsSaveOptions(SaveFormat.Excel97To2003));
        }          
        else
        {
            Workbook.Save(Response, fileName + ".xlsm", ContentDisposition.Attachment,
                             new OoxmlSaveOptions(SaveFormat.Xlsm));
        }

Upload The downloaded .xls file

					string fileName = string.Format("{0}{1}{3}",
                                      file.GetNameWithoutExtension(), UIConstants.EXCEL_SEPERATOR_ID_TEXT,file.GetExtension());
					string fileFullPath = Path.Combine(fileUploadPath, fileName);

                    using (Stream file1 = File.OpenWrite(fileFullPath))
                    {
                        file1.Write(uploadRequest.FileData, 0, uploadRequest.FileData.Length);
                    }

Also , please suggest If I can save a file which can be saved in the server?

Hi,

Thanks for your posting and using Aspose.Cells.

Please provide your code again for investigation. Because all of your code in your post is jumbled up and we are unable to look into it properly. Thanks for your cooperation.