Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7498471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:29:20+00:00 2026-05-29T19:29:20+00:00

When I try to add a SUMIF formula to an Excel file that has

  • 0

When I try to add a SUMIF formula to an Excel file that has data, Excel says the file has “unreadable content” and asks if it has to try to recover the contents of the file. If I then click “Yes”, it removes said formula and opens the file.

When I try to copy-paste the same SUMIF formula that was generated in the Excel file manually, it works. When I try another formula (a simple “SUM” for instance) it works.

Does anyone have any idea what could be wrong?

I’m using the OpenXML SDK from Microsoft to write to the Excel file. Again, this code works perfectly for some formulas (e.g. SUM), but not for SUMIF.

/// <summary>
/// Gets or set the cell formula
/// </summary>
public string Formula
    {
        get
        {
            return _cell.CellFormula.Text;
        }
        set
        {
            if(_cell.CellFormula == null) 
                _cell.CellFormula = new CellFormula(); 

            _cell.CellFormula.Text = value;
        } 
    }

Edit: After opening the Excel file and checking the xml files within, I found that the SUMIF function is saved in the exact same way as the SUM function (“=SUMIF(J3:J33;L34;N3:N33)” and “=SUM(N3:N33)” respectively, both without quotes), so there is no real difference in how the formula is written to the file.

Thanks in advance!

— Spoiler: The solution is to use “,” instead of “;” when working with formulas in your code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:29:22+00:00Added an answer on May 29, 2026 at 7:29 pm

    Whenever I get unreadable content errors when working with the Open XML SDK, I will create a blank worksheet and add the piece that is causing the errors to that worksheet. I will then use the Open XML SDK 2.0 Productivity Tool to see what gets generated behind the scenes and use the code it produces to get rid of the unreadable content errors.

    I did those steps and noticed the following were added when you add the SUMIF formula. The first being you need to add the formula to the cell using the following code:

        // Creates an Cell instance and adds its children.
        public Cell GenerateCell()
        {
            Cell cell1 = new Cell(){ CellReference = "A1" };
            CellFormula cellFormula1 = new CellFormula();
            cellFormula1.Text = "SUMIF(J3:J33,L34,N3:N33)";
            CellValue cellValue1 = new CellValue();
            cellValue1.Text = "0";
    
            cell1.Append(cellFormula1);
            cell1.Append(cellValue1);
            return cell1;
        }
    

    This will produce the following XML:

    <x:c r="A1" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
      <x:f>SUMIF(J3:J33,L34,N3:N33)</x:f>
      <x:v>0</x:v>
    </x:c>
    

    The text value is just the result of the summation, which is zero in my case since the range I defined were empty.

    Next you need to make sure the worksheet contains a sheetDimension which is defined as:

    This element specifies the used range of the worksheet. It specifies
    the row and column bounds of used cells in the worksheet. This is
    optional and is not required. Used cells include cells with formulas,
    text content, and cell formatting. When an entire column is formatted,
    only the first cell in that column is considered used.

    The code that code generated for me was:

     // Creates an SheetDimension instance and adds its children.
     public SheetDimension GenerateSheetDimension()
     {
        SheetDimension sheetDimension1 = new SheetDimension(){ Reference = "A1" };
        return sheetDimension1;
     }
    

    The XML looks like:

    <x:dimension ref="A1" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main" />
    

    Next you need to make sure the worksheetPart contains a calcChainPart which will have a calcChain element with a calculationCell child.

    This element represents a single cell, which shall contain a formula,
    in the calc chain. Cells are calculated in the same order as the c
    elements appear in the Calculation Chain part.

    This just tells excel which sheet contains the formula and which cell it is applied to. Here is the code and XML for mine:

    // Creates an CalculationCell instance and adds its children.
    public CalculationCell GenerateCalculationCell()
    {
       CalculationCell calculationCell1 = new CalculationCell(){ CellReference = "A1", SheetId = 1 };
       return calculationCell1;
    }
    
    <x:c r="A1" i="1" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main" />
    

    Finally, the workbookPart needs a calculationProperties element which defines the collection of properties the application uses to record calculation status and details. Calculation is the process of computing formulas and then displaying the results as values in the cells that contain the formulas.

    // Creates an CalculationProperties instance and adds its children.
    public CalculationProperties GenerateCalculationProperties()
    {
       CalculationProperties calculationProperties1 = new CalculationProperties(){ CalculationId = (UInt32Value)125725U };
       return calculationProperties1;
    }
    
    <x:calcPr calcId="125725" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main" />
    

    As you can see, all of these various elements and parts are created for you behind the scenes when you add a formula to a cell when using Excel. Unfortunately, you are responsible for adding the necessary elements when adding formulas using the Open XML SDK. Most likely one of these elements are missing from your Excel document, which is why you are probably getting an unreadable content error when opening up your Excel document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to add lookup field in content type. Field has this definition: <Field
I try to add Message.framework to my project frameworks directory. After that I compile
I have an example web solution that I downloaded and when I try Add
I try to add new data source for object with Data Source Configuration Wizard
My IDE crashes any time I try add a new component to the toolbar.
I try to add an addons system to my Windows.Net application using Reflection; but
I try to add dots between the page title and the page number in
I try to add a class to a td-element using javascript with the internet
Whenever I try to add a new project to my SourceSafe repository it creates
If I try to add a tab to the toolbox and name it 'Clipboard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.