本文介绍了使用CSS和背景图像导出重复器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想在excel中导出Repeater控件,因为它正在查看aspx页面,意味着CSS和背景图像以及相同的格式。 我有些人尽快得到同样的回复。 感谢大家。Hi,I want to export Repeater control in excel as it is looking in aspx pages, means with CSS and background images and same formatting.I some one know the same kindly reply ASAP.Thanks to all of you.推荐答案List<DataTable> data = GetMyTables(); using (ExcelPackage pck = new ExcelPackage()) { ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Sessions"); int CurrentRow = 1; foreach (DataTable dt in data) { ExcelRange rand = ws.Cells[CurrentRow, 1, CurrentRow, dt.Columns.Count]; rand.Merge = true; ws.Cells["A" + CurrentRow.ToString()].Value = dt.TableName; ws.Cells["A" + CurrentRow.ToString()].Style.Font.Bold = true; CurrentRow += 2; ws.Cells["A" + CurrentRow].LoadFromDataTable(dt, true); using (ExcelRange range = ws.Cells[CurrentRow, 1, CurrentRow, dt.Columns.Count]) { range.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml("#498af3")); range.Style.Font.Color.SetColor(Color.White); } using (ExcelRange range = ws.Cells[CurrentRow, 1, CurrentRow + dt.Rows.Count, dt.Columns.Count]) { range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; } CurrentRow += dt.Rows.Count + 2; } ws.Cells[1, 1, CurrentRow - 1, data[0].Columns.Count].AutoFitColumns(); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment; filename=file.xlsx"); Response.BinaryWrite(pck.GetAsByteArray()); Response.End(); } 这篇关于使用CSS和背景图像导出重复器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 13:16