title: Generated Excel with ClosedXML does not use the specified font/size during printing
body: <p>I am creating an offer generator for my company. The generated offer must contains the <code>General Conditions of Sale</code> in the second worksheet (the offer details are displayed in the first worksheet). The <code>General Conditions of Sale</code> are contained into a word document, so I have to inject them into the worksheet. Last constraint, I have to respect the word's two column layout.</p>
  
  <p>I already have the logic (it can be improved but that's not the point of my question) to extract and insert them into the worksheet. I am using a predefined excel file (with header, footer, column sizes, etc, already defined) and I simply insert the terms in the right merged cells, using <a href="https://github.com/ClosedXML/ClosedXML" rel="nofollow noreferrer">ClosedXml</a>. </p>
  
  <p>My issue concerns the printing of that offer. When I open the generated offer, directly click on <code>Print</code> and select <code>print the entire workbook</code>, I can then scrolldown in the preview to check if everything is good. When I arrive to the second worksheet, the font and/or the font size are not the ones I specified in the code.</p>
  
  <p>If I open the second worksheet at least once, and then do the former procedure, everything is back to normal and I can print my offer with the right font and font size. I encounter the same issue when I try to export the offer to pdf.</p>
  
  <p><a href="https://i.stack.imgur.com/i2tr0.png" rel="nofollow noreferrer">Here</a> is the preview when I do not open the second worksheet, with wrong font size. And <a href="https://i.stack.imgur.com/Takiu.png" rel="nofollow noreferrer">Here</a> is the preview if I open the second worksheet at least one before printing, with good font and font size.</p>
  
  <p>Here is my code (notice in the <code>PrintTerms</code> function the specification of the font and the size):</p>
  
  <pre><code>class Program
  {
      const int nbRowByPage = 67;
      const int nbCharByPage = 3650;
  
      const string generalTermsFileName = "ConditionsGeneralSales_R5.docx";
      const string baseTemplateFileName = "TemplateOffer.xlsx";
      const string generatedExcelFileName = "Offer.xlsx";
  
      static void Main(string[] args)
      {
          // Deletes any existing excel file
          var fi = new FileInfo(generatedExcelFileName);
          if (fi.Exists)
          {
              fi.Delete();
          }
  
          using (var workbookDocument = new XLWorkbook(baseTemplateFileName))
          {
              // Fills first worksheet
              // [..]
  
              // Gets the general terms from the word and injects them into the second worksheet
              using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(generalTermsFileName, true))
              {
                  // Extracts the paragraphs
                  var paragraphs = wordprocessingDocument.MainDocumentPart.Document.Body
                      .Descendants&lt;Paragraph&gt;()
                      .Where(p =&gt; !String.IsNullOrWhiteSpace(p.InnerText))
                      .ToList();
  
                  // Gets the second worksheet
                  var conditionsWS = workbookDocument.Worksheet(2);
  
                  // Injects the paragraphs in the worksheets
                  PrintTerms(conditionsWS, paragraphs);
              }
  
              // Saves the excel
              workbookDocument.SaveAs(generatedExcelFileName, true);
          }
  
          // Opens the generated excel with MS Excel
          Process.Start(generatedExcelFileName);
      }
  
      /// &lt;summary&gt;
      /// Adds the specified paragraph into the specified worksheet according this methodology:
      /// - Splits the paragraphs into two columns 
      /// - Fills the excel columns alternatively in order to looks like a two columns word text
      /// - Manage the break page
      /// &lt;/summary&gt;
      /// &lt;param name="ws"&gt;&lt;/param&gt;
      /// &lt;param name="generalTerms"&gt;&lt;/param&gt;
      static void PrintTerms(IXLWorksheet ws, List&lt;Paragraph&gt; generalTerms)
      {
          var currentParagraphIndex = 0;
          var index = 1;
  
          while (currentParagraphIndex &lt; generalTerms.Count)
          {
              var nbChar = 0;
              var currentParagraphs = generalTerms.Skip(currentParagraphIndex).TakeWhile(p =&gt; (nbChar += p.InnerText.Length) &lt; nbCharByPage).ToList();
  
              var row = ((int)Math.Ceiling(index / 2d) - 1) * nbRowByPage + 1;
              var column = index % 2 == 0 ? 3 : 1;
  
              var currentCell = ws.Cell(row, column);
              currentCell.Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Justify);
              currentCell.Style.Alignment.SetVertical(XLAlignmentVerticalValues.Top);
              currentCell.Style.Font.SetFontName("Arial");
              currentCell.Style.Font.SetFontSize(8);
  
              foreach (var paragraph in currentParagraphs)
              {
                  foreach (var run in paragraph.Descendants&lt;Run&gt;())
                  {
                      var text = currentCell.RichText.AddText(run.InnerText);
  
                      if (run.RunProperties.Bold != null)
                      {
                          text.SetBold();
                      }
  
                      if (run.RunProperties.Italic != null)
                      {
                          text.SetItalic();
                      }
  
                      if (run.RunProperties.Underline != null)
                      {
                          text.SetUnderline();
                      }
                  }
  
                  // Break line
                  currentCell.RichText.AddNewLine();
                  currentCell.RichText.AddNewLine();
              }
  
              ws.Range(row, column, row + nbRowByPage - 1, column).Merge();
  
              index++;
              currentParagraphIndex += currentParagraphs.Count();
          }
      }
  }
  </code></pre>
  
  <p>To run this code, you will need to put at the root of the console application the two following files: <a href="https://1drv.ms/w/s!ArmwPwH8RG7yuM4wWE2s_4PqY_53TA" rel="nofollow noreferrer">terms</a> and <a href="https://1drv.ms/x/s!ArmwPwH8RG7yuM4vNUdgXmf4deMjRg" rel="nofollow noreferrer">template</a> (check copy if newer in the files properties).</p>
  
  <p>I also tried a lot of combination like:</p>
  
  <p>Setting the workbook global style:</p>
  
  <pre><code>workbookDocument.Style
      .Font.SetFontName("Arial")
      .Font.SetFontSize(8);
  </code></pre>
  
  <p>Setting the worksheet style:</p>
  
  <pre><code>offerWS.Style
      .Font.SetFontName("Arial")
      .Font.SetFontSize(8);
  </code></pre>
  
  <p>Setting the cell's RichText style:</p>
  
  <pre><code>generalTermsCell.RichText
      .SetFontName("Arial")
      .SetFontSize(8);
  </code></pre>
  
  <p>All of this, at the begining or at the ending of the file modification. Nothing works.</p>
  
  <p>I don't think it is a bug into ClosedXML. Excel does not ask me for saving the changes when leaving the app if I had opened the second worksheet. So the generated files do not seem corrupted. It looks like an Excel bug, but may be there is a way in ClosedXML to workaround that?</p>