/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="dataStructureId"></param> /// <param name="extension"></param> /// <returns></returns> public string GetDataStructureTemplatePath(long dataStructureId, string extension) { using (DataStructureManager dataStructureManager = new DataStructureManager()) { StructuredDataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(dataStructureId); string dataStructureTitle = dataStructure.Name; // load datastructure from db an get the filepath from this object ExcelTemplateProvider provider = new ExcelTemplateProvider("BExISppTemplate_Clean.xlsm"); string path = ""; if (dataStructure.TemplatePaths != null) { XmlNode resources = dataStructure.TemplatePaths.FirstChild; XmlNodeList resource = resources.ChildNodes; foreach (XmlNode x in resource) { if (x.Attributes.GetNamedItem("Type").Value == "Excel") { if (File.Exists(x.Attributes.GetNamedItem("Path").Value)) { path = x.Attributes.GetNamedItem("Path").Value; } else { path = provider.CreateTemplate(dataStructure); } } } //string dataPath = AppConfiguration.DataPath; //Path.Combine(AppConfiguration.WorkspaceRootPath, "Data"); return(Path.Combine(AppConfiguration.DataPath, path)); } path = provider.CreateTemplate(dataStructure); return(Path.Combine(AppConfiguration.DataPath, path)); } }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="datasetId"></param> /// <param name="datasetVersionOrderNr"></param> /// <param name="dataStructureId"></param> /// <param name="title"></param> /// <param name="extention"></param> /// <returns></returns> public string CreateFile(long datasetId, long datasetVersionOrderNr, long dataStructureId, string title, string extention) { string dataPath = GetFullStorePath(datasetId, datasetVersionOrderNr, title, extention); //Template will not be filtered by columns if (this.VisibleColumns == null) { #region generate file with full datastructure string dataStructureFilePath = GetDataStructureTemplatePath(dataStructureId, extention); //dataPath = GetStorePath(datasetId, datasetVersionOrderNr, title, extention); try { SpreadsheetDocument dataStructureFile = SpreadsheetDocument.Open(dataStructureFilePath, true); SpreadsheetDocument dataFile = SpreadsheetDocument.Create(dataPath, dataStructureFile.DocumentType); foreach (OpenXmlPart part in dataStructureFile.GetPartsOfType <OpenXmlPart>()) { OpenXmlPart newPart = dataFile.AddPart <OpenXmlPart>(part); } dataFile.WorkbookPart.Workbook.Save(); dataStructureFile.Dispose(); dataFile.Dispose(); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } #endregion } // create a file with a subset of variables if (this.VisibleColumns != null) { /// call templateprovider from rpm ExcelTemplateProvider provider = new ExcelTemplateProvider(); string path = GetStorePath(datasetId, datasetVersionOrderNr); string newTitle = GetNewTitle(datasetId, datasetVersionOrderNr, title, extention); provider.CreateTemplate(getVariableIds(this.VisibleColumns), dataStructureId, path, newTitle); } return(dataPath); }