2

特定のセルでテキストを太字にしようとしていますが、できません。これは私が使用しているコードです:

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

2 に答える 2

6
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");
于 2015-05-19T15:00:58.757 に答える
1

以下のコードを試してください。

  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");
于 2015-05-15T20:21:37.097 に答える