private ListContent GetAttributes(string[] attributes, ListContent listItems) { if (attributes != null) { foreach (string attr in attributes) { listItems.AddItem(new FieldContent("AttrItem", attr)); } } else { listItems.AddItem(new FieldContent("AttrItem", "нет атрибутов")); } return(listItems); }
public object SaveChartToFile([FromQuery] string fileName) { byte[] chart = Convert.FromBase64String(StaticData.DataChart); string filePath = Path.ChangeExtension(fileName + " отчет с графиком", ".docx"); System.IO.File.Copy("TemplatesReportsWord/ChartReportTemplate.docx", filePath); using (FileStream fstream = System.IO.File.Open(filePath, FileMode.Open)) { List <IContentItem> fieldContents = new List <IContentItem>(); ListContent listContent = new ListContent("systems"); ListItemContent contentItems; TableContent tableContent; List <FieldContent> rows = new List <FieldContent>(); int number; foreach (var calculation in StaticData.ChartCalculation.calculations) { number = 1; tableContent = TableContent.Create("systemsMembers"); foreach (var value in calculation.values) { rows.Clear(); rows.Add(new FieldContent("number", number.ToString() + ".")); rows.Add(new FieldContent("parameterX", value.X.ToString())); rows.Add(new FieldContent("parameterY", value.Y.ToString())); tableContent.AddRow(rows.ToArray()); number++; } contentItems = new ListItemContent("system", calculation.nameSystem); contentItems.AddTable(tableContent); listContent.AddItem(contentItems); } fieldContents.Add(listContent); fieldContents.Add(new FieldContent("nameParameterX", StaticData.ChartCalculation.parameterNameX)); fieldContents.Add(new FieldContent("nameParameterY", StaticData.ChartCalculation.parameterNameY)); fieldContents.Add(new ImageContent("chart", chart)); using (var outputDocument = new TemplateProcessor(fstream).SetRemoveContentControls(true)) { outputDocument.FillContent(new Content(fieldContents.ToArray())); outputDocument.SaveChanges(); } } var memory = new MemoryStream(); using (var stream = new FileStream(filePath, FileMode.Open)) { stream.CopyTo(memory); } System.IO.File.Delete(filePath); memory.Position = 0; return(File(memory, MimeTypesMap.GetMimeType(filePath), filePath)); }
///<inheritdoc cref="ITemplateDocumentBuilder.FillTabelsContent{TRow}"/> public ITemplateDocumentBuilder FillTabelsContent <TRow>(DocumentList <DocumentTable <TRow> > tabels) where TRow : class { var listContent = new ListContent(tabels.ListKey); foreach (var table in tabels.ListItems) { var tableContent = ConstructTableContent(table); listContent.AddItem(new ListItemContent("TableHeader", table.TableHeader).AddTable(tableContent)); } _documentContent.Lists.Add(listContent); return(this); }
///<inheritdoc cref="ITemplateDocumentBuilder.FillListContent{TListItem}"/> public ITemplateDocumentBuilder FillListContent <TListItem>(DocumentList <TListItem> list) where TListItem : class { var listContent = new ListContent(list.ListKey); var members = GetModelMembers(typeof(TListItem)); foreach (var row in list.ListItems) { var listItems = new List <IContentItem>(); foreach (var member in members) { var value = member.GetValue <string>(row); if (value != null) { listItems.Add(new FieldContent(member.Name, value)); } } listContent.AddItem(listItems.ToArray()); } _documentContent.Lists.Add(listContent); return(this); }
private void Create_Doc(object sender, RoutedEventArgs e) { string file = AppDomain.CurrentDomain.BaseDirectory + "/tempplates/nak.docx"; Content values = new Content(); values.Fields.Add(new FieldContent("data", DateTime.Now.ToShortDateString().ToString())); values.Lists.Add(new ListContent("List")); ListContent ll = values.Lists.First(); for (int i = 0; i < all.Length; i++) { TableContent tt = new TableContent("table"); ArrayList tmp = all[i] as ArrayList; double allprice = 0; for (int j = 0; j < tmp.Count; j++) { Row tmprow = (Row)all[i][j]; int count = (int)counts[i][j]; tt.AddRow(new FieldContent("nameD", tmprow.name), new FieldContent("Mater", tmprow.material), new FieldContent("Size", tmprow.size), new FieldContent("Count", count + ""), new FieldContent("Price", tmprow.price + ""), new FieldContent("allPrice", tmprow.price * count + "")); allprice += tmprow.price * count; } ll.AddItem(new FieldContent("N", (i + 1) + ""), tt, new FieldContent("all", allprice + "")); } Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog(); saveFileDialog.DefaultExt = "docx"; saveFileDialog.Filter = "Docx|*.docx"; if (saveFileDialog.ShowDialog() == true) { File.Copy(file, saveFileDialog.FileName); using (var outputDocument = new TemplateProcessor(saveFileDialog.FileName) .SetRemoveContentControls(true)) { outputDocument.FillContent(values); outputDocument.SaveChanges(); } } }
public void Export() { this.setViewModel(); var fileInfo = new FileInfo(_viewModel.TemplatePath); var newFileInfo = new FileInfo(fileInfo.DirectoryName + "\\" + fileInfo.Name.Split('.')[0] + "_new" + fileInfo.Extension); File.Delete(newFileInfo.FullName); File.Copy(fileInfo.FullName, newFileInfo.FullName); using (var outputDocument = new TemplateProcessor(newFileInfo.FullName).SetRemoveContentControls(true)) { ListContent listContent = new ListContent("Table list"); foreach (var t in _viewModel.Tables) { var listItemContent = new ListItemContent(); listContent.AddItem(listItemContent); listItemContent.AddField("Table title", "[" + t.Schema + "].[" + t.TableName + "]"); listItemContent.AddField("Table name", "[" + t.Schema + "].[" + t.TableName + "]"); listItemContent.AddField("Table description", t.Description); listItemContent.AddField("Table pk", t.PrimaryKeys); var columnContent = new TableContent("Column row"); listItemContent.AddTable(columnContent); foreach (var c in t.Columns) { columnContent.AddRow( new FieldContent("Name", c.Name), new FieldContent("Type", c.Type), new FieldContent("Null", c.Nullable), new FieldContent("Description", c.Description)); } } Content mainContent = new Content(listContent); outputDocument.FillContent(mainContent); outputDocument.SaveChanges(); } }
public override CustomFile ProceedCV(string templatePath, CVExportModel cvModel) { using (MemoryStream mem = new MemoryStream(File.ReadAllBytes(templatePath))) { using (var outputDocument = new TemplateProcessor(mem) .SetRemoveContentControls(true)) { var valuesToFill = new Content( new FieldContent("FullName", cvModel.FullName), new FieldContent("Qualification", cvModel.Qualification), new FieldContent("Summary", cvModel.Summary) ); ListContent skillsList = new ListContent("Skills Nested List"); foreach (var technology in cvModel.Technologies) { ListItemContent technologyListItem = new ListItemContent("Technology", technology.Name); ListContent skillItem = new ListContent("Skill"); foreach (var skill in technology.Skills) { skillItem.AddItem( new FieldContent("SkillName", skill.Name), new FieldContent("KnowledgeLevel", skill.KnowledgeLevel)); } technologyListItem.AddList(skillItem); skillsList.AddItem(technologyListItem); } valuesToFill.Lists.Add(skillsList); TableContent experienceTable = new TableContent("ExperienceTable"); foreach (var jobExperienceModel in cvModel.JobExperiences) { experienceTable.AddRow( new FieldContent("Company", jobExperienceModel.Company), new FieldContent("Project", jobExperienceModel.Project), new FieldContent("ProjectDescription", jobExperienceModel.Description), new FieldContent("Period", jobExperienceModel.Period), new FieldContent("Space", string.Empty)); } valuesToFill.Tables.Add(experienceTable); TableContent educationTable = new TableContent("EducationTable"); foreach (var educationModel in cvModel.Educations) { educationTable.AddRow( new FieldContent("Place", educationModel.Place), new FieldContent("Speciality", educationModel.Speciality), new FieldContent("Degree", educationModel.Degree), new FieldContent("Period", educationModel.Period), new FieldContent("Space", string.Empty)); } valuesToFill.Tables.Add(educationTable); outputDocument.SetNoticeAboutErrors(false); outputDocument.FillContent(valuesToFill); outputDocument.SaveChanges(); _filecontents = mem.ToArray(); return(this); } } }
public static void FillContentControls(string fileName, List <DocumentData> newDocumentDatas) { List <IContentItem> contentItems = new List <IContentItem>(); foreach (var item in newDocumentDatas) { if (item is FieldDocumentData) { contentItems.Add(new FieldContent((item as FieldDocumentData).Key, (item as FieldDocumentData).Value)); } if (item is ListDocumentData) { ListContent listContent = new ListContent(item.Key); if ((item as ListDocumentData).Fields.Count != 0) { for (int i = 0; i < (item as ListDocumentData).Fields[0].Values.Count; i++) { ListItemContent listcontentItems = new ListItemContent(); foreach (var item1 in (item as ListDocumentData).Fields) { listcontentItems.AddField((item1 as FieldsDocumentData).Key, (item1 as FieldsDocumentData).Values[i]); } foreach (var item1 in (item as ListDocumentData).Tables) { TableContent tableContent = new TableContent(item1.Key); if ((item1 as TableDocumentData).Fields.Count != 0) { for (int j = ((item1 as TableDocumentData).Fields[0].Values.Count / (item as ListDocumentData).Fields[0].Values.Count) * i; j < ((item1 as TableDocumentData).Fields[0].Values.Count / (item as ListDocumentData).Fields[0].Values.Count) + (((item1 as TableDocumentData).Fields[0].Values.Count / (item as ListDocumentData).Fields[0].Values.Count) * i); j++) { List <IContentItem> tableRowContent = new List <IContentItem>(); foreach (var item2 in (item1 as TableDocumentData).Fields) { tableRowContent.Add(new FieldContent((item2 as FieldsDocumentData).Key, (item2 as FieldsDocumentData).Values[j])); } tableContent.AddRow(tableRowContent.ToArray()); } } listcontentItems.AddTable(tableContent); } listContent.AddItem(listcontentItems); } } contentItems.Add(listContent); } if (item is TableDocumentData) { TableContent tableContent = new TableContent(item.Key); if ((item as TableDocumentData).Fields.Count != 0) { for (int i = 0; i < (item as TableDocumentData).Fields[0].Values.Count; i++) { List <IContentItem> tableRowContent = new List <IContentItem>(); foreach (var item1 in (item as TableDocumentData).Fields) { tableRowContent.Add(new FieldContent((item1 as FieldsDocumentData).Key, (item1 as FieldsDocumentData).Values[i])); } tableContent.AddRow(tableRowContent.ToArray()); } } contentItems.Add(tableContent); } } var valuesToFill = new Content(contentItems.ToArray()); using (var outputDocument = new TemplateProcessor(fileName).SetRemoveContentControls(true))//true false { outputDocument.FillContent(valuesToFill); outputDocument.SaveChanges(); } }
private Content GetContent(List <ProjectReport> template, ApplicationUser user, DateTime firstDate, DateTime lastDate, Utils utils) { List <Appendix> appendices = new List <Appendix>(); int count = 1; var listContentTwo = ListContent.Create("Projects List"); for (int i = 0; i < template.Count; i++) { List <TableRowContent> tableRowContent = new List <TableRowContent>(); for (int j = 0; j < template[i].Modules.Count; j++) { List <FieldContent> fieldContents = new List <FieldContent>(); fieldContents.Add(new FieldContent("count", (j + 1).ToString())); fieldContents.Add(new FieldContent("Name", template[i].Modules[j].Module.Name)); string desc = ""; string status = ""; string date = ""; string cause = ""; string note = ""; for (int x = 0; x < template[i].Modules[j].Tasks.Count; x++) { if (template[i].Modules[j].Tasks[x].Name is null) { desc += " " + (x + 1).ToString() + ". "; } else { desc += " " + (x + 1).ToString() + ". " + template[i].Modules[j].Tasks[x].Name; } DateTime firstDate1 = template[i].Modules[j].Tasks[x].CreateDate; DateTime updateDate = template[i].Modules[j].Tasks[x].UpdateDate; DateTime dateTime = DateTime.Now; if (template[i].Modules[j].Tasks[x].StatusId == 1) { status += " " + (x + 1).ToString() + ". " + "В процессе"; int raznica = (dateTime - firstDate1).Days; date += " " + (x + 1).ToString() + ". " + raznica.ToString() + " дней"; } else { status += " " + (x + 1).ToString() + ". " + "Выполнено"; int raznica = (updateDate - firstDate1).Days; date += " " + (x + 1).ToString() + ". " + raznica.ToString() + " дней"; } if (template[i].Modules[j].Tasks[x].Appendix is null) { cause += " " + (x + 1).ToString() + ". "; } else { appendices.Add(template[i].Modules[j].Tasks[x].Appendix); cause += " " + (x + 1).ToString() + ". Примечание " + count.ToString(); count++; } if (template[i].Modules[j].Tasks[x].Note is null) { note += " " + (x + 1).ToString() + ". "; } else { note += " " + (x + 1).ToString() + ". " + template[i].Modules[j].Tasks[x].Note; } } fieldContents.Add(new FieldContent("Description", desc)); fieldContents.Add(new FieldContent("status", status)); fieldContents.Add(new FieldContent("date", date)); fieldContents.Add(new FieldContent("cause", note)); fieldContents.Add(new FieldContent("note", cause)); tableRowContent.Add(new TableRowContent(fieldContents)); } listContentTwo.AddItem(new ListItemContent("Project", "Проект: " + template[i].Project.Name) .AddTable(TableContent.Create("Team members", tableRowContent))); } ListContent imageList = new ListContent("Scientists List"); if (appendices.Count > 0) { for (int i = 0; i < appendices.Count; i++) { string uploadPath = Path.Combine(hostingEnvironment.WebRootPath, "images"); string fileName = appendices[i].FileName; string FilePath = Path.Combine(uploadPath, fileName); //appendices[i].FileName.CopyTo(new FileStream(FilePath, FileMode.Create)); imageList.AddItem(new FieldContent("CountImage", "Примечание " + (i + 1).ToString()), new ImageContent("Photo", System.IO.File.ReadAllBytes(FilePath)), new FieldContent("NameImage", appendices[i].Name)); } } if (imageList.Items == null) { imageList.AddItem(new FieldContent("CountImage", ""), new FieldContent("NameImage", "")); } var valuesToFill = new Content( listContentTwo, imageList, new FieldContent("reportName", "Отчет о выполненных задачах"), new FieldContent("reportDate", "За период с " + firstDate.ToString("D") + " по " + lastDate.ToString("D")), new FieldContent("employeePosition", user.Position.Name), new FieldContent("employeeQualification", user.QualificationLevel.Name), new FieldContent("First Parameter", utils.firstParameter), new FieldContent("Second Parameter", utils.secondParameter), new FieldContent("Third Parameter", utils.thirdParameter), new FieldContent("employeePositionTwo", user.Position.Name), new FieldContent("employeeName", user.UserName)); return(valuesToFill); }
public void Accept() { if (characterText.text != "" && statText.text != "") { if (editing) { if (characterText.text == editCharacter.text) { saving.saveFile.data[editCharacter.text] = Convert.ToInt32(statText.text); editCharacter.text = characterText.text; editStat.text = statText.text; gameObject.SetActive(false); error.text = ""; saving.Save(); listContent.SortList(); } else { bool found = false; foreach (KeyValuePair <string, int> entry in saving.saveFile.data) { if (entry.Key == characterText.text) { found = true; } } if (!found) { saving.saveFile.data.Remove(editCharacter.text); saving.saveFile.data.Add(characterText.text, Convert.ToInt32(statText.text)); saving.Save(); editCharacter.text = characterText.text; editStat.text = statText.text; gameObject.SetActive(false); error.text = ""; saving.Save(); listContent.SortList(); } else { error.text = "A character with that name already exists!"; } } } else { bool found = false; foreach (KeyValuePair <string, int> entry in saving.saveFile.data) { if (entry.Key == characterText.text) { found = true; } } if (!found) { listContent.AddItem(characterText.text, statText.text); gameObject.SetActive(false); error.text = ""; } else { error.text = "A character with that name already exists!"; } } } else { error.text = "Please fill out both fields!"; } }