My code is here:
private void btnExcel_Click(object sender, EventArgs e)
{
// create excel sheet
Worksheet.Cells[1, 1] = "Name";
Worksheet.Cells[1, 2] = "Date";
Worksheet.Cells[1, 3] = "Task Name";
Worksheet.Cells[1, 4] = "Time";
for(int i=0; i
{
//Connection to the database and retriving data from the databse
if (datardr.HasRows)
{
int j = 1;
while (datardr.Read())
{
Worksheet.Cells[j + 1, 2] = datardr[0].ToString();
Worksheet.Cells[j + 1, 3] = datardr[1].ToString();
Worksheet.Cells[j + 1, 4] = datardr[2].ToString();
j = j + 1;
}
}
datardr.Close();
con.Close();
}
In cmbName (Combo box has 11 names).
My problem is:
I want to show data in the excel like the following:
I have problem in looping.
Thanks!!
Darma
In cmbName (Combo box has 11 names).
My problem is:
I want to show data in the excel like the following:
| Name | Date | Task Name | Time |
| xyz | 11.07.2012 | sjhgg | 2 |
| 12.07.2012 | sgdfgfd | 3 | |
| 13.07.2012 | sgdfgfd1 | 3 | |
| 14.07.2012 | sgdfgfd2 | 4 | |
| abc | 11.07.2012 | rfgdf | 5 |
| 12.07.2012 | fdhdfh | 6 | |
| 13.07.2012 | dfhdfh | 7 | |
| 14.07.2012 | fdhdh | 8 | |
I have problem in looping.
Thanks!!
Darma
5 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Nov 21, 2012, 3:24 PM
darma tejaPosted Nov 22, 2012, 9:55 AM
VulpesPosted Nov 22, 2012, 6:21 AM
Color[] colors = new Color[11]
{
Color.Black,
Color.Red,
Color.Yellow,
Color.Blue
// plus 7 others
};
You can then do:
while (datardr.Read())
{
if (j == k)
{
Worksheet.Cells[j + 1, 1] = cmbName.Items[i].ToString();
Worksheet.Cells[j + 1, 1].Interior.Color = Color.Green;
}
Worksheet.Cells[j + 1, 2] = datardr[0].ToString();
Worksheet.Cells[j + 1, 3] = datardr[1].ToString();
Worksheet.Cells[j + 1, 4] = datardr[2].ToString();
for(int c = 2; c <= 4; c++) WorkSheet.Cells[j + 1, c].Interior.Color = colors[i];
j = j + 1;
}
darma tejaPosted Nov 22, 2012, 4:42 AM
I wanted to show every person data in different colors.
I tried like this:
Worksheet.Cells[j + 1, 1].Interior.Color = Color.Geen; // I wanted to show name column with
// For the following data I wanted to one unique color to Name
Worksheet.Cells[j + 1, 2].Interior.Color = Color.Yellow;
Worksheet.Cells[j + 1, 3].Interior.Color = Color.Yellow;
Worksheet.Cells[j + 1, 4].Interior.Color = Color.Yellow;
Darma
darma tejaPosted Nov 22, 2012, 4:11 AM