Hi team, I am using below code for performing the task mentioned. The problem is, code is working fine if there are NO graphical objects (charts etc) in the sheet. And if I run the same code on excels having charts, destination file is getting corrupted. Like, when I open the saved file in Excel, it throws an error - 'We found a problem with some content ‘destination file - name’ Do you want us to try to recover as much as we can? Yes or No. If we say Yes, MS Excel is throwing another error ‘Removed Part: /xl/drawings/drawing1.xml part. (Drawing shape)’ - there after, opening the file, but with no graphs.
My objective is move copy the sheet into destination as values. And the formattings, borders, colors everything should stay as is. Can you please advise. Thanks.
public void MoveCopySheetFromSourceToDestWorkBook(Workbook srcBook, Worksheet srcSheet, Workbook destBook, bool deleteIfAlreadyExists = true)
if (deleteIfAlreadyExists && destBook.ContainsSheet(srcSheet.Name))
CopyOptions copyOptions = new CopyOptions(); copyOptions.CopyInvalidFormulasAsValues = true; copyOptions.CopyNames = false; copyOptions.ReferToSheetWithSameName = false; Worksheet destSheet = destBook.Worksheets.Add(srcSheet.Name); destSheet.Copy(srcSheet,copyOptions); // Copy the page setup from source to destination destSheet.PageSetup.Copy(srcSheet.PageSetup, copyOptions); destSheet.PageSetup.PrintArea = srcSheet.PageSetup.PrintArea; destSheet.TabColor = srcSheet.TabColor; if (destBook.ContainsSheet("Sheet1")) destBook.Worksheets.RemoveAt("Sheet1"); //srcBook.Save(@"C:\Users\sv41\Desktop\New folder\source.xlsm"); destBook.Save(@"C:\Users\sv41\Desktop\New folder\destination.xlsx"); }