/// <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());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Exports the Objects in selected.
        /// </summary>
        /// <returns>Root of Model Prefab.</returns>
        /// <param name="selected">Objects to export.</param>
        internal virtual GameObject ExportSelection(Object selected, IExportOptions exportOptions = null)
        {
            // export selected to a file, then return the root
            var filename = GetRandomFileNamePath();

            return(ExportSelection(filename, selected, exportOptions));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 自动换行
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="workbookBytes">工作簿流</param>
        /// <param name="options">导出选项配置</param>
        /// <param name="context">装饰器上下文</param>
        public byte[] WarpText <T>(byte[] workbookBytes, IExportOptions <T> options, IDecoratorContext context) where T : class, new()
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var attribute = context.TypeDecoratorInfo.GetDecoratorAttribute <WrapTextAttribute>();

            if (attribute == null)
            {
                return(workbookBytes);
            }
            var workbook = workbookBytes.ToWorkbook();
            var sheet    = workbook.GetSheet(options.SheetName);

            if (sheet.PhysicalNumberOfRows <= 0)
            {
                return(workbookBytes);
            }

            for (var i = 0; i < sheet.PhysicalNumberOfRows; i++)
            {
                var row = sheet.GetRow(i);
                for (var colIndex = 0; colIndex < row.PhysicalNumberOfCells; colIndex++)
                {
                    row.GetCell(colIndex).CellStyle.WrapText = true;
                }
            }
            return(workbook.SaveToBuffer());
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 初始化一个<see cref="ExcelExportProcess{TEntity}"/>类型的实例
 /// </summary>
 /// <param name="excelExportService">Excel导出服务</param>
 /// <param name="options">导出选项配置</param>
 /// <param name="func">导出函数事件</param>
 /// <param name="condition">查询条件</param>
 public ExcelExportProcess(IExcelExportService excelExportService, IExportOptions <TEntity> options, GetExportDataEventAsync <TEntity> func, object condition)
 {
     _excelExportService = excelExportService ?? throw new ArgumentNullException(nameof(excelExportService));
     _options            = options ?? throw new ArgumentNullException(nameof(options));
     _func      = func;
     _condition = condition;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 导出
 /// </summary>
 /// <typeparam name="T">实体类型</typeparam>
 /// <param name="options">导出选项配置</param>
 public byte[] Export<T>(IExportOptions<T> options) where T : class, new()
 {
     var workbook = CreateWorkbook(options.ExportFormat);
     var sheet = workbook.CreateSheet(options.SheetName);
     var headerDict = ExportMappingFactory.CreateInstance(typeof(T));
     BuildDynamicHeader(headerDict, options.DynamicColumns);
     HandleHeader(sheet, options.HeaderRowIndex, headerDict);
     if (options.Data != null && options.Data.Count > 0)
         HandleBody(sheet, options.DataRowStartIndex, options.Data, headerDict);
     return workbook?.SaveToBuffer();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// collect all object dependencies for given animation clip
        /// </summary>
        public void CollectDependencies(
            AnimationClip animClip,
            GameObject rootObject,
            IExportOptions exportOptions
            )
        {
            Debug.Assert(rootObject != null);
            Debug.Assert(exportOptions != null);

            if (this.animationClips.ContainsKey(animClip))
            {
                // we have already exported gameobjects for this clip
                return;
            }

            // NOTE: the object (animationRootObject) containing the animation is not necessarily animated
            // when driven by an animator or animation component.
            this.animationClips.Add(animClip, rootObject);

            foreach (EditorCurveBinding uniCurveBinding in AnimationUtility.GetCurveBindings(animClip))
            {
                Object uniObj = AnimationUtility.GetAnimatedObject(rootObject, uniCurveBinding);
                if (!uniObj)
                {
                    continue;
                }

                GameObject unityGo = ModelExporter.GetGameObject(uniObj);
                if (!unityGo)
                {
                    continue;
                }

                if (!exportOptions.AnimateSkinnedMesh && unityGo.GetComponent <SkinnedMeshRenderer>())
                {
                    continue;
                }

                // If we have a clip driving a camera or light then force the export of FbxNodeAttribute
                // so that they point the right way when imported into Maya.
                if (unityGo.GetComponent <Light>())
                {
                    this.exportComponent[unityGo] = typeof(Light);
                }
                else if (unityGo.GetComponent <Camera>())
                {
                    this.exportComponent[unityGo] = typeof(Camera);
                }

                this.goExportSet.Add(unityGo);
            }
        }
        /// <summary>
        /// 合并单元格
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="sheet">工作表</param>
        /// <param name="columnIndex">列索引</param>
        /// <param name="options">导出选项配置</param>
        private void MergeCells <T>(NPOI.SS.UserModel.ISheet sheet, int columnIndex, IExportOptions <T> options)
            where T : class, new()
        {
            string currentCellValue;
            var    startRowIndex = options.DataRowStartIndex;

            NPOI.SS.Util.CellRangeAddress mergeRangeAddress;
            var startRow = sheet.GetRow(startRowIndex);

            if (startRow == null)
            {
                return;
            }
            var startCell = startRow.GetCell(columnIndex);

            if (startCell == null)
            {
                return;
            }
            string startCellValue = startCell.StringCellValue;

            if (string.IsNullOrWhiteSpace(startCellValue))
            {
                return;
            }

            for (var rowIndex = options.DataRowStartIndex; rowIndex < sheet.PhysicalNumberOfRows; rowIndex++)
            {
                var cell = sheet.GetRow(rowIndex)?.GetCell(columnIndex);
                currentCellValue = cell == null ? string.Empty : cell.StringCellValue;
                if (currentCellValue.Trim() != startCellValue.Trim())
                {
                    mergeRangeAddress = new CellRangeAddress(startRowIndex, rowIndex - 1, columnIndex, columnIndex);
                    if (mergeRangeAddress.NumberOfCells > 1)
                    {
                        sheet.AddMergedRegion(mergeRangeAddress);
                        startRow.GetCell(columnIndex).CellStyle.VerticalAlignment = VerticalAlignment.Center;
                    }

                    startRowIndex  = rowIndex;
                    startCellValue = currentCellValue;
                }

                if (rowIndex == sheet.PhysicalNumberOfRows - 1 && startRowIndex != rowIndex)
                {
                    mergeRangeAddress = new CellRangeAddress(startRowIndex, rowIndex, columnIndex, columnIndex);
                    sheet.AddMergedRegion(mergeRangeAddress);
                    startRow.GetCell(columnIndex).CellStyle.VerticalAlignment = VerticalAlignment.Center;
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// collect all objects dependencies for animation clips.
        /// </summary>
        public void CollectDependencies(
            AnimationClip[] animClips,
            GameObject rootObject,
            IExportOptions exportOptions
            )
        {
            Debug.Assert(rootObject != null);
            Debug.Assert(exportOptions != null);

            foreach (var animClip in animClips)
            {
                CollectDependencies(animClip, rootObject, exportOptions);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 合并单元格
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="workbookBytes">工作簿流</param>
        /// <param name="options">导出选项配置</param>
        /// <param name="context">装饰器上下文</param>
        public byte[] MergeCells<T>(byte[] workbookBytes, IExportOptions<T> options, IDecoratorContext context) where T : class, new()
        {
            if (context == null)
                throw new ArgumentNullException(nameof(context));
            var propertyDecoratorInfos = context.TypeDecoratorInfo.PropertyDecoratorInfos;
            var workbook = workbookBytes.ToWorkbook();
            var sheet = workbook.GetSheet(options.SheetName);
            foreach (var item in propertyDecoratorInfos)
            {
                if (item.Decorators.SingleOrDefault(x => x.GetType() == typeof(MergeColumnsAttribute)) != null)
                {
                    MergeCells(sheet, item.ColumnIndex, options);
                }
            }

            return workbook.SaveToBuffer();
        }
        /// <summary>
        /// 自定义表头行
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sheet"></param>
        /// <param name="options"></param>
        private void CustomHeaderRow <T>(NPOI.SS.UserModel.ISheet sheet, IExportOptions <T> options) where T : class, new()
        {
            if (options.HeaderRow == null || !options.HeaderRow.Any())
            {
                return;
            }
            CellRangeAddress(sheet, options);

            options.HeaderRow.ForEach(x =>
            {
                var hRow = sheet.GetRow(x.RowIndex) ?? sheet.CreateRow(x.RowIndex);
                x.Cells.OrderBy(m => m.ColumnIndex).ForEach(m =>
                {
                    var col = hRow.GetCell(m.ColumnIndex) ?? hRow.CreateCell(m.ColumnIndex);
                    col.SetCellValue(m.Value.ToString());
                });
            });
        }
        /// <summary>
        /// 处理表头
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="sheet">NPOI工作表</param>
        /// <param name="options">导出选项配置</param>
        /// <param name="headerDict">表头映射字典</param>
        private void HandleHeader <T>(NPOI.SS.UserModel.ISheet sheet, IExportOptions <T> options, IDictionary <string, PropertySetting> headerDict) where T : class, new()
        {
            var row         = sheet.CreateRow(options.HeaderRowIndex);
            var columnIndex = 0;

            foreach (var kvp in headerDict)
            {
                if (kvp.Value.Ignored)
                {
                    continue;
                }
                if (kvp.Value.IsDynamicColumn)
                {
                    foreach (var column in kvp.Value.DynamicColumns)
                    {
                        row.CreateCell(columnIndex).SetCellValue(column);
                        columnIndex++;
                    }
                    continue;
                }
                row.CreateCell(columnIndex).SetCellValue(kvp.Value.Title);
                columnIndex++;
            }
        }
        /// <summary>
        /// 合并单元格
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sheet"></param>
        /// <param name="options"></param>
        private void CellRangeAddress <T>(NPOI.SS.UserModel.ISheet sheet, IExportOptions <T> options) where T : class, new()
        {
            //if (options.HeaderRow.All(x => x.Cells.All(m => m.ColumnSpan == 1)))
            //    return;
            //var rows = options.HeaderRow.Where(x => x.Cells.Any(m => m.ColumnSpan > 1)).ToList();
            var rows = options.HeaderRow.Where(x => x.Cells.Any(t => t.RowSpan > 1 || t.ColumnSpan > 1)).ToList();

            if (rows.Any())
            {
                rows.OrderBy(x => x.RowIndex).ForEach(row =>
                {
                    row.Cells.OrderBy(x => x.ColumnIndex).ForEach(x =>
                    {
                        if (x.RowSpan <= 1 && x.ColumnSpan <= 1)
                        {
                            return;
                        }
                        var region =
                            new CellRangeAddress(x.RowIndex, x.EndRowIndex, x.ColumnIndex, x.EndColumnIndex);
                        sheet.AddMergedRegion(region);
                    });
                });
            }
        }
Ejemplo n.º 13
0
        internal virtual GameObject ExportSelection(string filename, Object[] selected, IExportOptions exportOptions = null)
        {
            Debug.unityLogger.logEnabled = false;
            var fbxFileName = ModelExporter.ExportObjects(filename, selected, exportOptions) as string;

            Debug.unityLogger.logEnabled = true;

            Assert.IsNotNull(fbxFileName);

            // make filepath relative to project folder
            if (fbxFileName.StartsWith(Application.dataPath, System.StringComparison.CurrentCulture))
            {
                fbxFileName = "Assets" + fbxFileName.Substring(Application.dataPath.Length);
            }
            // refresh the assetdata base so that we can query for the model
            AssetDatabase.Refresh();

            Object unityMainAsset = AssetDatabase.LoadMainAssetAtPath(fbxFileName);
            var    fbxRoot        = unityMainAsset as GameObject;

            Assert.IsNotNull(fbxRoot);
            return(fbxRoot);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// 初始化一个<see cref="ExcelExportProcess{TEntity}"/>类型的实例
 /// </summary>
 /// <param name="excelExportService">Excel导出服务</param>
 /// <param name="options">导出选项配置</param>
 public ExcelExportProcess(IExcelExportService excelExportService, IExportOptions <TEntity> options) : this(excelExportService, options, null, null)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 /// 处理
 /// </summary>
 /// <typeparam name="T">实体类型</typeparam>
 /// <param name="workbookBytes">工作簿字节数组</param>
 /// <param name="options">导出选项配置</param>
 /// <param name="context">装饰器上下文</param>
 /// <param name="excelExportProvider">Excel导出提供程序</param>
 public byte[] Handler <T>(byte[] workbookBytes, IExportOptions <T> options, IDecoratorContext context,
                           IExcelExportProvider excelExportProvider)
     where T : class, new() => excelExportProvider.WarpText(workbookBytes, options, context);
Ejemplo n.º 16
0
        internal virtual GameObject ExportSelection(Object[] selected, IExportOptions exportOptions = null)
        {
            var filename = GetRandomFileNamePath();

            return(ExportSelection(filename, selected, exportOptions));
        }
Ejemplo n.º 17
0
 internal virtual GameObject ExportSelection(string filename, Object selected, IExportOptions exportOptions = null)
 {
     // export selected to a file, then return the root
     return(ExportSelection(filename, new Object[] { selected }, exportOptions));
 }