如何在 excel 中使字体大小加粗
How to make font size bold in excel
现在我正在开发一个 c# 桌面应用程序,在这个应用程序中,在 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;
应该能胜任
现在我正在开发一个 c# 桌面应用程序,在这个应用程序中,在 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;
应该能胜任