0

Hello i have this code in c# that inserts values in excel and then saves the file but i get an error saying Error saving file C:\Users\user\Desktop\Phone.xlsx

This is the code:

  Regex re = new Regex(@"\s*\+\d+ \d{3}-\d{3}-\d{4}"); //\w{8}, \w{2}, \w[a-zA]{5}
                    var matches = re.Matches(tag.InnerText);
                    foreach (Match m in matches)
                    {
                        lines.Add(m.Value);
                            count = lines.Count;
                            try
                            {
                                sheet.Cells.LoadFromCollection(lines, true);
                            }catch(Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                    }
                    if (matches.Count == 0)
                    {
                        lines.Add("Sorry no phone number found!");
                    }
               }
 FileInfo excelFile = new FileInfo(@"C:\Users\user\Desktop\Phone.xlsx");
                try
                {
                    xlWorkbook.SaveAs(excelFile); //error happens here
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

1 Answers1

0

check detail Exception about error you get (inner Exception ) and tell more about it . also i think change save directory to another location , for example D:\ , don't use C:\