c# - 如何在excel中使字体大小变粗
问题描述
现在正在处理 ac# 桌面应用程序,并且在事务完成 Excel 中的事务导出后在此应用程序中工作,但我想将 excel 字体大小设置为粗体,我不知道该怎么做,请在这种情况下帮助我。
Thanks.
here is my code
//creating Excel Application
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
//creating new WorkBook within Excel application
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
//creating new Excelsheet in workbook
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
//see the excel sheet behind the program
app.Visible = true;
//get the reference of first sheet. By default its name is Sheet1.
//store its reference to worksheet
worksheet = workbook.Sheets["Sheet1"];
worksheet = workbook.ActiveSheet;
//changing the name of active sheet
worksheet.Name = "Exported from gridview";
//storing header part in Excel
//
worksheet.Cells[1, 1] = "Customer Name";
worksheet.Cells[1, 2] = "S/D/W";
worksheet.Cells[1, 3] = "NIC";
worksheet.Cells[1, 4] = "Postal Address";
worksheet.Cells[1, 5] = "Flat No";
worksheet.Cells[1, 6] = "Type";
worksheet.Cells[3, 1] = "Floor";
worksheet.Cells[3, 2] = "Block";
worksheet.Cells[3, 3] = "Size";
worksheet.Cells[3, 5] = "File No";
worksheet.Cells[3, 6] = "Nominee";
worksheet.Cells[5, 1] = "Relation";
worksheet.Cells[5, 2] = "nominee_NIC";
worksheet.Cells[5, 3] = "Contact_NIC";
worksheet.Cells[5, 4] = "Status";
worksheet.Cells[5, 5] = "Booking Station";
worksheet.Cells[5, 6] = "Booked By";
worksheet.Cells[7, 1] = "Cost";
worksheet.Cells[7, 2] = "Discount";
worksheet.Cells[7, 3] = "Total";
workbook.SaveAs("D:\\output.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
解决方案
worksheet.Cells[1, 1].Font.Bold = true;
应该做的工作
推荐阅读
- android - 如何使用工作管理器在 android 中运行定期工作请求
- asp.net-core - 如何将 AutoMapper.Collection 安装到 aspnet 样板 asp.net 核心项目中
- .net - WCF net.tcp 绑定:托管多个服务是否需要端口共享?
- react-native - 在 React Native 代码库中,生成声称的“单个 JSON 消息”的代码在哪里?
- c# - 从 WCF 客户端传播到 WCF 服务的事务的隔离是什么意思?
- java - 为什么 producer.send(record).get() 有效但 producer.send(record, callback) 无效
- c++ - 在 C++ 中使用类型名和模板
- javascript - 通过在同一表格行中查找图像从链接中获取文本
- java - Java MVC:如何在另一个类更改时正确设置更改的主模型类
- python - 如何检查数据框行名是否与列名匹配