Insert Formula Matrix in Excel, via C#. ? (If you insert directly through excel, I have to give Crtl - Shift - Enter) - How to do this command with C#?

Asked

Viewed 59 times

0

The following Code inserts a Formula into a cell in Excel. Based on the Spreadsheet "DATA", AND According to the column beside. However, this formula is a Matrix Formula, which in Excel needs to be inserted by the keys Ctrl + Shift + Enter. Different from the Basic Formulas, which only with Enter is already inserted.


In Excel, this Formula is inserted with the Ctrl + Shift + Enter keys. It is with {} between them.

inserir a descrição da imagem aqui

However, in the code if I insert these {}, it does not even read as Formula.


Follow the excerpt of the Code, which inserts the Formula.

              if (!dado.Equals("Outros"))
                {
                    planilhaGrafico.Cells[i, j].Value = dado;

                    planilhaGrafico.Cells[i, j + 1].Formula
                        "=SUM(LEN(" + nomePlanilha + "!" + colunaGrafico
                        + ":" + colunaGrafico + ")-LEN(SUBSTITUTE(" 
                        + nomePlanilha + "!" + colunaGrafico
                        + ":" + colunaGrafico + ",A" + i + ",\"\")))/LEN(A" + i 
                        + ")";
                }

Does anyone know how to Insert a Matrix Formula, by C#, in Excel.???

Yeah, the command planilhaGrafico.Cells[i, j + 1].Formuladoes not insert correctly.

1 answer

0


I managed to make.

Answer obtained on Link: C# EPPLUS excel array formula workarounds

Stayed that way:

planilhaGrafico.Cells[i, j + 1].CreateArrayFormula("=SUM(LEN(" + nomePlanilha + "!" + colunaGrafico
+ ":" + colunaGrafico + ")-LEN(SUBSTITUTE(" + nomePlanilha + "!" + colunaGrafico
+ ":" + colunaGrafico + ",A" + i + ",\"\")))/LEN(A" + i + ")");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.