コード例 #1
0
        public static void Crear(IRow fila, int columnaIndex, string value, ref ISheet sheet, HSSFWorkbook hssfworkbook)
        {
            //font style1: underlined, italic, red color, fontsize=20
            IFont font = hssfworkbook.CreateFont();

            font.Color              = HSSFColor.DarkBlue.Index;
            font.IsItalic           = true;
            font.Boldweight         = (short)FontBoldWeight.Bold;
            font.Underline          = FontUnderlineType.DoubleAccounting;
            font.FontHeightInPoints = 9;
            font.FontName           = "Abadi";


            ICellStyle estilo = hssfworkbook.CreateCellStyle();

            estilo.BorderBottom      = BorderStyle.Thin;
            estilo.BottomBorderColor = IndexedColors.Orange.Index;

            estilo.SetFont(font);

            //apply font styles
            ICell cell1 = CellUtil.CreateCell(fila, columnaIndex, value);

            cell1.CellStyle = estilo;


            sheet.AutoSizeColumn(columnaIndex);
        }
コード例 #2
0
ファイル: BuildExcel.cs プロジェクト: FindingData/FD.Util
        public void InsertText(string text, int row, int col)
        {
            IRow r = CellUtil.GetRow(row, currentSheet);

            if (r == null)
            {
                r = currentSheet.CreateRow(row);
            }
            ICell cell = CellUtil.CreateCell(r, col, text, CreateStyle());
        }
コード例 #3
0
        public void CreateCell()
        {
            IWorkbook wb  = _testDataProvider.CreateWorkbook();
            ISheet    sh  = wb.CreateSheet();
            IRow      row = sh.CreateRow(0);

            ICellStyle style = wb.CreateCellStyle();

            style.WrapText = (/*setter*/ true);

            // calling CreateCell on a non-existing cell should create a cell and Set the cell value and style.
            ICell F1 = CellUtil.CreateCell(row, 5, "Cell Value", style);

            Assert.AreSame(row.GetCell(5), F1);
            Assert.AreEqual("Cell Value", F1.StringCellValue);
            Assert.AreEqual(style, F1.CellStyle);
            // should be Assert.AreSame, but a new HSSFCellStyle is returned for each GetCellStyle() call.
            // HSSFCellStyle wraps an underlying style record, and the underlying
            // style record is the same between multiple GetCellStyle() calls.

            // calling CreateCell on an existing cell should return the existing cell and modify the cell value and style.
            ICell f1 = CellUtil.CreateCell(row, 5, "Overwritten cell value", null);

            Assert.AreSame(row.GetCell(5), f1);
            Assert.AreSame(F1, f1);
            Assert.AreEqual("Overwritten cell value", f1.StringCellValue);
            Assert.AreEqual("Overwritten cell value", F1.StringCellValue);
            Assert.AreEqual(style, f1.CellStyle, "cell style should be unChanged with CreateCell(..., null)");
            Assert.AreEqual(style, F1.CellStyle, "cell style should be unChanged with CreateCell(..., null)");

            // test CreateCell(row, column, value) (no CellStyle)
            f1 = CellUtil.CreateCell(row, 5, "Overwritten cell with default style");
            Assert.AreSame(F1, f1);

            wb.Close();
        }
コード例 #4
0
ファイル: HSSFCellUtil.cs プロジェクト: zzy092/npoi
 public static ICell CreateCell(IRow row, int column, String value, HSSFCellStyle style)
 {
     return((HSSFCell)CellUtil.CreateCell(row, column, value, style));
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: zxfgithub12/npoi
        static void Main(string[] args)
        {
            InitializeWorkbook();

            ISheet sheet1 = hssfworkbook.CreateSheet("Sheet1");

            //font style1: underlined, italic, red color, fontsize=20
            IFont font1 = hssfworkbook.CreateFont();

            font1.Color              = HSSFColor.Red.Index;
            font1.IsItalic           = true;
            font1.Underline          = FontUnderlineType.Double;
            font1.FontHeightInPoints = 20;

            //bind font with style 1
            ICellStyle style1 = hssfworkbook.CreateCellStyle();

            style1.SetFont(font1);

            //font style2: strikeout line, green color, fontsize=15, fontname='宋体'
            IFont font2 = hssfworkbook.CreateFont();

            font2.Color              = HSSFColor.OliveGreen.Index;
            font2.IsStrikeout        = true;
            font2.FontHeightInPoints = 15;
            font2.FontName           = "宋体";

            //bind font with style 2
            ICellStyle style2 = hssfworkbook.CreateCellStyle();

            style2.SetFont(font2);

            //apply font styles
            ICell cell1 = CellUtil.CreateCell(sheet1.CreateRow(1), 1, "Hello World!");

            cell1.CellStyle = style1;
            ICell cell2 = CellUtil.CreateCell(sheet1.CreateRow(3), 1, "早上好!");

            cell2.CellStyle = style2;

            //cell with rich text
            ICell cell3 = sheet1.CreateRow(5).CreateCell(1);
            HSSFRichTextString richtext = new HSSFRichTextString("Microsoft OfficeTM");

            //apply font to "Microsoft Office"
            IFont font4 = hssfworkbook.CreateFont();

            font4.FontHeightInPoints = 12;
            richtext.ApplyFont(0, 16, font4);
            //apply font to "TM"
            IFont font3 = hssfworkbook.CreateFont();

            font3.TypeOffset         = FontSuperScript.Super;
            font3.IsItalic           = true;
            font3.Color              = HSSFColor.Blue.Index;
            font3.FontHeightInPoints = 8;
            richtext.ApplyFont(16, 18, font3);

            cell3.SetCellValue(richtext);

            WriteToFile();
        }