我有一个网格,我必须导出到pdf。我通过使用aspxgridviewexporter和printinsystem完成了这个。一切都很好。 pdf中网格的标题单元格的颜色具有灰色背景颜色,我想要更改。
这是我的代码:
PrintingSystem ps = new PrintingSystem();
PrintableComponentLink link1 = new PrintableComponentLink(ps);
GridViewExporter.GridView.Styles.Header.BackColor = Color.Blue;//This line didn't change the color.
link1.Component = GridViewExporter;
PrintableComponentLink link2 = new PrintableComponentLink(ps);
link2.Component = ((IChartContainer)ChartId).Chart;
// export column header
Link reportTitle = new Link();
reportTitle.CreateDetailArea +=
new CreateAreaEventHandler(reportTitle_CreateDetailArea);
Link chartTitle = new Link();
chartTitle.CreateDetailArea +=
new CreateAreaEventHandler(chartTitle_CreateDetailArea);
CompositeLink compositeLink = new CompositeLink(ps);
compositeLink.Links.AddRange(new object[] { reportTitle, link1, chartTitle, link2 });
//compositeLink.Links.Add(link1);
compositeLink.CreateDocument(false);
link1.PrintingSystem.Document.AutoFitToPagesWidth = 1;
link1.Landscape = false;
using (MemoryStream stream = new MemoryStream())
{
compositeLink.PrintingSystem.ExportToPdf(stream);
Response.Clear();
Response.Buffer = false;
Response.AppendHeader("Content-Type", "application/pdf");
Response.AppendHeader("Content-Transfer-Encoding", "binary");
Response.AppendHeader("Content-Disposition", "attachment; filename=Report.pdf");
Response.BinaryWrite(stream.ToArray());
Response.End();
}
ps.Dispose();
我在这里用过
GridViewExporter.GridView.Styles.Header.BackColor = Color.Blue;
将标题颜色更改为蓝色。但我看到相同的灰色。
请帮忙。
答案 0 :(得分:1)
尝试访问上面的链接,看看它是否能解决您的问题。希望这可以帮助! :)
答案 1 :(得分:1)
您应该使用RenderBrick事件处理程序来处理necessery列的renderig样式。请看下面的例子
<dx:ASPxGridViewExporter ID="_gridViewExporter" runat="server" GridViewID="_gridView"
Landscape="True" PaperKind="A4" OnRenderBrick="OnRenderGridViewBrick" />
protected void OnRenderGridViewBrick(object sender, ASPxGridViewExportRenderingEventArgs e)
{
if (e.RowType == GridViewRowType.Data)
{
var column = e.Column as GridViewEditDataColumn;
if (column != null)
{
switch (column.FieldName)
{
case Constants.FieldName_Semaphore:
e.BrickStyle.BackColor = Color.Black;
break;
}
}
}
}