开发者

Can't copy a Worksheet that contains a Chart using EPPLUS

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? *If I remove the chart from the template, everything works fine.

Here's my code:

  public void GenerateFromTemplate(DirectoryInfo outputPath, FileInfo templateFile,
        string newFileName, List<Dictionary<string, string>> cellDataList)
    {
        try
        {
            using (ExcelPackage p = new ExcelPackage(templateFile, true))
            {
                bool first = true;
                foreach (Dictionary<string, string> 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<string, string> 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)
        {
            Logger.LogError(ex);
        }
    }

Regards!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