예제 #1
0
        ///// <summary>
        ///// Creates an excel file containing data provided in the dataparts.
        ///// Each IDatapart will match with an ExportPart of the same PartId
        ///// and will use this information to output the data in the desired format.
        ///// </summary>
        ///// <param name="open">true to open, false to not</param>
        ///// <param name="title">The title.</param>
        ///// <param name="dataParts">The data parts to output</param>
        ///// <param name="metadata">The metadata.</param>
        ///// <param name="exportParameters">Optional export parameters.</param>
        ///// <returns>The full path of the created file</returns>
        //public string ExportToExcel(bool open, string title, IEnumerable<IDataPart> dataParts, ExportMetadata metadata, ExcelTemplatePackage templatePackage, ExportParameters exportParameters = null)
        //{
        //    if (string.IsNullOrEmpty(title))
        //    {
        //        throw new ArgumentNullException("targetFilePath");
        //    }
        //    if (dataParts == null)
        //    {
        //        throw new ArgumentNullException("dataParts");
        //    }
        //    if (metadata == null)
        //    {
        //        throw new ArgumentNullException("metadata");
        //    }
        //    if (templatePackage == null)
        //    {
        //        throw new ArgumentNullException("templatePackage");
        //    }

        //    // Adds the parameters as a data part (creates a hidden sheet)
        //    dataParts = AddDebugPart(dataParts, metadata, exportParameters);

        //    // build our sets of DataParts, ExportParts, ExportTemplates
        //    List<ExportTripleSet> sets = this.BuildSets(dataParts, metadata, templatePackage);
        //    if (sets.Count == 0)
        //    {
        //        throw new ExportException("Nothing to export, no matching DataParts, ExportParts, ExportTemplates found");
        //    }

        //    var stream = this.ExcelExportInternal(exportParameters, metadata, sets, dataParts, templatePackage);

        //    if (!title.EndsWith(".xls") && !title.EndsWith(".xlsx"))
        //    {
        //        title = string.Concat(title, ".xlsx");
        //    }

        //    return SaveAndOpen(open, title, stream);
        //}

        /// <summary>
        /// Exports to excel memory stream.
        /// </summary>
        /// <param name="dataParts">The data parts.</param>
        /// <param name="metadata">The metadata.</param>
        /// <param name="templatePackage">The template package.</param>
        /// <param name="exportParameters">The export parameters.</param>
        /// <returns></returns>
        public ExportToMemoryStreamResult ExportToExcelMemoryStream(
            IEnumerable <IDataPart> dataParts,
            Book metadata,
            ExcelTemplatePackage resourcePackage,
            ExportParameters exportParameters = null)
        {
            Guard.IsNotNull(dataParts, "dataParts");
            Guard.IsNotNull(metadata, "metadata");
            Guard.IsNotNull(resourcePackage, "resourcePackage");

            var result = new ExportToMemoryStreamResult();

            dataParts = AddDebugPart(dataParts, metadata, exportParameters);

            // build our sets of DataParts, ExportParts, ExportTemplates
            List <ExportTripleSet> sets = this.BuildSets(dataParts, metadata, resourcePackage);

            if (sets.Count == 0)
            {
                throw new ExportException("Nothing to export, no matching DataParts, ExportParts, ExportTemplates found");
            }

            try
            {
                result.MemoryStream = this.ExcelExportInternal(exportParameters, metadata, sets, dataParts, resourcePackage);
            }
            catch (Exception ex)
            {
                result.Error = ex;
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Generates the document.
        /// </summary>
        /// <param name="dataParts">The data parts.</param>
        /// <param name="metadata">The metadata.</param>
        /// <param name="resourcePackage">The resource package.</param>
        /// <param name="exportParameters">The export parameters.</param>
        /// <returns></returns>
        public ExportToMemoryStreamResult GenerateDocument(IEnumerable <IDataPart> dataParts, DocumentMetadataBase metadata, ResourcePackage resourcePackage, ExportParameters exportParameters = null)
        {
            Guard.IsNotNull(dataParts, "dataParts");
            Guard.IsNotNull(metadata, "metadata");
            Guard.IsNotNull(resourcePackage, "resourcePackage");

            var result = new ExportToMemoryStreamResult();

            try
            {
                if (metadata.DocumentMetadataType == DocumentMetadataType.ExcelDocument)
                {
                    result.MemoryStream = this.GenerateExcelInternal(exportParameters, (ExcelDocumentMetadata)metadata, dataParts, resourcePackage);
                }
                else
                {
                    throw new ExportException("Unknown document metadata type");
                }
            }
            catch (Exception ex)
            {
                result.Error = ex;
            }
            return(result);
        }
예제 #3
0
        /// <summary>
        /// The generate export metadata report.
        /// </summary>
        private MemoryStreamResult GenerateExportMetadataBasedReport()
        {
            this.logger.Log(LogType.Trace, this.GetAssemblyName(), "{0}.GenerateExportMetadataReport", this.GetType().Name);
            var resourcesPackage = ExcelTemplatePackage.Open(Path.Combine(this.sourceFolder, this.templatePackageName));
            var exportMetadata   = ExportMetadataPackage.Open(Path.Combine(this.sourceFolder, this.metadataPackageName)).ExportMetadata;
            var generator        = new ExportGenerator();
            var exportParams     = new ExportParameters();

            ExportToMemoryStreamResult result = generator.ExportToExcelMemoryStream(this.dataParts,
                                                                                    exportMetadata,
                                                                                    resourcesPackage,
                                                                                    exportParams);

            if (result.Error != null)
            {
                this.logger.Log(LogType.Fatal, this.GetAssemblyName(), "{0}.GenerateExportMetadataReport", result.Error);
            }

            return(new MemoryStreamResult
            {
                MemoryStream = result.MemoryStream,
                Status = result.Error == null ? MemoryStreamResultStatus.Success : MemoryStreamResultStatus.Failure,
                ErrorMessage = result.Error == null ? null : result.Error.Message,
            });
        }
예제 #4
0
        /// <summary>
        /// The generate document metadata based report.
        /// </summary>
        private MemoryStreamResult GenerateDocumentMetadataBasedReport(bool isPdf)
        {
            this.logger.Log(LogType.Trace, this.GetAssemblyName(), "{0}.GenerateDocumentMetadataBasedReport", this.GetType().Name);
            var resourcesPackage        = ResourcePackage.Open(Path.Combine(this.sourceFolder, this.templatePackageName));
            var documentMetadataPackage = DocumentMetadataPackage.Open(Path.Combine(this.sourceFolder, this.metadataPackageName)).DocumentMetadata;
            var generator    = new ExportGenerator();
            var exportParams = new ExportParameters {
                ConvertOutputToPdf = isPdf
            };

            ExportToMemoryStreamResult result = generator.GenerateDocument(this.dataParts,
                                                                           documentMetadataPackage,
                                                                           resourcesPackage,
                                                                           exportParams);

            if (result.Error != null)
            {
                this.logger.Log(LogType.Fatal, this.GetAssemblyName(), "{0}.GenerateDocumentMetadataBasedReport", result.Error);
            }

            return(new MemoryStreamResult
            {
                MemoryStream = result.MemoryStream,
                Status = result.Error == null ? MemoryStreamResultStatus.Success : MemoryStreamResultStatus.Failure,
                ErrorMessage = result.Error == null ? null : result.Error.Message,
            });
        }
예제 #5
0
        ///// <summary>
        ///// Creates an excel file containing data provided in the dataparts.
        ///// Each IDatapart will match with an ExportPart of the same PartId
        ///// and will use this information to output the data in the desired format.
        ///// </summary>
        ///// <param name="open">true to open, false to not</param>
        ///// <param name="title">The title.</param>
        ///// <param name="dataParts">The data parts to output</param>
        ///// <param name="metadata">The metadata.</param>
        ///// <param name="exportParameters">Optional export parameters.</param>
        ///// <returns>The full path of the created file</returns>
        //public string ExportToExcel(bool open, string title, IEnumerable<IDataPart> dataParts, ExportMetadata metadata, ExcelTemplatePackage templatePackage, ExportParameters exportParameters = null)
        //{
        //    if (string.IsNullOrEmpty(title))
        //    {
        //        throw new ArgumentNullException("targetFilePath");
        //    }
        //    if (dataParts == null)
        //    {
        //        throw new ArgumentNullException("dataParts");
        //    }
        //    if (metadata == null)
        //    {
        //        throw new ArgumentNullException("metadata");
        //    }
        //    if (templatePackage == null)
        //    {
        //        throw new ArgumentNullException("templatePackage");
        //    }

        //    // Adds the parameters as a data part (creates a hidden sheet)
        //    dataParts = AddDebugPart(dataParts, metadata, exportParameters);

        //    // build our sets of DataParts, ExportParts, ExportTemplates
        //    List<ExportTripleSet> sets = this.BuildSets(dataParts, metadata, templatePackage);
        //    if (sets.Count == 0)
        //    {
        //        throw new ExportException("Nothing to export, no matching DataParts, ExportParts, ExportTemplates found");
        //    }

        //    var stream = this.ExcelExportInternal(exportParameters, metadata, sets, dataParts, templatePackage);

        //    if (!title.EndsWith(".xls") && !title.EndsWith(".xlsx"))
        //    {
        //        title = string.Concat(title, ".xlsx");
        //    }

        //    return SaveAndOpen(open, title, stream);
        //}

        /// <summary>
        /// Exports to excel memory stream.
        /// </summary>
        /// <param name="dataParts">The data parts.</param>
        /// <param name="metadata">The metadata.</param>
        /// <param name="templatePackage">The template package.</param>
        /// <param name="exportParameters">The export parameters.</param>
        /// <returns></returns>
        public ExportToMemoryStreamResult ExportToExcelMemoryStream(IEnumerable <IDataPart> dataParts, ExportMetadata metadata, ExcelTemplatePackage templatePackage, ExportParameters exportParameters = null)
        {
            var result = new ExportToMemoryStreamResult();

            if (dataParts == null)
            {
                throw new ArgumentNullException("dataParts");
            }
            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }
            if (templatePackage == null)
            {
                throw new ArgumentNullException("templatePackage");
            }

            dataParts = AddDebugPart(dataParts, metadata, exportParameters);

            // build our sets of DataParts, ExportParts, ExportTemplates
            List <ExportTripleSet> sets = this.BuildSets(dataParts, metadata, templatePackage);

            if (sets.Count == 0)
            {
                throw new ExportException("Nothing to export, no matching DataParts, ExportParts, ExportTemplates found");
            }

            try
            {
                result.MemoryStream = this.ExcelExportInternal(exportParameters, metadata, sets, dataParts, templatePackage);
            }
            catch (Exception ex)
            {
                result.Error = ex;
            }

            return(result);
        }