Why is an # symbol after = symbol in excel formula with EPPLUS? - c#

This is how the formula appears in excel:
I want to use Forecast formula in Excel with EPPLUS from c#. The formula in the code is correct but in Excel appears =#FORECAST(params).
ExcelRange targetDate = sheet.Cells[listItems + 2, 2];
ExcelRange values = sheet.Cells[2, 3, listItems+1, 3];
ExcelRange timeLine = sheet.Cells[2, 2, listItems+1, 2];
sheet.Cells[8, 4].Formula = "=FORECAST.ETS(" + targetDate + "," + values + "," + timeLine + ",1,1)";
sheet.Cells[8, 4].Calculate();
I want to trim the # from the formula in the excel file, like this:
=FORECAST.ETS(B8,C2:C7,B2:B7,1,1)

In code you don't need to put the '=' character
Just use:
sheet.Cells[8, 4].Formula = "FORECAST.ETS(" + targetDate + "," + values + "," + timeLine + ",1,1)";

Similar Problem
I'm having a similar problem with a different formula:
worksheet.Cells[y, x].Formula = "SUMME(C5:C35)";
gave me =#SUMME(C5:C35) within Excel.
Instead of =SUMME(C5:C35).
Solution
It seems that EPPLUS has problems with the German formula. The problem disappears when I use:
worksheet.Cells[y, x].Formula = "SUM(C5:C35)";
My generated Excel now looks like this: =SUMME(C5:C35) (which is what I need)
I know it's not the answer to the exact problem mentioned above. But I thought it might help someone. And maybe serves as a hint to the original question.

Related

EPPlus How to add LineSeries with specific range of data from worksheet

I create an Excel file in code. So far, everything works out fine.
Created excel file (image)
I want to create the following chart in code
Excel with Chart (image)
(Notice the selected cells and xseries names)
In Excel its easy.
But how do I do that in code?
My experiment
string values = "='Overall Results'!B3;'Overall Results'!D3;'Overall Results'!F3;'Overall Results'!H3;'Overall Results'!J3";
string xSerie = "='Overall Results'!$B$1:$K$1";
linechart.Series.Add(values, xSerie);
didn't work.
You have to create a string with the EPPlus cell adresses.
string values = worksheet.Cells[3, 2].Address + ":" + worksheet.Cells[3, 4].Address + ":" + worksheet.Cells[3, 6].Address;
linechart.Series.Add(values, ExcelRange.GetAddress(1, 2, 1, 11));
Had this problem aswell, but i found a solution:
For some reason, in order to get multiple specific cells in EPPlus, every cell has to be in a range.
So creating multiple ranges, which each only contains 1 cell, is the way to go
string values = "sheetName!B3:sheetName!B3,sheetName!D3:sheetName!D3,sheetName!F3:sheetName!F3,sheetName!H3:sheetName!H3,sheetName!J3:sheetName!J3";
var valueCells = sheet.Cells[values];
string xSerie = (Same concept);
var xCells = sheet.Cells[xSerie];
linechart.Series.Add(valueCells, xCells);

how to calculate total Sum in Excel

I am producing last report for my venture. I need to ascertain the Sum of aggregate cells in my excel sheet. I have done the accompanying code. Be that as it may, its not computing the qualities.. Here is my code:
Worksheet.Cells[20, 16].Formula =
"Sum(" + Worksheet.Cells[6, 16].Value +
":" + Worksheet.Cells[rowIndex, 16].Value + ")";
I need to figure the Cell No 16's Sum esteem and I will show it into Cells[20,16]. Its not working. Anybody help me to settle this?
Change the two occurrences of .Value in your code to .Address.
Update
... and add a = before the Sum:
Worksheet.Cells[20, 16].Formula =
"=Sum(" + Worksheet.Cells[6, 16].Address +
":" + Worksheet.Cells[rowIndex, 16].Address + ")";

C# Excel Formatting Issue

