简体   繁体   中英

How to make font size bold in excel

Nowadays am working on a c# desktop application and in this application after a transaction completed that transaction export in excel but I want to make an excel font size bold I don't know how to do it please help me in this scenario.

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; should do the job

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM