Example #1
0
        public static void CreateMatrixHeaderRow(this IWfClientMatrixContainer matrix, WorkSheet sheet)
        {
            matrix.NullCheck("matrix");
            sheet.NullCheck("sheet");

            Row headRow = new Row(3);

            headRow.Style.Fill.SetBackgroundColor(Color.Gold, ExcelFillStyle.Solid);
            headRow.Style.Border.Top.Style = ExcelBorderStyle.Thin;
            headRow.Style.Border.Top.Color.SetColor(Color.Black);
            headRow.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
            headRow.Style.Border.Bottom.Color.SetColor(Color.Black);
            headRow.Style.Border.Left.Style = ExcelBorderStyle.Thin;
            headRow.Style.Border.Left.Color.SetColor(Color.Black);
            headRow.Style.Font.Bold = true;
            sheet.Rows.Add(headRow);

            int columnIndex = 1;

            foreach (WfClientRolePropertyDefinition dimension in matrix.PropertyDefinitions)
            {
                sheet.Cells[headRow.Index, columnIndex].Value = dimension.Description.IsNotEmpty() ? dimension.Description : dimension.Name;
                sheet.Names.Add(CellAddress.Parse(columnIndex, headRow.Index).ToString(), dimension.Name);

                columnIndex++;
            }
        }
Example #2
0
        public static void FillMatrixSheetData(this IWfClientMatrixContainer matrix, WorkSheet sheet)
        {
            matrix.NullCheck("matrix");
            sheet.NullCheck("sheet");

            int rowIndex = 4;
            WfClientRolePropertyRowCollection rows = matrix.Rows;

            foreach (WfClientRolePropertyRow row in rows)
            {
                foreach (DefinedName name in sheet.Names)
                {
                    var propertyValue = row.Values.FindByColumnName(name.Name);

                    object dataValue = null;

                    if (propertyValue != null)
                    {
                        if (propertyValue.Column.DataType != Data.DataObjects.ColumnDataType.String)
                        {
                            dataValue = DataConverter.ChangeType(typeof(string),
                                                                 propertyValue.Value,
                                                                 propertyValue.Column.RealDataType);
                        }
                        else
                        {
                            dataValue = propertyValue.Value;
                        }
                    }
                    else
                    {
                        if (matrix.MatrixType != WfClientMatrixType.ApprovalMatrix)
                        {
                            switch (name.Name.ToLower())
                            {
                            case "operatortype":
                                dataValue = row.OperatorType.ToString();
                                break;

                            case "operator":
                                dataValue = row.Operator;
                                break;
                            }
                        }
                    }

                    if (dataValue != null)
                    {
                        sheet.Cells[rowIndex, name.Address.StartColumn].Value = dataValue;
                    }
                }

                rowIndex++;
            }
        }
Example #3
0
        /// <summary>
        /// 矩阵转换为Excel的WorkBook的流
        /// </summary>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public static Stream ToExcelStream(this IWfClientMatrixContainer matrix)
        {
            matrix.NullCheck("matrix");

            WorkBook workBook = matrix.ToWorkBook();

            MemoryStream stream = new MemoryStream();

            workBook.Save(stream);
            stream.Seek(0, SeekOrigin.Begin);

            return(stream);
        }
Example #4
0
        /// <summary>
        /// 转换为Excel的WorkSheet
        /// </summary>
        /// <param name="matrix"></param>
        /// <param name="workBook"></param>
        /// <returns></returns>
        public static WorkSheet ToWorkSheet(this IWfClientMatrixContainer matrix, WorkBook workBook)
        {
            matrix.NullCheck("matrix");

            WorkSheet sheet = new WorkSheet(workBook, "Matrix");

            Row titleRow = new Row(1)
            {
                Height = 30d
            };

            titleRow.Style.Fill.SetBackgroundColor(Color.LightGray, ExcelFillStyle.Solid);
            titleRow.Style.Font.Size = 20;
            sheet.Rows.Add(titleRow);

            sheet.Cells[titleRow.Index, 1].Value = "审批矩阵";

            CreateMatrixHeaderRow(matrix, sheet);

            FillMatrixSheetData(matrix, sheet);

            return(sheet);
        }