#NAME error when inserting a chart as an image in word document

Hi Aspose Team,
I’m having an issue with some charts where I’m inserting it into a word document and one of the footnotes for the chart comes in as #NAME? even though the name range from which it is pulled into the chart exists.
Below is the sample code I’ve used. Another thing I’d like to point out is the fact that the images stored separately as EMF File (Chart_Demographics_D137_O169, Chart_Demographics_D205_O237, etc) have missing information even though the same thing that is inserted into word document looks to be complete aside from the #NAME? error.

static void TestChartInsertion()
{
    string dir = @"Insert you directory path here";
    List<string> PrintAreas = new() { "Demographics!R137C4:R169C15", "Demographics!R205C4:R237C15", "Demographics!R476C4:R508C15", "Demographics!R510C4:R542C15" };
    Document doc = new Document();
    DocumentBuilder Builder = new DocumentBuilder(doc);
    using (Workbook TestWB = new Workbook(dir + @"Chart_Template.xlsm"))
    {
        foreach (var coordinates in PrintAreas)
        {
            Stream ImgStream = ProcessOleObject_Aspose(TestWB, coordinates, dir);
            if (ImgStream == Stream.Null)
            {
                continue;
            }
            Builder.InsertImage(ImgStream);
            Builder.InsertBreak(BreakType.PageBreak);
        }
    }
    doc.Save(dir + @"TestDoc_Aspose.docm");
}

static Stream ProcessOleObject_Aspose(Workbook sourceWB, string imgCoordinates, string dir)
{
    string ProcessName = "Convert excel range to image";
    string ExceptionType = "P";
    string StartCell = string.Empty;
    string EndCell = string.Empty;
    try
    {
        //Check to see if image coordinate matches the regex.
        //Regex Pattern = new Regex(@"^[a-zA-Z0-9]+![\s]*R[0-9]+C[0-9]+:R[0-9]+C[0-9]+$");
        Regex Pattern = new Regex(@"^.*![\s]*R[0-9]+C[0-9]+:R[0-9]+C[0-9]+$");
        if (!Pattern.IsMatch(imgCoordinates))
        {
            throw new Exception($"Invalid range encountered: {imgCoordinates}");
        }
        string[] CoordinateParts = imgCoordinates.Trim().Split('!', ':');
        // Here's an example of what an imgCoordinates looks like RespRate!R5C1:R8C2
        string WSName = CoordinateParts[0].Trim(); //RespRate
        string StartAddress = CoordinateParts[1].Trim(); //R5C1
        string EndAddress = CoordinateParts[2].Trim(); //R8C2

        //Processing Start Address
        string[] StartDigits = StartAddress.Split('R', 'C').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
        int.TryParse(StartDigits[0], out int startRow);
        int.TryParse(StartDigits[1], out int startCol);
        //Process End Address
        string[] EndDigits = EndAddress.Split('R', 'C').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
        int.TryParse(EndDigits[0], out int endRow);
        int.TryParse(EndDigits[1], out int endCol);

        // Coordinates cannot be zero by any chance 
        if (startRow != 0 || startCol != 0 || endRow != 0 || endRow != 0)
        {
            // Convert the starting coordinates to cell address
            StartCell = CellsHelper.CellIndexToName(startRow - 1, startCol - 1);
            // Convert the ending coordinates to cell address
            EndCell = CellsHelper.CellIndexToName(endRow - 1, endCol - 1);
        }
        else
        {
            throw new Exception($"Linked coordinate contain 0 as a coordinate.\n Cannot convert the image coordinate -\n {imgCoordinates}\n to an image");
        }

        //Open the source workbook
        sourceWB.CalculateFormula();
        Worksheet sourceWS = sourceWB.Worksheets[WSName];

        //Set print area
        sourceWS.PageSetup.PrintArea = $"{StartCell}:{EndCell}";
        sourceWS.PageSetup.LeftMargin = 0;
        sourceWS.PageSetup.RightMargin = 0;
        sourceWS.PageSetup.TopMargin = 0;
        sourceWS.PageSetup.BottomMargin = 0;
        // Clear any header/footer as they'll be captured when converting the worksheet to image
        sourceWS.PageSetup.ClearHeaderFooter();

        // Set OnePagePerSheet option as true
        ImageOrPrintOptions options = new ImageOrPrintOptions
        {
            OnePagePerSheet = true,
            ImageType = Aspose.Cells.Drawing.ImageType.Emf,
            HorizontalResolution = 100,
            VerticalResolution = 100,
            OnlyArea = true,
            TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
        };

        // Take the image of your worksheet
        SheetRender Render = new SheetRender(sourceWS, options);
        // Create a stream to save the image in
        MemoryStream Stream = new MemoryStream();
        Render.ToImage(0, Stream);
        Render.ToImage(0, dir + $"Chart_{WSName}_{StartCell}_{EndCell}.emf");
        return Stream;
    }
    catch (Exception ex)
    {
        return Stream.Null;
    }
}

