以编程方式在Excel中以C#更改字体(Trebuchet MS,Calibari) [英] Changing font (Trebuchet MS, Calibari) in Excel programmatically C#
本文介绍了以编程方式在Excel中以C#更改字体(Trebuchet MS,Calibari)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在C#应用程序中工作,该应用程序具有将生成excel文件的类.一切顺利. Excel工作表中填充的数据具有"Times New Roman"字体.我想将其更改为某些其他字体(Calibari).我该如何以编程方式做到这一点.
I am currently working in a C# application which has a class which will generate an excel file. Everything went smooth. The data populated on the excel sheet has 'Times New Roman' has font. I would like to change it to some other fonts (Calibari). How can I do that programmatically.
推荐答案
方法如下:
//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;
将焦点放在底部的第二行.设置了默认的字体类型,但是我想向您展示xlApp的来源,即使它是不言自明的.
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.
这篇关于以编程方式在Excel中以C#更改字体(Trebuchet MS,Calibari)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文