Changing font (Trebuchet MS, Calibari) in Excel programmatically C#
From what I tried, simply changing font name, size etc... on range changes font for that range:
range.Font.Name = "Arial"
range.Font.Size = 10
range.Font.Bold = true
Here is how:
//Declare Excel Interop variables
Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
//Initialize variables
xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//Set global attributes
xlApp.StandardFont = "Arial Narrow";
xlApp.StandardFontSize = 10;
Focus on the 2nd line from the bottom. That sets the default font type, but I wanted to show you where xlApp came from, even if it's self explanatory.
the following worked for me, when I tried setting the default application font it did nothing so I was able to set the font name of the active sheet rows and it worked. Also worth noting I used and tested this using Excel Interop version 12
Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
//Create\Add workbook object
Excel.Workbooks workBooks = excelApp.Workbooks;
//Excel.Workbook
Excel.Workbook workBook = workBooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
//use worksheet object
Excel.Worksheet workSheet = (Excel.Worksheet)excelApp.ActiveSheet;
//set default font
workSheet.Rows.Font.Name = "Arial";