Files used for testing:
Test_12112025.zip (2.2 MB)

@JThomas98

What I understand from your post

  • You are converting a range that contains a chart (the chart has a footnote that refers to a named range) to an EMF image with Aspose.Cells, then inserting that image into a Word document with Aspose.Words.
  • In the resulting Word document the footnote appears as #NAME? even though the named range exists in the source workbook. The same EMF files saved to disk also show missing information (the footnote text is not rendered).
  • The code you posted calls sourceWB.CalculateFormula(); before rendering and uses ImageOrPrintOptions with OnePagePerSheet = true, OnlyArea = true, etc.

These observations are confirmed by the forum thread you posted [#1, #2]​.

What we need to investigate further

The #NAME? value is what Excel returns when a formula refers to a name that cannot be resolved. When a chart’s text box (or footnote) contains a formula like =MyFootnote, the rendering engine must evaluate that name before drawing the chart. If the name is not available in the calculation context used by Aspose.Cells, the rendered image will contain #NAME?.

To pinpoint the cause we need a few additional details:

Required information Why it matters
Aspose.Cells and Aspose.Words version numbers (e.g., 24.9, 24.10, etc.) Some rendering bugs are version‑specific; the latest release often contains fixes.
A minimal reproducible sample (the workbook with the chart and the named range) Allows us to verify whether the name is defined in the same worksheet, another sheet, or a workbook‑level name.
Whether the chart footnote is a text box with a formula (=MyName) or plain static text Static text is always rendered; a formula requires calculation.
If you have any external references (e.g., links to other workbooks) used by the named range External links are not resolved by default and can lead to #NAME?.
Whether you have tried options.RenderChart = true (the default) or options.RenderChart = false Disabling chart rendering would skip the footnote entirely; enabling it ensures the chart is drawn, but the name must be resolved.

Typical steps that resolve the issue

  1. Upgrade to the latest Aspose.Cells/Words build – many chart‑rendering improvements were added after version 23.x.
  2. Verify the named range scope – open the workbook in Excel and check Formulas ► Name Manager. The name should be Workbook scope (or at least visible to the sheet that contains the chart).
  3. Force calculation of all formulas before rendering:
    sourceWB.CalculateFormula();               // already present
    sourceWB.CalculateFormulaEngine();         // optional extra call in newer versions
    
  4. Render the chart explicitly (instead of rendering the whole sheet) to see if the footnote is drawn correctly:
    var chart = sourceWS.Charts[0];            // or the appropriate index
    using (var imgStream = new MemoryStream())
    {
        chart.ToImage(imgStream, ImageOrPrintOptions.ImageType.Emf);
        imgStream.Position = 0;
        Builder.InsertImage(imgStream);
    }
    
    If the chart image contains the correct footnote, the problem is with the sheet‑rendering path.
  5. Check the PrintArea – the chart must be fully inside the area you set (OnlyArea = true). If the chart extends beyond the defined range, parts of it (including the footnote) may be clipped, causing the placeholder #NAME? to appear.
  6. If the name is defined in another workbook, load that workbook as a linked workbook or copy the name definition into the current workbook before rendering.

Next actions for you

  1. Reply with the version numbers of Aspose.Cells and Aspose.Words you are using.
  2. Attach a small workbook (e.g., a single sheet with the problematic chart and the named range) so we can reproduce the issue locally.
  3. Let us know whether the footnote is a formula (=MyName) or static text, and whether the name is workbook‑level or sheet‑level.
  4. Try the chart‑only rendering snippet above and tell us if the footnote appears correctly in the generated EMF.

Once we have the above information we can either confirm a defect in the current release or provide a precise workaround.

We look forward to your reply so we can resolve the #NAME? issue promptly.

@JThomas98,

Thanks for the sample files and details.

After initial testing, I was able to reproduce the issue as you mentioned by using your template Excel file and sample code snippet. I found “#NAME?” error when rendering charts as images. Moreover, I confirmed that the images stored separately as EMF file type (Chart_Demographics_D137_O169, Chart_Demographics_D205_O237, etc) have missing information even though the same thing that is inserted into Word document looks to be complete aside from the “#NAME?” error.

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-59547

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.