How to show a title on each page of the report dynamically created reportviewer

こ雲淡風輕ζ 提交于 2019-12-10 18:52:35

问题


I create the report dynamically, i e, I have no way to open a designer RDLC and fix it. I create a table and fill it through the dataset. Getting XML file and export it to PDF file. But even if I write

string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>11in</PageWidth>" +
" <PageHeight>8.5.0in</PageHeight>" +
" <MarginTop>0.05in</MarginTop>" +
" <MarginLeft>0.05in</MarginLeft>" +
" <MarginRight>0.05in</MarginRight>" +
" <MarginBottom>0.05in</MarginBottom>" +

" <KeepWithGroup>After</KeepWithGroup>" +
" <RepeatOnNewPage>true</RepeatOnNewPage>" + 
" <FixedData>true</FixedData>"+
 " <RepeatHeaderOnNewPage>true</RepeatHeaderOnNewPage>" +
"</DeviceInfo>";
try
{
 byte[] bytes = reportViewer1.LocalReport.Render(
 "PDF", deviceInfo, out mimeType, out encoding, out filenameExtension,
 out streamids, out warnings);

 using (FileStream fs = new FileStream(filename, FileMode.Create))
 {
 fs.Write(bytes, 0, bytes.Length);
 fs.Close();
 }
 return filename;
 }
 //....

I see the title only on 1 page Help solve the problem! Thanks!


回答1:


    private Rdl.HeaderType CreateHeader()
    {
        Rdl.HeaderType header = new Rdl.HeaderType();
        header.Items = new object[]
            {
                CreateHeaderTableRows(),
                true,
            };
        header.ItemsElementName = new Rdl.ItemsChoiceType20[]
            {
                Rdl.ItemsChoiceType20.TableRows,
                Rdl.ItemsChoiceType20.RepeatOnNewPage,
            };
        return header;
    }
   //....
    public string ExportReport(string filename)
    {
        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string filenameExtension;
        string deviceInfo =
             "<DeviceInfo>" +
             " <OutputFormat>PDF</OutputFormat>" +
             " <PageWidth>11in</PageWidth>" +
             " <PageHeight>8.5.0in</PageHeight>" +
             " <MarginTop>0.05in</MarginTop>" +
             " <MarginLeft>0.05in</MarginLeft>" +
             " <MarginRight>0.05in</MarginRight>" +
             " <MarginBottom>0.05in</MarginBottom>" +
             "</DeviceInfo>"; 
        try
        {
            byte[] bytes = reportViewer1.LocalReport.Render(
                "PDF", deviceInfo, out mimeType, out encoding, out filenameExtension,                       out streamids, out warnings);
            using (FileStream fs = new FileStream(filename, FileMode.Create))
            {
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();
            }
            return filename;
        }
        catch (Exception e)
        {
            Program.WriteLogEx.WriterLogErr(e.Message);
            return "";
        }
    }


来源:https://stackoverflow.com/questions/10869315/how-to-show-a-title-on-each-page-of-the-report-dynamically-created-reportviewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!