none
How to set a cell's formula RRS feed

Answers

  • Hi JBDevoArch,

    >> I just need to know how to set a cell's formula in excel.

    I suggest you do as below:
    1. Create an empty Excel file and a Excel file with formula;
    2. Use Open XML SDK 2.5 productivity Tool for Microsoft Office
    3. Click the Compare Files, generate the code, and then you could get the code
    For more information about Open XML SDK 2.5 productivity Tool for Microsoft Office, you could refer the link below:
    # Open XML SDK 2.5 for Microsoft Office
    https://www.microsoft.com/en-us/download/details.aspx?id=30425

    With Open XML SDK productivity Toll for Microsoft Office, you could create two files, one is original file and another it the result file, click the Compare Files, generate the code, and then you could get the code what you want.

    Pay attention to the code like below, it insert the formula to the cell:

            private  void ChangeWorksheetPart1(WorksheetPart worksheetPart1)
            {
                Worksheet worksheet1 = worksheetPart1.Worksheet;
    
                SheetViews sheetViews1=worksheet1.GetFirstChild<SheetViews>();
                SheetData sheetData1=worksheet1.GetFirstChild<SheetData>();
    
                SheetView sheetView1=sheetViews1.GetFirstChild<SheetView>();
    
                Selection selection1=sheetView1.GetFirstChild<Selection>();
                selection1.ActiveCell = "E3";
                selection1.SequenceOfReferences = new ListValue<StringValue>() { InnerText = "E3" };
    
                Row row1=sheetData1.GetFirstChild<Row>();
    
                Cell cell1=row1.Elements<Cell>().ElementAt(2);
    
                CellValue cellValue1=cell1.GetFirstChild<CellValue>();
    
                CellFormula cellFormula1 = new CellFormula();
                cellFormula1.Text = "A1+B1";
                cell1.InsertBefore(cellFormula1,cellValue1);
            }
    

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, September 1, 2015 5:53 AM