如何格式化Aspose中的单元格

时间:2015-05-15 19:02:23

标签: c# aspose aspose-cells

我试图在一个特定的单元格中制作一段粗体但不能。 这是我正在使用的代码:

  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);

2 个答案:

答案 0 :(得分:5)

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");

答案 1 :(得分:0)

尝试以下代码,

  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");