Hello and thanks in advance for the help.
I have an SQL Query getting data on technicians and some work indicators from them into a DataTable. I have that working. I then run through the table getting the cell.Value for each cell and write them in an excel file, so far so good. Problem is I need to get the values in specific cells, depending on the name of the technicians (OPERADOR in the code) because they are divided into different teams.
- datatable has all the workers and info I need
- workers are divided into teams
- I need to export to the excel file, separating workers by team and putting them in the specific table in the file. (DataTable is ordered by alphabetical order so sorting it is not necessary).
Here is my code so far
string cellContent = string.Empty;
DataTable dt = dgv_CS24.DataSource as DataTable;
foreach (DataRow dRow in dt.Rows)
{
cellContent = dRow["OPERADOR"].ToString();
if (cellContent == "csalmeida" ||
cellContent == "bmferreira" ||
cellContent == "dleitao" ||
cellContent == "armauricio" ||
cellContent == "Psoares")
{
int i;
var tableRC = dgv_CS24.RowCount;
var tableCC = dgv_CS24.ColumnCount;
var size = 5;
var width = 1;
for (i = 0; i <= tableCC - 1; i++)
{
int j;
for (j = 0; j <= tableRC - 1; j++)
{
var cell = dgv_CS24[j, i];
xlWorkSheet.Cells[i + 6, j + 2] = cell.Value;
if (size == 5)
{
width++;
}
}
size++;
}
}
else if (cellContent == "cacaetano" ||
cellContent == "Cborralho" ||
cellContent == "Mfiães" ||
cellContent == "pcaraujo" ||
cellContent == "iacasimiro" ||
cellContent == "Rodrigues")
{
int i;
var tableRC = dgv_CS24.RowCount;
var tableCC = dgv_CS24.ColumnCount;
var size = 6;
var width = 1;
for (i = 0; i <= tableCC - 1; i++)
{
int j;
for (j = 0; j <= tableRC - 1; j++)
{
var cell = dgv_CS24[j, i];
xlWorkSheet.Cells[i + 15, j + 2] = cell.Value;
if (size == 6)
{
width++;
}
}
size++;
}
}
else if (cellContent == "Asalgueiro" ||
cellContent == "mltorres" ||
cellContent == "mrodrigues" ||
cellContent == "Ppimenta" ||
cellContent == "rjrosa" ||
cellContent == "Vnogueira")
{
int i;
var tableRC = dgv_CS24.RowCount;
var tableCC = dgv_CS24.ColumnCount;
var size = 6;
var width = 1;
for (i = 0; i <= tableCC - 1; i++)
{
int j;
for (j = 0; j <= tableRC - 1; j++)
{
var cell = dgv_CS24[j, i];
xlWorkSheet.Cells[i + 24, j + 2] = cell.Value;
if (size == 6)
{
width++;
}
}
size++;
}
}
else if (cellContent == "Ccarvalho" ||
cellContent == "falmeida" ||
cellContent == "maleal" ||
cellContent == "Mendes" ||
cellContent == "micaeiro" ||
cellContent == "Tantunes")
{
int i;
var tableRC = dgv_CS24.RowCount;
var tableCC = dgv_CS24.ColumnCount;
var size = 6;
var width = 1;
for (i = 0; i <= tableCC - 1; i++)
{
int j;
for (j = 0; j <= tableRC - 1; j++)
{
var cell = dgv_CS24[j, i];
xlWorkSheet.Cells[i + 33, j + 2] = cell.Value;
if (size == 6)
{
width++;
}
}
size++;
}
}
else if (cellContent == "Rpedro" ||
cellContent == "jcoutinho" ||
cellContent == "rjlope" ||
cellContent == "alopes" ||
cellContent == "Alacerda" ||
cellContent == "acurveira" ||
cellContent == "smteixeira" ||
cellContent == "mjmartins")
{
int i;
var tableRC = dgv_CS24.RowCount;
var tableCC = dgv_CS24.ColumnCount;
var size = 8;
var width = 1;
for (i = 0; i <= tableRC - 1; i++)
{
int j;
for (j = 0; j <= tableCC - 1; j++)
{
var cell = dgv_CS24[j, i];
xlWorkSheet.Cells[i + 42, j + 2] = cell.Value;
if (size == 8)
{
width++;
}
}
size++;
}
}
else if (cellContent == "cestrela")
{
int i;
var tableRC = dgv_CS24.RowCount;
var tableCC = dgv_CS24.ColumnCount;
var size = 1;
var width = 1;
for (i = 0; i <= tableCC - 1; i++)
{
int j;
for (j = 0; j <= tableRC - 1; j++)
{
var cell = dgv_CS24[j, i];
xlWorkSheet.Cells[i + 50, j + 2] = cell.Value;
if (size == 1)
{
width++;
}
}
size++;
}
}
else if (cellContent == "capestana" ||
cellContent == "etavares" ||
cellContent == "lmalanho" ||
cellContent == "nvital" ||
cellContent == "nherbert" ||
cellContent == "ppinto" ||
cellContent == "ppombal" ||
cellContent == "rpessoa")
{
int i;
var tableRC = dgv_CS24.RowCount;
var tableCC = dgv_CS24.ColumnCount;
var size = 8;
var width = 1;
for (i = 0; i <= tableCC - 1; i++)
{
int j;
for (j = 0; j <= tableRC - 1; j++)
{
var cell = dgv_CS24[j, i];
xlWorkSheet.Cells[i + 53, j + 2] = cell.Value;
if (size == 8)
{
width++;
}
}
size++;
}
}
and here is what that exports:
https://drive.google.com/file/d/0B6ziRKPZ22ZhaXFYWTBqQ3hpcEE/edit?usp=sharing[
^]