I have an issue which I cannot solve. I'm writing some strings into Excel cells. But Excel is formatting them in a wrong way. These strings are IDs, for example 12A1, 12D1, 12E1 etc..
Everything works well except from the "12E1" string which is seen as an exponential. I tried with numberformat but it doesn't work.
For example the string "12E3" is written as 1.2e03, or 1200 and so on. i just want to see "12E3" written there. This program is going to be used by many PCs so i cannot change the Microsoft Excel General Settings for everyone!
Thank you and sorry for my poor english!
EDIT: Here's the code:
foreach (var Citem in ComQuery)
{
i++;
xlWorkSheet.Cells[i, 1] = "'" + Citem.commessaID; //the item is "12D3"
xlWorkSheet.Cells[i, 2] = Citem.commessaID; //the item is "12D3"
}
The first cell gives me the string "12D3" but with a warning on Excel, the second cell gives me 1.2E+004
xlWorkSheet.Cells[i, 2].NumberFormat = "#";
xlWorkSheet.Cells[i, 2] = Citem.commessaID;
You could do something like this:
var id = "12E1"
ws.Range("A1").Value = "'" + id
which will give your cell the following value:
'12E1

How to write long numbers as text with interop.excel

I am using interop.excel dll and creating an Excel file. I am having issues while writing long numbers as text.
Below is the code I am using. I can use apostrophe, but if you look in formula bar, you can see the cell is formatted.
Is there any other way of writing long numbers to an Excel spreadsheet without seeing the formatted value in the formula bar (using numberformat)?
worksheet.Cells[i, j] = "'" + dr[p];
//var startCell = (Excel.Range)worksheet.Cells[i, j];
//var endCell = (Excel.Range)worksheet.Cells[i, j];
//worksheetRange = worksheet.get_Range(startCell, endCell);
//worksheetRange.NumberFormat = "#####";
If you wanted to do it in one line, you could use the Text function.
Example:
worksheets.Cells[i, j] = "=Text(" + dr[p] + ", \"#\"";
But that probably isn't what you're looking for because this would store the number as a text and display the formula in the formula bar. In that case, like user194076 suggested, you could use .NumberFormat = "#";
or .NumberFormat = "#"; if you don't want it to show in scientific notation.
You can use NumberFormat with '#' or '#'
Example:
Range r= worksheet.Cells;
r.NumberFormat = "#";

Error on delimited

have problem with delimited on one PC but on mine is everything good.
I have WinXP but my friend Vista.
Here is the code:
string AccessKonekcija2 = null;
AccessKonekcija2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\exports_blaise2\\" + textBox22.Text + ".mdb";
System.Data.OleDb.OleDbConnection AccessExcelKonekcija = new System.Data.OleDb.OleDbConnection(AccessKonekcija2);
System.Data.OleDb.OleDbCommand AccessExcelKomanda = new System.Data.OleDb.OleDbCommand();
AccessExcelKomanda.Connection = AccessExcelKonekcija;
AccessExcelKomanda.CommandText = "SELECT * INTO[Text;HDR=Yes;FMT=Delimited;DATABASE=C:\\exports_blaise2\\zips\\manipulai\\" + value3 + "\\" + textBox22.Text + "\\OUT].[" + value3 + "man.txt] FROM " + value3 + "man";
AccessExcelKonekcija.Open(); AccessExcelKomanda.ExecuteNonQuery();
AccessExcelKonekcija.Close();
And the error is:
Can someone tell me whats wrong ?
And how come that I can do that w/o an error.
But my friend not.
I already checked regional setting they are both equal.
Check the Regional Settings in Control Panel: One of the things you can set is the list separation character. The error message sounds like this could be the case. Since Excel respects this setting for CSV files and your code mentions Excel somewhat... give it a try?
Make sure they match. Standard (US) is ,. Here in Switzerland, though, it is normally ; and this can lead to subtle errors like the one you're having...

Categories