导出到Excel富文本框

时间:2015-07-21 07:36:50

标签: c# richtextbox export-to-excel

在c#中,富文本内容以下面的格式保存到数据库中 < B个你好< / B个。

我需要将其导出为MS Excel工作表 Hello (带粗体字母)

当我尝试在excel中导出内容时,它不会以富文本显示。请帮助我。谢谢,

           var workbook = new HSSFWorkbook();               
            var sheet = workbook.CreateSheet("");     
            int rowNumber = 1;              

            NPOI.SS.UserModel.IFont font = workbook.CreateFont();
            font.Boldweight = (short)(NPOI.SS.UserModel.FontBoldWeight.BOLD);
            font.FontHeight = 210;
            font.FontName = "Calibri";

            NPOI.SS.UserModel.ICellStyle headerCell = workbook.CreateCellStyle();
            headerCell.FillBackgroundColor = NPOI.SS.UserModel.IndexedColors.GREY_25_PERCENT.Index;
            headerCell.FillForegroundColor = NPOI.SS.UserModel.IndexedColors.GREY_25_PERCENT.Index;
            headerCell.FillPattern = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;
            headerCell.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;
            headerCell.WrapText = true;
            headerCell.SetFont(font);
            headerCell.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
            headerCell.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;
            headerCell.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;
            headerCell.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;
            NPOI.SS.UserModel.IFont fontShort = workbook.CreateFont();
            fontShort.Boldweight = (short)(NPOI.SS.UserModel.FontBoldWeight.NORMAL);
            fontShort.FontName = "Calibri";

            NPOI.SS.UserModel.ICellStyle normalCell = workbook.CreateCellStyle();
            normalCell.FillBackgroundColor = 50;
            normalCell.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;
            normalCell.WrapText = true;
            normalCell.SetFont(fontShort);
            normalCell.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
            normalCell.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;
            normalCell.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;
            normalCell.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;

            NPOI.SS.UserModel.ICellStyle emptyCell = workbook.CreateCellStyle();
            emptyCell.SetFont(font);
            emptyCell.BorderBottom = NPOI.SS.UserModel.BorderStyle.NONE;
            emptyCell.BorderLeft = NPOI.SS.UserModel.BorderStyle.NONE;
            emptyCell.BorderRight = NPOI.SS.UserModel.BorderStyle.NONE;
            emptyCell.BorderTop = NPOI.SS.UserModel.BorderStyle.NONE;
    var headerRow = sheet.CreateRow(0);
    var output ="<b>HelloWorld</b>"                          
            var row = sheet.CreateRow(rowNumber++);
            row.CreateCell(0).SetCellValue(output); 
            row.Cells[0].CellStyle = normalCell;

0 个答案:

没有答案
相关问题