Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi friends,

I am downloading gridview data in excel file my grid contains gridlines but after downloading excel file not displaying cell borders.

What I have tried:

I tried with

For each(Tablecell cell in gridview1.cell..)
{Cell.border style=color.black;
}
Like this
Posted
Updated 28-Nov-16 7:52am
Comments
[no name] 24-Nov-16 21:51pm    
Show the code where you are setting the cell border in your excel file.
prasanna204 24-Nov-16 22:28pm    
if (grdMaterials.Rows.Count > 0)
{
Response.Clear();
Response.Buffer = true;
if (txtDate.Text == "")
{
Response.AddHeader("content-disposition", "attachment;filename=ApprovedMaterialsData.xls");
}
else
{
Response.AddHeader("content-disposition", "attachment;filename=ApprovedMaterialsData_"+txtDate.Text+".xls");
}

Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

//To Export all pages
grdMaterials.AllowPaging = false;

GetData();

grdMaterials.HeaderRow.BackColor = Color.White;
foreach (TableCell cell in grdMaterials.HeaderRow.Cells)
{
cell.BackColor = grdMaterials.HeaderStyle.BackColor;
}
foreach (GridViewRow row in grdMaterials.Rows)
{
//row.BackColor = Color.White;

foreach (TableCell cell in row.Cells)
{
if (row.RowIndex % 2 == 0)
{
cell.BackColor = grdMaterials.AlternatingRowStyle.BackColor;
cell.BorderColor = Color.Black;
cell.BorderStyle = grdMaterials.BorderStyle;

//Range cell1 = worksheet.Cells[row1, col1];
//Range cell2 = worksheet.Cells[row2, col2];
//Range range = worksheet.get_Range(cell1, cell2);
//range.BorderAround(
// Type.Missing, XlBorderWeight.xlThick, (XlColorIndex)color, Type.Missing);
//((Range)excelSheet.get_Range(exRange)).Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
}
else
{
cell.BackColor = grdMaterials.RowStyle.BackColor;
// ((Range)excelSheet.get_Range(exRange)).Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
}
cell.CssClass = "textmode";
}
}

grdMaterials.RenderControl(hw);

//style to format numbers to string
string style = @" .textmode { } ";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
StackQ 25-Nov-16 4:44am    
check google or check my similar question link:-
http://www.codeproject.com/Questions/450479/Export-to-multiple-sheet

1 solution

My guess is that you're setting the border style AFTER you've set the border itself.

C#
foreach (TableCell cell in row.Cells)
{
    cell.BorderStyle = grdMaterials.BorderStyle; // <--- moved this line out of the following if condition
    if (row.RowIndex % 2 == 0)
    {
        cell.BackColor = grdMaterials.AlternatingRowStyle.BackColor;
        cell.BorderColor = Color.Black;
        // cell.BorderStyle = grdMaterials.BorderStyle;
    }
    else
    {
       cell.BackColor = grdMaterials.RowStyle.BackColor;
    }
    cell.CssClass = "textmode";
}
 
Share this answer
 
v2

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