Writing a string, numeric data in Excel using C # works, but Excel does not process numeric data correctly

I get result sets from Sybase that I return to the C # client.

I use the following function to write result set data in Excel:

private static void WriteData(Excel.Worksheet worksheet, string cellRef, ref string[,] data)
{
     Excel.Range range = worksheet.get_Range(cellRef, Missing.Value);

     if (data.GetLength(0) != 0)
     {
         range = range.get_Resize(data.GetLength(0), data.GetLength(1));

         range.set_Value(Missing.Value, data);
     }
}

Data is being written correctly.

The problem is that since I use a string array to write data (which is a mixture of strings and floats), Excel selects every cell that contains numeric data with the message "The number is stored as text."

How can I get rid of this problem?

Thanks a lot Chapax

+3
source share
2 answers

: .

var data = new object[2,2];
data[0, 0] = "A";
data[0, 1] = 1.2;
data[1, 0] = null;
data[1, 1] = "B";

var theRange = theSheet.get_Range("D4", "E5");
theRange.Value2 = data;

, :

var data = new string[2,2];

, . : , .

+3

NumberFormat .

0

Source: https://habr.com/ru/post/1738845/


All Articles