using (ExcelRange rng = ws.Cells[cellRange]) { rng.Style.WrapText = true; rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; rng.Style.Font.Bold = false; rng.Style.Fill.PatternType = ExcelFillStyle.Solid; //Set Pattern for the background to Solid rng.Style.Fill.BackgroundColor.SetColor(Color.Silver); ws.Row(1).Height = 30; rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; rng.Style.VerticalAlignment = ExcelVerticalAlignment.Center; rng.Style.Font.Color.SetColor(Color.Black); } //prepare the range for the rows string rowsCellRange = "A2:" + Convert.ToChar('A' + dtResult.Columns.Count - 1) + dtResult.Rows.Count * dtResult.Columns.Count; //Format the rows using (ExcelRange rng = ws.Cells[rowsCellRange]) { rng.Style.WrapText = true; rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; } //foreach (DataColumn dc in dtResult.Columns) //Creating Headings //{ // var cell = ws.Cells[rowIndex, colIndex]; // //Setting the background color of header cells to Gray // var fill = cell.Style.Fill; // var vallign = cell.Style.VerticalAlignment; // var hallign = cell.Style.HorizontalAlignment; // fill.PatternType = ExcelFillStyle.Solid; // cell.Style.VerticalAlignment = ExcelVerticalAlignment.Center; // cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // cell.Style.Fill.BackgroundColor.SetColor(Color.Silver); // ws.Row(1).Height = 30; // //Setting Top/left,right/bottom borders. // var border = cell.Style.Border; // border.Bottom.Style = // border.Top.Style = // border.Left.Style = // border.Right.Style = ExcelBorderStyle.Thin; // //Setting Value in cell // cell.Value = dc.ColumnName; // colIndex++; //} //foreach (DataRow dr in dtResult.Rows) // Adding Data into rows //{ // colIndex = 1; // rowIndex++; // foreach (DataColumn dc in dtResult.Columns) // { // var cell = ws.Cells[rowIndex, colIndex]; // //Setting Value in cell // cell.Value = (dr[dc.ColumnName]); // //Setting borders of cell // var border = cell.Style.Border; // border.Left.Style = // border.Right.Style = ExcelBorderStyle.Thin; // colIndex++; // } //} //colIndex = 0; Byte[] bin = pck.GetAsByteArray();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)