0

I am already using interops to convert a Datable into a Excel file, everything is ok but when I try to insert in the excel a formula like this:

=(0,5*E30)

I have an error but if I try to insert another one like this:

=(0*E30)

everything it's ok. I am inserting it like a String. So what can be happening? I can't understand why only for use a , I get that error.

Excepción de HRESULT: 0x800A03EC</Message><StackTrace>   en Intranet.InteropExcel.DataTableToExcel(DataTable DataTable, String ExcelFilePath) en C:\Desarrollo\VisualStudio2010\ImeApps\Buscador\Intranet\ExportToExcel.cs:línea 301
   en Intranet.Intranet.butExcel_Click(Object sender, EventArgs e) en C:\Desarrollo\VisualStudio2010\ImeApps\Buscador\Intranet\Intranet.cs:línea 3306
   en System.Windows.Forms.Control.OnClick(EventArgs e)
   en System.Windows.Forms.Button.OnClick(EventArgs e)

So what can be happening? Thanks in advance!

GetData
  • 7
  • 4
  • This may help. https://stackoverflow.com/questions/7099770/hresult-0x800a03ec-on-worksheet-range – Steve Nov 20 '19 at 12:28
  • Pls share your code and show us where it fails. – Eldar Nov 20 '19 at 12:29
  • @Steve have not sense, how can be a limit if the project works with the formula =(0*E30) and not with =(0,5*E30) – GetData Nov 20 '19 at 12:37
  • @Eldar is simply, I'm just trying this Cells[j, i] = formulaCantidad; where formulaCantidad is a String like this =(0,5*E30) – GetData Nov 20 '19 at 12:49
  • 1
    I would think it was the comma, where it probably expects a full stop. The answer suggesting changing the culture may work. – Steve Nov 20 '19 at 13:14
  • @Steve yes, has to be the comma but if I need to use it, how can I put it into the formula? – GetData Nov 20 '19 at 14:16

1 Answers1

0

Try this :

Excel.Range rng = ActiveSheet.Cells[j, i] as Excel.Range;
rng.Formula = formulaCantidad;

The problem probably format provider. Try with value like this 0.5 Or set your number format by culture.

var cultureInfo = //get culture info local or named
rng.NumberFormat = cultureInfo.NumberFormat;
Eldar
  • 6,531
  • 2
  • 5
  • 25
  • Thank you @Eldar for your help. I am doing this: NumberFormatInfo nfi = new CultureInfo("es-ES",false).NumberFormat; Int64 myInt = -1234; System.Diagnostics.Debug.WriteLine(myInt.ToString("C",nfi)); nfi.CurrencyDecimalDigits = 4; Console.WriteLine(myInt.ToString("C", nfi)); And I get: -1.234,0000 € What this means? – GetData Nov 20 '19 at 14:44
  • "C" means currency, but as you can see "**,**" is the decimal separator for "es-ES" culture. if you want to specify it manually you can set it `nfi.NumberDecimalSeparator = ".";` – Eldar Nov 20 '19 at 17:52