Hello everyone,
I'm working on a project and trying to solve same problem on last 2 weeks !
I accepted, i can't solve and need some help from you.
Basically i have a datagrid and an excel file. They have different values.
In excel i have some columns like "report_no_1" or "report_no_1_1" etc. Under this colums some measurements will come from my datagrid.
My datagrid is basically same, just i have 2 columns : Report No and Measurement
I edited report no for get just first number from the string. So i have 2 for report_no_2 or report_no_2_12
Sample Excel Template :
Report_No_1 | Report_no_2_1 | Report_no_2_2 |Report_no_3 | etc.....
Datagrid template :
2 | 21,3
2 | 22,4
3 | 12,1
5 | 11,1
etc.
Thing is very simple. I want to get first number in string from excel cell and compare with my datagrid number for every data in datagrid. If they are equel than need to write measurement to excel file under the report no.
I'm comparing them cause there is some empty space. For example there isn't a 4 value in the datagrid. So i need to check.
Here is my code. If there is just one empty space ( for example there isn't a 4 value in data grid then i need to give an empty space to excel ) it doesn't work first time.
When i checked it seems equal.And just one line later i'm trying to write excel. It wrote to previous column.
Please help me.
akademi is my first column index on excel.
int akademi = 5;
raporBos++;
int toplamStr = dataGridView1.Rows.Count;
for (int i = 0; i < toplamStr-1; i++)
{
int nope = Int32.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString());
double olcumi = double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
int abc = 0;
int cag;
int gac;
if (!String.IsNullOrEmpty(raporAralik.Cells[raporBasSatZ, akademi].Value))
{
string[] cagF = (raporAralik.Cells[raporBasSatZ, akademi].Value.ToString().Substring(8)).Split('_');
cag = Int32.Parse(cagF[1]);
gac = Int32.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString());
Debug.WriteLine(gac + " gac || " + cag + " cag");
int osman = gac - cag;
while (cag < gac)
{
Debug.WriteLine("*** "+gac + " gac || " + cag + " cag");
akademi++;
if (!String.IsNullOrEmpty(raporAralik.Cells[raporBasSatZ, akademi].Value))
{
string[] cagG = (raporAralik.Cells[raporBasSatZ, akademi].Value.ToString().Substring(8)).Split('_');
cag = Int32.Parse(cagG[1]);
}
abc++;
if (abc == 100)
{
break;
}
}
raporWrkS.Cells[raporBos, akademi] = Math.Round(olcumi, 3);
akademi++;
}
else
{
break;
}
}
What I have tried:
while loop, if statement, for loop