This project has moved and is read-only. For the latest updates, please go here.

Can't copy a Worksheet

Jul 7, 2011 at 10:40 PM



I'm trying to copy a worksheet that contains a chart, but when I try to do it, my code fires a "package relationship with specified id does not exist for the source part" exception, what are possible reasons for this?


Here's my code:


      public void GenerateFromTemplate(DirectoryInfo outputPath, FileInfo templateFile,
            string newFileName, List<Dictionary<stringstring>> cellDataList)
                using (ExcelPackage p = new ExcelPackage(templateFile, true))
                    bool first = true;
                    foreach (Dictionary<stringstring> cellData in cellDataList) {
                        Logger.LogInfo("Adding new Sheet...");
                        ExcelWorksheet currentWorkSheet;
                        if (first)
                            currentWorkSheet = p.Workbook.Worksheets[1];
                            first = false;
                        else {
                            currentWorkSheet = p.Workbook.Worksheets.Copy("Ticker""Ticker" + p.Workbook.Worksheets.Count);
                        foreach (KeyValuePair<stringstring> cell in cellData)
                            Logger.LogInfo(cell.Key + "cell value set to" + cell.Value);
                            currentWorkSheet.Cells[cell.Key].Value = cell.Value;
                    Byte[] bin = p.GetAsByteArray();
                    string file = outputPath + newFileName;
                    Logger.LogInfo("Writing Excel File to " + file);
                    File.WriteAllBytes(file, bin);
                    Logger.LogInfo("Writing Done");
            catch (Exception ex)

Thanks in advance! :D
Jul 7, 2011 at 10:50 PM

This is pretty weird since if I remove the chart, everything works just fine,