Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends
I want to develop codes in C#. I have an excel file consist of ten rows and three column. I have to develop Random number and I will multiply that random numbers with the each row in excel file.
So, In order to do this:
How I will call excel file and access to the each row and column and then multiply with the random numbers.
To explain this more consider
C = ax + by +z:
where (a, b) are the random numbers (this is also an array of 100 rows and 2 column) generated in the C# and x, y, z is the experimental data saved in excel file. I have to access to the excel file and multiply the first row (a, b) with the first row in excel (x, y , z) to calculate C and similarly through all rows using for or while loop in C#.
How to program this code.
I expect full co-operation from you all.
Thank you very much
Ilyas

Edit:
Hello Thanks I have generated Random Like in the codes below
C#
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace RandomNumber 
{ 

    class Program 
    { 
          static void Main(string[] args) 
          { 
             Double[,] randdouble = new Double[100, 2]; 
             Random randNum = new Random(); 

             for (int row = 0; row < randdouble.GetLength(0); row++) 
             { 
                   for (int col = 0; col < randdouble.GetLength(1); col++) 
                   { 
                        Double x = randNum.NextDouble(); 
                        randdouble[row, col] = x; 
                        Console.Write(randdouble[row, col]); 
                        Console.Write(" ");
                   } 
                   Console.WriteLine(); 
             } 
          } 
    } 
}

But how to proceed next is the main hurdle in my codes development. Thanks
Posted
Updated 14-Apr-13 19:06pm
v3

1 solution

I dont know about your random number, as one could easily solve it by using the Random class.

The excel file could be read like the documentation here specifies, where most instances are covered:
http://support.microsoft.com/kb/302084[^]

It is advicable to use a array instead though, and I have done this here in VB:
Sound in games - Rooms[^]
 
Share this answer
 
Comments
Member 9958867 15-Apr-13 1:00am    
Hello Thanks
I have generated Random Like in the codes below
sing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RandomNumber
{
class Program
{
static void Main(string[] args)
{

Double[,] randdouble = new Double[100, 2];
Random randNum = new Random();
for (int row = 0; row < randdouble.GetLength(0); row++)
{
for (int col = 0; col < randdouble.GetLength(1); col++)
{
Double x = randNum.NextDouble();

randdouble[row, col] = x;

Console.Write(randdouble[row, col]);
Console.Write(" ");
}
Console.WriteLine();
}
}
}
}

But how to proceed next is the main hurdle in my codes development.
Thanks
Member 9958867 15-Apr-13 1:27am    
Hello Kenneth Haugland
Thanks for your response, but I want to read each rows and column of Excel . The subject codes which you have sent is writing in Excel.
Thank you very much for your co-operation
Ilyas

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900