简体   繁体   English

如何在Aspose中格式化单元格

[英]How to format cells in Aspose

I am trying to make a piece of text bold at a particular cell but not able to. 我试图在特定单元格上使文本变粗体,但不能。 This is the code I am using: 这是我正在使用的代码:

  Style boldStyle = workBook.CreateStyle();
           boldStyle.BackgroundColor = Color.Red;
            StyleFlag boldStyleFlag = new StyleFlag();
            boldStyleFlag.HorizontalAlignment =true ;
            boldStyleFlag.FontBold = true;
            Cell c = workSheetIntroduction.Cells["B1"];
            c.SetStyle(boldStyle, boldStyleFlag);
Workbook workBook = new Workbook();

Worksheet workSheetIntroduction = workBook.Worksheets[0];


//This Style object will make the fill color Red and font Bold

Style boldStyle = workBook.CreateStyle();

boldStyle.ForegroundColor = Color.Red;

boldStyle.Pattern = BackgroundType.Solid;

boldStyle.Font.IsBold = true;


//Bold style flag options

StyleFlag boldStyleFlag = new StyleFlag();

boldStyleFlag.HorizontalAlignment = true;

boldStyleFlag.FontBold = true;


//Apply this style to row 1

Row row1 = workBook.Worksheets[0].Cells.Rows[0];

row1.ApplyStyle(boldStyle, boldStyleFlag);



//Now set the style of indvidual cell

Cell c = workSheetIntroduction.Cells["B1"];


Style s = c.GetStyle();

s.ForegroundColor = Color.Red;

s.Pattern = BackgroundType.Solid;

s.Font.IsBold = true;

c.SetStyle(s);


//Save the workbook

workBook.Save("output.xlsx");

Try below code, 试试下面的代码,

  Workbook workbook = new Workbook("F:\\test.xlsx");
        Worksheet s = workbook.Worksheets.First();
        Cell c = s.Cells.FirstCell;
        if (c != null)
        {
            Style st = c.GetStyle();
            st.Font.IsBold = true;
            c.SetStyle(st);
        }

        workbook.Save("F:\\test1.xlsx");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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