使用CSS和背景图像导出重复器 [英] Export Repeter with CSS and Background Images

查看:50
本文介绍了使用CSS和背景图像导出重复器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想在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.

推荐答案

我不知道你可以将转发器转换为excel的解决方案,但我只想告诉你如何在最近的项目中将转发器导出为ex​​cel ...



我的转发器在我的ItemTemplate中包含一个gridview,然后我循环遍历我的桌子并添加样式,因为我去...希望这会对你有帮助... < br $>


I don't know of a solution where you could just convert your repeater to excel but I just wanted to show you how I exported my repeater to excel in a recent project...

My repeater contains a gridview in my ItemTemplate then I just loop through my tables and add the styling as I go... Hope this will help 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和背景图像导出重复器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