/// <summary>
 ///     格式化
 /// </summary>
 /// <param name="sheetAdapter">Sheet适配器</param>
 public override void Format(SheetAdapter sheetAdapter)
 {
     if (FormatterList.IsNullOrEmpty())
     {
         throw new ExcelReportFormatException("TableFormatter is empty");
     }
     if (DataSource.IsNullOrEmpty())
     {
         sheetAdapter.RemoveRow(TagParameter.RowIndex); //删除模板行
     }
     else
     {
         for (int i = 0; i < DataSource.Count; i++)
         {
             if (i < DataSource.Count - 1) //非最后一行数据时,复制模板
             {
                 sheetAdapter.CopyRow(TagParameter.RowIndex, () =>
                 {
                     foreach (var formatter in FormatterList) //格式化行
                     {
                         formatter.Format(sheetAdapter, DataSource[i]);
                     }
                 });
             }
             else
             {
                 foreach (var formatter in FormatterList) //格式化行
                 {
                     formatter.Format(sheetAdapter, DataSource[i]);
                 }
             }
         }
     }
 }
        /// <summary>
        /// 格式化
        /// </summary>
        /// <param name="workbook">工作薄</param>
        public void Format(IWorkbook workbook)
        {
            ISheet sheet = workbook.GetSheet(SheetName);

            if (!sheet.IsNull() && !FormatterList.IsNullOrEmpty())
            {
                var sheetAdapter = new SheetAdapter(sheet);
                foreach (ElementFormatter formatter in FormatterList)
                {
                    formatter.Format(sheetAdapter);
                }
            }
        }
Exemple #3
0
        /// <summary>
        ///     格式化
        /// </summary>
        /// <param name="sheetAdapter">Sheet适配器</param>
        public override void Format(SheetAdapter sheetAdapter)
        {
            IRow row = sheetAdapter.GetRow(Parameter.RowIndex);

            if (null == row)
            {
                throw new ExcelReportFormatException("row is null");
            }
            ICell cell = row.GetCell(Parameter.ColumnIndex);

            if (null == cell)
            {
                throw new ExcelReportFormatException("cell is null");
            }
            cell.SetValue(Value);
        }
Exemple #4
0
        /// <summary>
        ///     格式化
        /// </summary>
        /// <param name="sheetAdapter">Sheet适配器</param>
        public override void Format(SheetAdapter sheetAdapter)
        {
            IRow row = sheetAdapter.GetRow(Parameter.RowIndex);

            if (null == row)
            {
                throw new ExcelReportException("row is null");
            }
            ICell cell = row.GetCell(Parameter.ColumnIndex);

            if (null == cell)
            {
                throw new ExcelReportException("cell is null");
            }

            cell.SetValue(cell.StringCellValue.Replace(string.Format("$[{0}]", Parameter.Name), Value.CastTo <string>()));
        }
        public override void Format(SheetAdapter sheetAdapter)
        {
            ISheet        currentSheet = sheetAdapter.CurrentSheet;
            List <object> shapes       = this.PictureInfo.GetShapes(currentSheet);
            bool          flag         = false;

            if (currentSheet is HSSFSheet)
            {
                flag = true;
            }
            if (shapes == null || shapes.Count <= 0)
            {
                throw new Exception(string.Format("未能获取到工作薄[{0}]指定区域的图形对象列表!", currentSheet.SheetName));
            }
            byte[]        pictureData = File.ReadAllBytes(this.PictureInfo.FilePath);
            IClientAnchor anchor;
            IDrawing      drawing;

            if (flag)
            {
                HSSFShape hSSFShape = shapes[0] as HSSFShape;
                anchor              = (hSSFShape.Anchor as IClientAnchor);
                drawing             = hSSFShape.Patriarch;
                hSSFShape.LineStyle = LineStyle.None;
            }
            else
            {
                XSSFShape xSSFShape = shapes[0] as XSSFShape;
                anchor              = (xSSFShape.GetAnchor() as IClientAnchor);
                drawing             = xSSFShape.GetDrawing();
                xSSFShape.LineStyle = LineStyle.None;
            }
            int      pictureIndex = currentSheet.Workbook.AddPicture(pictureData, this.PictureInfo.PictureType);
            IPicture picture      = drawing.CreatePicture(anchor, pictureIndex);

            if (this.PictureInfo.AutoSize)
            {
                picture.Resize();
            }
        }