locked
Local report line return appended problem RRS feed

  • Question

  • Hi,
    We have a rendering problem when rendering in Word format using a local report (calling Microsoft.Reporting.WinForms.LocalReport.Render). The problem occurs when the HTML markup type is specified inside a Textbox: an extra line return is appended to the text that’s displayed. This creates vertical alignment problems inside tables. When rendering PDF the problem does not occur.
    We also encountered this problem (but not in all cases) when remote processing on SQL Server 2008, but it does not seem to occur for remote processing on SQL Server 2008 R2. 
    Is there any way we can stop this rendering bug from occurring, without using remote processing? We would really prefer not to use remote processing  as we have everything already set up for local processing using object data sources;  it would mean significant work to expose the object data sources we’ve developed for our reports as web services. 
    Is there any way we could have the local report render to Word using the same Word rendering engine as used by Reporting Service 2008 R2 servers?
    I wondered which forum to post this to query to. I wondered about “SQL Server Reporting Services”, but decided to try “Visual Studio Report Controls”.  Please move this post if it isn’t in the correct forum.
    Instructions follow for a test case in VS 2010 which replicates the bug. 
    1. Create a new Reports Application project in VS 2010 (New Project, Installed Templates, Visual C#, Reporting)
    2. Cancel the wizard that’s launched, and delete all project files except Program.cs and Report1.rdlc.
    3. Replace the code in Program.cs with the C# code below.
    4. Replace the XML in Report1.rdlc with the report definition below.
    5. Run the project (Ctrl F5 for instance). The project will render the test case as a PDF and as a Word document. The box surrounding the text in the PDF document surrounds one line of text (correct) whereas in the Word document the box surrounds two lines (bug).
    Thanks for any help.
    Regards,
    Malcolm
    Code for Program.cs:
    using System;
    
    namespace ReportsApplication1
    {
        static class Program
        {
            [STAThread]
            static void Main()
            {
    			RenderWordBugTestCase("Word").CallWord();
    			RenderWordBugTestCase("PDF").CallAcrobat();
            }
    
    		public static byte[] RenderWordBugTestCase(string format)
    		{
    			var localReport = new Microsoft.Reporting.WinForms.LocalReport();
    			localReport.LoadReportDefinition(
    				System.Reflection.Assembly.GetExecutingAssembly()
    					.GetManifestResourceStream(@"ReportsApplication1.Report1.rdlc"));
    			localReport.Refresh();
    			string mimeType, encoding, fileNameExtension;
    			string[] streams;
    			Microsoft.Reporting.WinForms.Warning[] warnings;
    			return localReport.Render(format, null, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
    		}
        }
    
    	public static class Extensions {
    
    		internal static void CallWord(this byte[] bytes)
    		{
    			var path = System.IO.Path.Combine(
    				System.IO.Directory.GetCurrentDirectory(),
    				"test.doc");
    			System.IO.File.WriteAllBytes(path, bytes);
    			System.Diagnostics.Process.Start(path);
    		}
    
    
    		internal static void CallAcrobat(this byte[] bytes)
    		{
    			var path = System.IO.Path.Combine(
    				System.IO.Directory.GetCurrentDirectory(),
    				"test.pdf");
    			System.IO.File.WriteAllBytes(path, bytes);
    			System.Diagnostics.Process.Start(path);
    		}
    	}
    }
    


    Code for Report1.rdlc:
    <?xml version="1.0" encoding="utf-8"?>
    <Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">
      <DataSources>
        <DataSource Name="DataSource">
          <ConnectionProperties>
            <DataProvider>System.Data.DataSet</DataProvider>
            <ConnectString>/* Local Connection */</ConnectString>
          </ConnectionProperties>
          <rd:DataSourceID>7f8e1f00-1259-41b6-8dfe-f67780d426a1</rd:DataSourceID>
        </DataSource>
      </DataSources>
      <Body>
        <ReportItems>
          <Textbox Name="Textbox1">
            <CanGrow>true</CanGrow>
            <KeepTogether>true</KeepTogether>
            <Paragraphs>
              <Paragraph>
                <TextRuns>
                  <TextRun>
                    <Value>="&lt;span style=""font-weight:bold""&gt;test&lt;/span&gt; case"</Value>
                    <MarkupType>HTML</MarkupType>
                    <Style />
                  </TextRun>
                </TextRuns>
                <Style />
              </Paragraph>
            </Paragraphs>
            <rd:DefaultName>Textbox1</rd:DefaultName>
            <Top>3.3782cm</Top>
            <Left>4.3307cm</Left>
            <Height>0.6cm</Height>
            <Width>4.21979cm</Width>
            <Style>
              <Border>
                <Style>Solid</Style>
              </Border>
              <PaddingLeft>2pt</PaddingLeft>
              <PaddingRight>2pt</PaddingRight>
              <PaddingTop>2pt</PaddingTop>
              <PaddingBottom>2pt</PaddingBottom>
            </Style>
          </Textbox>
        </ReportItems>
        <Height>12.71677cm</Height>
        <Style />
      </Body>
      <Width>28.70005cm</Width>
      <Page>
        <PageHeight>21cm</PageHeight>
        <PageWidth>29.7cm</PageWidth>
        <LeftMargin>0.49cm</LeftMargin>
        <RightMargin>0.49cm</RightMargin>
        <TopMargin>0.5cm</TopMargin>
        <BottomMargin>0.2cm</BottomMargin>
        <ColumnSpacing>0.13cm</ColumnSpacing>
        <Style />
      </Page>
      <rd:ReportID>3a450608-e2cd-4f7d-bc6a-ac49da185843</rd:ReportID>
      <rd:ReportUnitType>Cm</rd:ReportUnitType>
    </Report>
    



    Don't code: play go instead.
    Monday, October 3, 2011 2:37 PM