0

is there a way to export information to an xlsm file? the steps I do is:

in a button I put an input to select the file, I upload the file to the server I look for the sheet which is already specified in the code I modify the file information according to the information to be exported command to save the file locally.

the error is as follows: {"The 'br' start tag on line 59 position 30 does not match the end tag of 'font'. Line 60, position 9."} when indicating the sheet with which to work

I share my code: any suggestions?

public void ExportFile(string FileName, string UserID)
        {
            FileInfo fi = new FileInfo(FileName);
            Master.MSGError = string.Empty;
            string SheetName = "test";
            using (MemoryStream file = new MemoryStream())
            {
                try
                {
                    using (ExcelPackage xlPackage = new ExcelPackage(fi))
                    {
                        ExcelWorksheet worksheet;
                        worksheet = xlPackage.Workbook.Worksheets[SheetName]; //here is the error exception 
                        
                        worksheet.Cells[1, 1].Value = "TEST";
                        
                        //save file
                         xlPackage.SaveAs(file);
                        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                        

                        Response.BinaryWrite(file.ToArray());
                        Response.Flush();
                        Response.End();
                    }
                }
                catch (Exception ex)
                {
                    Master.fc.MSGError = ex.Message;
                }
            }
        }
  • epplus version? with epplus should work , if task is simple and you can change try with npoi. – Xilmiki Jul 14 '21 at 18:24
  • 1
    XLSM correct mime is application/vnd.ms-excel.sheet.macroEnabled.12 – Xilmiki Jul 14 '21 at 18:26
  • I already tried it with with epplus and closedxml – Diego Bonfil Jul 14 '21 at 18:28
  • 1
    @Diego Bonfil, based on my test, I meet the different error where you mentioned. I add the code ** ExcelPackage.LicenseContext = LicenseContext.NonCommercial;** to solve the problem. Based on your error, could you provide your xlsm file? I think your error related to your file. Besides, we should use **xlPackage.Save();** to save the file. – Jack J Jun Jul 15 '21 at 06:54
  • @Jack J Jun, I wish I could share the file but it doesn't belong to me, I ran into another error using closedxml, there seems to be several issues related to the content of the file : https://stackoverflow.com/questions/29970814/openxml-excel-throw-error-in-any-word-after-mail-address – Diego Bonfil Jul 15 '21 at 16:34

1 Answers1

0

Currently I solved my problem I thought that the detail was in the macro, but I found the real error doing different tests, it seems that both epplus and closedxml have problems reading certain information in the excel, I ended up using closedxml and applying the solution: OpenXml Excel: throw error in any word after mail address

I'm sorry for confusion

  • I am glad to hear that your problem has been solved, you can click '✔' to mark your reply as an answer. It will also help others to solve the similar issue. – Jack J Jun Aug 05 '21 at 08:52