We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problems with sheet copy

Hi! I have some problrm with copying sheet from one workbook to another. Here is simple code that demonstrate the problem static void Main(string[] args) { IWorkbook wbMain = ExcelUtils.Open("templ.xls"); IWorksheet shTempl = wbMain.Worksheets["Template"]; IWorkbook wb = ExcelUtils.CreateWorkbook(1); IWorksheet sh1 = wb.Worksheets.AddCopy(shTempl); // Ok sh1.Name = "Sh1"; wb.Worksheets.AddCopy(shTempl); // Exception Can you help me? Thanks a lot for help

3 Replies

AD Administrator Syncfusion Team August 2, 2005 06:16 AM UTC

Hi , I put together a sample based on your requirements. Please take a look at this sample from Knowledge base and let me know if you have any questions. How do i copy worksheet from one workbook to another Workbook? Best Regards, Seetha >Hi! I have some problrm with copying sheet from one workbook to another. Here is simple code that demonstrate the problem > >static void Main(string[] args) >{ > IWorkbook wbMain = ExcelUtils.Open("templ.xls"); > IWorksheet shTempl = wbMain.Worksheets["Template"]; > > IWorkbook wb = ExcelUtils.CreateWorkbook(1); > IWorksheet sh1 = wb.Worksheets.AddCopy(shTempl); // Ok > sh1.Name = "Sh1"; > wb.Worksheets.AddCopy(shTempl); // Exception > >Can you help me? Thanks a lot for help


AD Administrator Syncfusion Team August 2, 2005 06:59 AM UTC

>Hi , > >I put together a sample based on your requirements. Please take a look at this sample from Knowledge base and let me know if you have any questions. > >How do i copy worksheet from one workbook to another Workbook? > >Best Regards, >Seetha > > Thanks a lot for answer. I readed this help topic. Problem is still staying. I think this is bug. Here is code fragment that demonstrate the problem: [STAThread] static void Main(string[] args) { ExcelUtils.ThrowNotSavedOnDestroy = false; IWorkbook wbSrc = ExcelUtils.Open("Src.xls"); IWorkbook wbDest = ExcelUtils.CreateWorkbook(1); wbDest.Worksheets.AddCopy(wbSrc.Worksheets[0]); // Ok wbDest.Worksheets.AddCopy(wbSrc.Worksheets[0]); // Ok wbDest.Worksheets.AddCopy(wbSrc.Worksheets[0]); // Exception An unhandled exception of type ''System.NullReferenceException'' occurred in syncfusion.excelrw.base.dll Additional information: Object reference not set to an instance of an object wbDest.SaveAs("Dest.xls"); }


AD Administrator Syncfusion Team August 3, 2005 12:03 PM UTC

Hi, I was able to see the issue and have filed a bug report with the development team. Defect #552 - AddCopy does not work properly when copying multiple times Best Regards, Seetha > > >>Hi , >> >>I put together a sample based on your requirements. Please take a look at this sample from Knowledge base and let me know if you have any questions. >> >>How do i copy worksheet from one workbook to another Workbook? >> >>Best Regards, >>Seetha >> >> >Thanks a lot for answer. I readed this help topic. Problem is still staying. I think this is bug. Here is code fragment that demonstrate the problem: > >[STAThread] >static void Main(string[] args) >{ >ExcelUtils.ThrowNotSavedOnDestroy = false; >IWorkbook wbSrc = ExcelUtils.Open("Src.xls"); >IWorkbook wbDest = ExcelUtils.CreateWorkbook(1); >wbDest.Worksheets.AddCopy(wbSrc.Worksheets[0]); // Ok >wbDest.Worksheets.AddCopy(wbSrc.Worksheets[0]); // Ok >wbDest.Worksheets.AddCopy(wbSrc.Worksheets[0]); // Exception An unhandled exception of type ''System.NullReferenceException'' occurred in syncfusion.excelrw.base.dll Additional information: Object reference not set to an instance of an object >wbDest.SaveAs("Dest.xls"); >}

Loader.
Up arrow icon