/// <summary>
        /// 处理表头
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="workbookBytes">工作簿流</param>
        /// <param name="options">导出选项配置</param>
        /// <param name="context">装饰器上下文</param>
        public byte[] HandleHeader <T>(byte[] workbookBytes, IExportOptions <T> options, IDecoratorContext context) where T : class, new()
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var attribute =
                context.TypeDecoratorInfo?.TypeDecorators?.SingleOrDefault(x => x.GetType() == typeof(HeaderAttribute))
                as HeaderAttribute;

            if (attribute == null)
            {
                return(workbookBytes);
            }
            var workbook  = workbookBytes.ToWorkbook();
            var headerRow = workbook?.GetSheet(options.SheetName)?.GetRow(options.HeaderRowIndex);

            if (headerRow == null)
            {
                return(workbookBytes);
            }
            var style = workbook.CreateCellStyle();
            var font  = workbook.CreateFont();

            font.FontName           = attribute.FontName;
            font.Color              = ColorResolver.Resolve(attribute.Color);
            font.FontHeightInPoints = attribute.FontSize;
            font.IsBold             = attribute.Bold;
            style.SetFont(font);
            for (var i = 0; i < headerRow.PhysicalNumberOfCells; i++)
            {
                headerRow.GetCell(i).CellStyle = style;
            }
            return(workbook.SaveToBuffer());
        }
Exemplo n.º 2
0
        /// <summary>
        /// ぉに変換
        /// </summary>
        /// <param name="index">色</param>
        /// <returns>ぉ</returns>
        public ぉ Toぉ(int index = -1)
        {
            if (index != -1)
            {
                var c = ColorResolver.Lookup(colors[index].Format, colors[index].Color);
                if (null == c)
                {
                    throw new およよ($"色解決失敗: {colors[0].Color}");
                }
                return(c);
            }
            index = ConvertedIndex;
            if (colors[index].Converted)
            {
                return(colors[index].ConvertedColor);
            }

            for (int i = 0; i < colors.Length; ++i)
            {
                if (colors[i].Converted)
                {
                    return(colors[i].ConvertedColor);
                }
                var k = ColorResolver.Lookup(colors[i].Format, colors[i].Color);
                if (null != k)
                {
                    colors[i].ConvertedColor = k;
                    colors[i].Converted      = true;
                    return(colors[i].ConvertedColor);
                }
            }
            throw new およよ($"色解決失敗: {colors[0].Color}");
        }