Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default font for RDLC report

Is it possible to set default font in RDLC report ? I have report where i want to change font by I don't want to change it in every element of the report.

like image 259
MichaelT Avatar asked Oct 10 '12 08:10

MichaelT


People also ask

What is Rdlc format?

What is an RDLC file? The RDLC stands for Report Definition Language Client side. Actually It is an extension of report file created by using Microsoft reporting technology. The SQL Server 2005 version of Report Designer is used to create these files.

How do I change font size in Rdlc?

First go to report designing and Right Click on field you want to change the font size. Then click on TextBox Properties will open textbox property window and click on Font tab after that click on Size expression(fx). The expression window will be open there you have write the expression.

How do Rdlc reports work?

Drag the dataset field on the Table. To add Report Viewer in the WPF application, select ReportViewer under Reporting. Set the ReportPath and the ProcessingMode as local in the Report Viewer. Set the DataSource information in the code to view the report in the Report Viewer.


2 Answers

There isn't a way to change the font used for the entire report using the design interface. However if you are trying to replace one font with another, e.g. Tahoma with Verdana, then you can open the code view (View > Code) and do a Find and Replace there.

Note that Arial is the default font for Reporting Services reports and therefore the font is only defined in the code for fonts other than Arial. If you need to change from Arial to another font you will have to do this manually in the designer.

like image 51
Nathan Griffiths Avatar answered Oct 20 '22 15:10

Nathan Griffiths


There is a way to do this. It's actually fairly simple. Backup your rdl file before starting. This answer requires a simple app to be written:

Open the rdl as an XML document. Find all TextRun nodes. Look for a Style node in each. If no Style node is found, add one with a FontFamily node inside with the desired font specified. If the Style node is found, look for the FontFamily node. If it is found you can either leave it alone or replace the value with the desired font, depending on your requirement. If there is no FontFamily node, add it with the specified font.

ETA: I have the code and it works fabulously for me. Just note this is destructive, ie. your file will be overwritten.

pivate static void AddFontsToRdlc(string fileName, string defaultFont)
{
  if (!File.Exists(fileName))
  {
    // Report file does not exist
    return;
  }
  XmlDocument document = new XmlDocument();
  document.Load(fileName);
  string documentNamespace = document.DocumentElement.NamespaceURI;
  XmlNodeList nodes = document.GetElementsByTagName("TextRun");
  bool foundStyle = false;
  bool foundFontFamily = false;
  foreach (XmlNode node in nodes)
  {
    foundStyle = false;
    foundFontFamily = false;
    foreach (XmlNode childNode in node.ChildNodes)
    {
      if (childNode.Name == "Style")
      {
        foundStyle = true;
        foreach (XmlNode styleNode in childNode.ChildNodes)
        {
          if (styleNode.Name == "FontFamily")
          {
            // Change the font here if changing all fonts to the default font
            // Alternatively, specify what font should change to what font with a switch
            foundFontFamily = true;
            break;
          }
        }
        if (!foundFontFamily)
        {
          XmlElement fontElement = document.CreateElement("FontFamily", documentNamespace);
          fontElement.InnerText = defaultFont;
          childNode.AppendChild(fontElement);
        }
        break;
      }
    }
    if (!foundStyle)
    {
      XmlNode styleElement = document.CreateElement("Style", documentNamespace);
      XmlElement fontElement = document.CreateElement("FontFamily", documentNamespace);
      fontElement.InnerText = defaultFont;
      styleElement.AppendChild(fontElement);
      node.AppendChild(styleElement);
    }
  }
  document.Save(fileName);
}
like image 5
Marc K Avatar answered Oct 20 '22 15:10

Marc K