Number saved as text in excel


I have an automatism that takes data from different data sources, the problem is that there are some decimal data that I save as text.

How can I do so that I do not save these numbers as text?

This is what I have now

//Variables interop para excel, xlWorksheet es la hoja de excel.

String excel[100,100]; //Array bidimensional
/*     Mapeo el excel a la matriz     */
       //Aquí habría código

/* Relleno la matriz con datos String */
       //Aquí recogería información

/*     Mapeo la matriz al excel       */ <---- aquí empieza el problema
xlWorksheet.Cells[i, j] = Convert.ToDouble(excel[fila, columna]); <-- esto es String
Range r = (Range)xlWorksheet.Cells[fila, columna];
r.NumberFormat = "#0.00";

I've also tried with

r.NumberFormat = "#0,00";
asked by Aritzbn 12.04.2018 в 10:09

1 answer


What you should do is change the format of the cell (or column) in the Excel, doing something like the following:

First, in the cell you must enter the correct type of data:

xlWorksheet.Cells[i, j] = Convert.ToDouble(excel[i, j]);

And then, you can select the format type as in the following code:

Range r = (Excel.Range)worksheet.Cell[1,1];
r.NumberFormat = "#0.00";
// o para la columna completa
r.EntireColumn.NumberFormat = "#0.00";
answered by 12.04.2018 / 10:43