protected override Template RetrieveTemplate(string name, byte[] body, string TemplateID = null) { #warning Order and for each Entity entity = null; object entityID, attributeID, formatID; Attribute attribute = null; var placeholders = GetExcelPlaceHolders(body); if (placeholders.Count == 0) { throw new Exception("Указанный файл не содержит шаблон."); } var fields = new List <TemplateField>(); var creatorID = new Teleform.Reporting.UniqueIDCreator(); creatorID.Split(placeholders.First().ID, out entityID, out attributeID, out formatID); entity = Storage.Select <Entity>(entityID); foreach (var holder in placeholders) { creatorID.Split(holder.ID, out entityID, out attributeID, out formatID); attribute = entity.Attributes.FirstOrDefault(o => o.ID.ToString() == attributeID.ToString()); if (attribute == null) { throw new InvalidOperationException( string.Format("Сущность '{0}' не имеет атрибут с идентификатором {1}.", entity.Name, attributeID)); } var field = new TemplateField(attribute); field.Format = attribute.Type.GetAdmissableFormats().FirstOrDefault(o => o.ID.ToString() == formatID.ToString()); if (field.Format == null) { throw new InvalidOperationException( string.Format("Тип '{0}' атрибута {1} не имеет формат с идентификатором {2}.", attribute.Type.Name, attribute.Name, formatID)); } field.Name = holder.Alias; fields.Add(field); } #if sheetbox var template = new ExcelTemplate(name, entity, "ExcelBased", body, fields, SheetBox.Text.Trim()); #else var template = new ExcelTemplate(name, entity, this.TemplateTypeCode, body, fields, string.Empty, TemplateID); #endif return(template); }
protected override Template RetrieveTemplate(string name, byte[] body, string TemplateID = null) { var fields = new List <TemplateField>(); Entity entity = null; using (var t = new Teleform.Office.Reporting.OpenXMLWordTemplate(body)) { var placeholders = t.GetPlaceholders().ToList(); if (placeholders.Count == 0) { throw new Exception("Указанный файл не содержит шаблон."); } var creatorID = new Teleform.Reporting.UniqueIDCreator(); object entityID, attributeID, formatID; creatorID.Split(placeholders.First().Tag, out entityID, out attributeID, out formatID); entity = Global.Schema.Entities.FirstOrDefault(o => o.ID.ToString() == entityID.ToString()); Attribute attribute = null; foreach (var p in placeholders) { creatorID.Split(p.Tag, out entityID, out attributeID, out formatID); attribute = entity.Attributes.FirstOrDefault(o => o.ID.ToString() == attributeID.ToString()); if (attribute == null) { throw new InvalidOperationException( string.Format("Сущность '{0}' не имеет атрибут с идентификатором {1}.", entity.Name, attributeID)); } #warning порядок всегда равен 0 var field = new TemplateField(attribute); field.Format = attribute.Type.GetAdmissableFormats().FirstOrDefault(o => o.ID.ToString() == formatID.ToString()); if (field.Format == null) { throw new InvalidOperationException( string.Format("Тип '{0}' атрибута {1} не имеет формат с идентификатором {2}.", attribute.Type.Name, attribute.Name, formatID)); } fields.Add(field); } } #warning при содании требуется задавать id, а также fileName и name, задаются в GeneralTemplateDesigner var template = new Template(name, entity, this.TemplateTypeCode, body, fields, TemplateID); return(template); }