Unable to Save the file 2nd time after deleting the rows

Sep 13, 2012 at 2:24 AM

Hi

I am unable to save the file 2nd time if i execute the same code first time it saves but second time i am not sure why its not saving the file

 protected void MergeProcess()
        {

            try
            {

                XLWorkbook destFile;

                string[] finalfiles = Directory.GetFiles(DestinationFolderPath);

                foreach (string finalFileName in finalfiles)
                {

                    #region ForEachFinalFile

                    /*
                     * For all the available finalfiles we are going to loop through and merge the relevant data
                     * from the sourcefiles.
                     */

                    //From the filename get the Year based as its assumed and should be consistant with Year.
                    string[] arr = finalFileName.Replace(DestinationFolderPath, "").Split('.');
                    string str = arr[arr.Length - 2];
                    string year = str.Substring(str.Length - 4);

                    //Open the finalfile which needs to be merged
                    destFile = new XLWorkbook(finalFileName);
                    System.Threading.Thread.Sleep(1000);

                    //Access the "Data" Sheet in the finalfile
                    var destxWS = destFile.Worksheet("Data");


                    #region DeletePreviousRows

                    int deleterowCount = 4;
                    var isused = destxWS.Row(deleterowCount).RowUsed();

                    while (isused != null)
                    {
                        try
                        {
                            deleterowCount++;
                            isused = destxWS.Row(deleterowCount).RowUsed();

                        }
                        catch { break; }
                    }

                    if (deleterowCount > 5)
                    {
                        //destxWS.Range("A5:R" + deleterowCount.ToString()).Delete(XLShiftDeletedCells.ShiftCellsUp);
                        destxWS.Rows(5, deleterowCount).Delete();
                    }

                    destFile.Save();
                    System.Threading.Thread.Sleep(1000);

                    #endregion DeletePreviousRows
                                       

                    #endregion ForEachFinalFile

                }

            }
            catch (Exception e)
            {
                string err = e.Message.ToString();
            }
            finally
            {


            }


        }
    

Coordinator
Sep 13, 2012 at 2:50 AM

I don't understand the problem so create a project that reproduces the error and attach it to a new issue.

Sep 13, 2012 at 3:04 AM

Hi MDeleon

Just created it as a new issue and attached the project please kindly let me know if you need any other information

Regards

Raghu