Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Negrita y cursiva no funcionan en Excel con EPPLUS

Estoy usando el siguiente código para actualizar el formato de datos de Excel, aquí quiero que el encabezado esté en negrita y los datos completos en cursiva, pero cuando ejecuto el código, todas las funciones parecen estar funcionando bien, excepto Negrita y Cursiva. El código también completa la ejecución sin ningún error, pero en el archivo de Excel ninguna de las celdas tiene datos en formato de negrita o cursiva.

 public void FormatExcel() { string currentDate = DateTime.Now.ToString("yyyyMMdd"); FileInfo File = new FileInfo("G:\\Selenium\\Test66.xlsx"); using (ExcelPackage excel = new ExcelPackage(File)) { ExcelWorksheet worksheet = excel.Workbook.Worksheets[currentDate]; int totalRows = worksheet.Dimension.End.Row; int totalCols = worksheet.Dimension.End.Column; var headerCells = worksheet.Cells[1, 1, 1, totalCols]; var headerFont = headerCells.Style.Font; headerFont.Bold = true; headerFont.Italic = true; headerFont.SetFromFont(new Font("Times New Roman", 12)); headerFont.Color.SetColor(Color.DarkBlue); var headerFill = headerCells.Style.Fill; headerFill.PatternType = ExcelFillStyle.Solid; headerFill.BackgroundColor.SetColor(Color.Gray); var dataCells = worksheet.Cells[2, 1, totalRows, totalCols]; var dataFont = dataCells.Style.Font; dataFont.Italic = true; dataFont.SetFromFont(new Font("Times New Roman", 10)); dataFont.Color.SetColor(Color.DarkBlue); var dataFill = dataCells.Style.Fill; dataFill.PatternType = ExcelFillStyle.Solid; dataFill.BackgroundColor.SetColor(Color.Silver); var allCells = worksheet.Cells[1, 1, totalRows, totalCols]; allCells.AutoFitColumns(); allCells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; var border = allCells.Style.Border; border.Top.Style = border.Left.Style = border.Bottom.Style = border.Right.Style = ExcelBorderStyle.Thin; excel.Save(); } }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

El problema es que está configurando/sobrescribiendo la fuente después de configurar negrita/cursiva. Simplemente configure la fuente primero así:

 headerFont.SetFromFont(new Font("Times New Roman", 12)); //Do this first headerFont.Bold = true; headerFont.Italic = true;

o incluso puedes acortarlo un poco así:

 headerFont.SetFromFont(new Font("Times New Roman", 12, FontStyle.Italic | FontStyle.Bold));
over 4 years ago · Santiago Trujillo Report

0

headerFont.SetFromFont("Times New Roman", 16, verdadero);

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!