public void ExportToWord(Docx.DocX doc) { // Skip encrypted scenes. var scenes = Scenes.Where(i => !i.IsEncrypted).OrderBy(i => i.SortIndex).ToList(); if (scenes.Count > 0) { // Export chapter name. Xceed.Document.NET.Paragraph chapterHeader = doc.InsertParagraph(); chapterHeader.StyleId = "Heading1"; chapterHeader.Append(Model.Name); doc.InsertParagraph(); doc.InsertParagraph(); doc.InsertParagraph(); for (int i = 0; i < scenes.Count; i++) { SceneViewModel scene = scenes[i]; scene.ExportToWord(doc); if (i < Scenes.Count - 1) { Xceed.Document.NET.Paragraph p = doc.InsertParagraph(); p.StyleId = "SceneBreak"; p.Append("\n*\t\t*\t\t*\n"); } } doc.Paragraphs.Last().InsertPageBreakAfterSelf(); } }
public void GetLineSpacingInfo(uint line, string text, Xceed.Document.NET.Paragraph p) { try { if (p.LineSpacing == 0) { throw new Exception(); } else if (Math.Round(p.LineSpacing, 2, MidpointRounding.AwayFromZero) != Math.Round(DefaultLineSpacing, 2, MidpointRounding.AwayFromZero)) { ResultErrors += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - используется неверный междустрочный интервал: " + (p.LineSpacing / 12).ToString("0.00").Replace(',', '.') + $" вместо {(DefaultLineSpacing / 12).ToString("0.00").Replace(',', '.')} строки" + '\n'; if (checkCopy) { if (checkErrors) { p.InsertText($"\n--- Используется неверный междустрочный интервал: {(p.LineSpacing / 12).ToString("0.00").Replace(',', '.')} вместо {(DefaultLineSpacing / 12).ToString("0.00").Replace(',', '.')} строки ---"); } } } } catch { ResultWarnings += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - предположительно используется неверный междустрочный интервал." + '\n'; if (checkCopy) { if (checkWarnings) { p.InsertText("\n--- Предположительно используется неверный междустрочный интервал. ---"); } } } }
public static void AddParagraph(Paragraph paragraph, Docx.DocX doc) { Xceed.Document.NET.Paragraph p = doc.InsertParagraph(); foreach (var inline in paragraph.Inlines) { AddInline(inline, p); } }
private void CreateThirdParagraph() { Xceed.Document.NET.Paragraph disciplineContent = document.InsertParagraph("\t3. Содержание дисциплины: "). Font("Times New Roman"). FontSize(12). Bold(); }
private void CreateSixthParagraph(string developerReference) { Xceed.Document.NET.Paragraph developer = document.InsertParagraph("\t6. Разработчик: "). Font("Times New Roman"). FontSize(12). Bold(); developer.Append(developerReference).Font("Times New Roman").FontSize(12); }
private void CreateFirstParagraph(string subjectName, string subjectIndex, string subjectIndexDecoding) { Xceed.Document.NET.Paragraph disciplinePlace = document.InsertParagraph("\t1. Место дисциплины в структуре ОПОП."). Font("Times New Roman"). FontSize(12). Bold(); disciplinePlace.AppendLine($"\tДисциплина «{subjectName}» относится к дисциплинам {subjectIndexDecoding} {subjectIndex}"). Font("Times New Roman"). FontSize(12); }
private void CreateFourthParagraph(string competencies) { Xceed.Document.NET.Paragraph plannedResults = document.InsertParagraph("\t4. Планируемые результаты обучения по дисциплине."). Font("Times New Roman"). FontSize(12). Bold(); plannedResults.AppendLine("\tВ результате освоения дисциплины у студента должны быть сформированы следующие компетенции:"). Font("Times New Roman"). FontSize(12); plannedResults.AppendLine(competencies). Font("Times New Roman"). FontSize(12); }
private void CreateSecondParagraph(int creditUnits) { Xceed.Document.NET.Paragraph disciplineScope = document.InsertParagraph("\t2. Объем дисциплины: "). Font("Times New Roman"). FontSize(12). Bold(); if (creditUnits != 0) { disciplineScope.Append(ChangeDeclination(creditUnits)). Font("Times New Roman"). FontSize(12); } }
private void CreateFifthParagraph(bool isExam, bool isTest) { Xceed.Document.NET.Paragraph controlForms = document.InsertParagraph("\t5. Форма контроля: "). Font("Times New Roman"). FontSize(12). Bold(); if (isTest && isExam) { controlForms.Append("зачёт/экзамен.").Font("Times New Roman").FontSize(12); } else if (isExam || !isExam && !isTest) { controlForms.Append("экзамен.").Font("Times New Roman").FontSize(12); } else if (isTest) { controlForms.Append("зачёт.").Font("Times New Roman").FontSize(12); } }
public void GetFontInfo(uint line, string text, Xceed.Document.NET.Paragraph p) { HashSet <string> usingFonts = new HashSet <string>(); try { foreach (var magic in p.MagicText) { /*foreach (var s in styles) * { * // some code * }*/ if (magic.formatting.FontFamily.Name != DefaultFont) { if (usingFonts.Contains(magic.formatting.FontFamily.Name) == false) { usingFonts.Add(magic.formatting.FontFamily.Name); ResultErrors += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - используется неверный шрифт: " + magic.formatting.FontFamily.Name + '\n'; if (checkCopy) { if (checkErrors) { p.InsertText($"\n--- Используется неверный шрифт: {magic.formatting.FontFamily.Name}. ---"); } } } } else if (magic.formatting.FontFamily == null & usingFonts.Contains("null") == false) { usingFonts.Add("null"); ResultWarnings += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - предположительно используется неверный шрифт. Возможные варианты:" + '\n'; if (checkCopy) { if (checkWarnings) { p.InsertText("\n--- Предположительно используется неверный шрифт. Возможные варианты: ---"); } } foreach (var f in fontTable.ChildElements) { Font font = f as Font; if (!font.Name.ToString().Contains(DefaultFont) & !font.Name.ToString().Contains("serif")) { ResultWarnings += "* " + font.Name + '\n'; } if (checkCopy) { if (checkWarnings) { p.InsertText($"\n* {font.Name}"); } } } } } usingFonts.Clear(); } catch { ResultWarnings += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - предположительно используется неверный шрифт. Возможные варианты:" + '\n'; if (checkCopy) { if (checkWarnings) { p.InsertText("\n--- Предположительно используется неверный шрифт. Возможные варианты: ---"); } } foreach (var f in fontTable.ChildElements) { Font font = f as Font; if (!font.Name.ToString().Contains(DefaultFont) & !font.Name.ToString().Contains("serif")) { ResultWarnings += "* " + font.Name + '\n'; } if (checkCopy) { if (checkWarnings) { p.InsertText($"\n* {font.Name}"); } } } } }
public void GetAlignmentInfo(uint line, string text, Xceed.Document.NET.Paragraph p) { try { if (p.Alignment.ToString() != DefaultAlignment) { if (p.Alignment.ToString() == "center") { ResultErrors += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - используется выравнивание по центру." + '\n'; if (checkCopy) { if (checkErrors) { p.InsertText("\n--- Используется выравнивание по центру. ---"); } } } else if (p.Alignment.ToString() == "left") { ResultErrors += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - используется выравнивание по левому краю." + '\n'; if (checkCopy) { if (checkErrors) { p.InsertText("\n--- Используется выравнивание по левому краю. ---"); } } } else if (p.Alignment.ToString() == "right") { ResultErrors += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - используется выравнивание по правому краю." + '\n'; if (checkCopy) { if (checkErrors) { p.InsertText("\n--- Используется выравнивание по правому краю. ---"); } } } else if (p.Alignment.ToString() == "both") { ResultErrors += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - используется выравнивание по ширине." + '\n'; if (checkCopy) { if (checkErrors) { p.InsertText("\n--- Используется выравнивание по ширине. ---"); } } } else { ResultWarnings += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - предположительно используется неверное выравнивание." + '\n'; if (checkCopy) { if (checkWarnings) { p.InsertText("\n--- Предположительно используется неверное выравнивание. ---"); } } } } } catch { } }
public void GetFontSizeInfo(uint line, string text, Xceed.Document.NET.Paragraph p) { HashSet <double?> usingSize = new HashSet <double?>(); try { foreach (var magic in p.MagicText) { if (magic.formatting.Size != DefaultFontSize & usingSize.Contains(magic.formatting.Size) == false & magic.formatting.Size != null & magic.formatting.Size != 0) { usingSize.Add(magic.formatting.Size); ResultErrors += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - используется неверный кегль: " + magic.formatting.Size + '\n'; if (checkCopy) { if (checkErrors) { p.InsertText($"\n--- Используется неверный кегль: {magic.formatting.Size} ---"); } } usingSize.Add(magic.formatting.Size); } else if ((magic.formatting.Size == null || magic.formatting.Size == 0) & usingSize.Contains(DefaultOpenXmlFontSize / 2) == false) { if (DefaultFontSize != 0 & DefaultOpenXmlFontSize != 0 & (DefaultOpenXmlFontSize / 2) != DefaultFontSize) { ResultWarnings += "Строка " + line + " (начинается со слов \"" + text + "\" )" + $" - предположительно используется неверный кегль. Возможно: {DefaultOpenXmlFontSize / 2}" + '\n'; if (checkCopy) { if (checkWarnings) { p.InsertText($"\n--- Предположительно используется неверный кегль. Возможно: {DefaultOpenXmlFontSize / 2} ---"); } } usingSize.Add(DefaultOpenXmlFontSize / 2); } else if (usingSize.Contains(0) == false) { ResultWarnings += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - предположительно используется неверный кегль. " + '\n'; if (checkCopy) { if (checkWarnings) { p.InsertText("\n--- Предположительно используется неверный кегль. ---"); } } usingSize.Add(0); } } } usingSize.Clear(); } catch { ResultWarnings += "Строка " + line + " (начинается со слов \"" + text + "\" )" + " - предположительно используется неверный кегль. " + '\n'; if (checkCopy) { if (checkWarnings) { p.InsertText("\n--- Предположительно используется неверный кегль. ---"); } } } }
public void ExportToWord(Docx.DocX doc) { // Format title page of the document. Xceed.Document.NET.Paragraph p = doc.InsertParagraph(); p.Append("\n\n" + Model.Name); p.StyleId = "Title"; if (!string.IsNullOrWhiteSpace(Model.Subtitle)) { p = doc.InsertParagraph(); p.Append(Model.Subtitle); p.StyleId = "Subtitle"; } if (!string.IsNullOrWhiteSpace(Model.Author)) { p = doc.InsertParagraph(); p.Append("\n\n" + Model.Author); p.StyleId = "Subtitle"; } p.InsertPageBreakAfterSelf(); // Insert copyright page. if (Model.FlowDocumentId.HasValue) { FlowDocument copyrightFd = new FlowDocument(Model.Connection); copyrightFd.id = Model.FlowDocumentId.Value; copyrightFd.Load(); FlowDocumentViewModel copyrightVm = new FlowDocumentViewModel(copyrightFd, DialogOwner); foreach (WinDoc.Block block in copyrightVm.Document.Blocks) { if (block is WinDoc.Paragraph) { FlowDocumentExporter.AddParagraph((WinDoc.Paragraph)block, doc); } } p.InsertPageBreakAfterSelf(); } // Insert eBook table of contents. // This doesn't make sense to me. Xceed's documentation says "A key-value dictionary where the key is a TableOfContentSwitches // and the value is the parameter of the switch." // I have no idea what the string values are supposed to be. Empty strings seem to work. Dictionary <Xceed.Document.NET.TableOfContentsSwitches, string> tocParams = new Dictionary <Xceed.Document.NET.TableOfContentsSwitches, string>(); tocParams[Xceed.Document.NET.TableOfContentsSwitches.H] = ""; // TOC entries are clickable hyperlinks. tocParams[Xceed.Document.NET.TableOfContentsSwitches.N] = ""; // Omits page numbers. tocParams[Xceed.Document.NET.TableOfContentsSwitches.Z] = ""; // Hides tab leader and page numbers...? tocParams[Xceed.Document.NET.TableOfContentsSwitches.U] = ""; // Uses the applied paragraph outline level...? Xceed.Document.NET.TableOfContents toc = doc.InsertTableOfContents("Table of Contents", tocParams); doc.Paragraphs.Last().InsertPageBreakAfterSelf(); for (int i = 0; i < Chapters.Count; i++) { ChapterViewModel chapter = Chapters[i]; chapter.ExportToWord(doc); } }
public static void AddInline(Inline inline, Xceed.Document.NET.Paragraph p, Xceed.Document.NET.Formatting inheritFormat = null) { if (inline is Run) { Run run = (Run)inline; Xceed.Document.NET.Formatting f = new Xceed.Document.NET.Formatting(); Color c = (run.Foreground as SolidColorBrush).Color; f.FontColor = System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B); f.FontFamily = new Xceed.Document.NET.Font(run.FontFamily.Source); if (run.FontWeight == FontWeights.Bold) { f.Bold = true; } if (run.FontStyle == FontStyles.Italic) { f.Italic = true; } foreach (var dec in run.TextDecorations) { if (dec.Location == TextDecorationLocation.Underline) { f.UnderlineStyle = Xceed.Document.NET.UnderlineStyle.singleLine; f.UnderlineColor = f.FontColor; } } f.Size = run.FontSize; if (inheritFormat != null) { f = inheritFormat; } p.Append(run.Text, f); } else if (inline is Span) { Span span = (Span)inline; Xceed.Document.NET.Formatting f = new Xceed.Document.NET.Formatting(); Color c = (span.Foreground as SolidColorBrush).Color; f.FontColor = System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B); f.FontFamily = new Xceed.Document.NET.Font(span.FontFamily.Source); if (span.FontWeight == FontWeights.Bold) { f.Bold = true; } if (span.FontStyle == FontStyles.Italic) { f.Italic = true; } foreach (var dec in span.TextDecorations) { if (dec.Location == TextDecorationLocation.Underline) { f.UnderlineStyle = Xceed.Document.NET.UnderlineStyle.singleLine; f.UnderlineColor = f.FontColor; } } f.Size = span.FontSize; if (inheritFormat != null) { f = inheritFormat; } foreach (var spanInline in span.Inlines) { AddInline(spanInline, p, f); } } }
private void SaveReport(object sender, EventArgs e) { Bitmap bmpStats = DrawControlToBitMap(cartesianChart1); Bitmap bmpBar = DrawControlToBitMap(cartesianChart2); cartesianChart1.DrawToBitmap(bmpStats, new Rectangle(0, 0, bmpStats.Width, bmpStats.Height)); cartesianChart2.DrawToBitmap(bmpBar, new Rectangle(0, 0, bmpBar.Width, bmpBar.Height)); foreach (var country in countries) { if (countryBox.Text == country) { int fontSize = 12; int fontTitleSize = 16; string font = "Calibri"; bmpStats.Save($"{picturePath}{country}_stats.png", ImageFormat.Png); bmpBar.Save($"{picturePath}{country}_bar.png", ImageFormat.Png); var doc = DocX.Create($"{reportsPath}\\{country} Report.docx"); string title = $"{country} Covid-19 Report from {startDateBox.Text} to {endDateBox.Text}"; Xceed.Document.NET.Formatting titleFormat = new Xceed.Document.NET.Formatting(); titleFormat.FontFamily = new Xceed.Document.NET.Font(font); titleFormat.Size = fontTitleSize; Xceed.Document.NET.Paragraph repTitle = doc.InsertParagraph(title, false, titleFormat); repTitle.Alignment = Xceed.Document.NET.Alignment.center; Xceed.Document.NET.Image imgStats = doc.AddImage($"{picturePath}{country}_stats.png"); Xceed.Document.NET.Picture statsPic = imgStats.CreatePicture(); statsPic.Width = 500; statsPic.Height = 200; Xceed.Document.NET.Paragraph statsPar = doc.InsertParagraph(); statsPar.AppendPicture(statsPic); Xceed.Document.NET.Table table1 = doc.AddTable(3, 2); table1.Alignment = Xceed.Document.NET.Alignment.center; Xceed.Document.NET.Formatting table1Format = new Xceed.Document.NET.Formatting(); table1Format.FontFamily = new Xceed.Document.NET.Font(font); table1Format.Size = fontTitleSize; doc.InsertParagraph("General Stats ", false, table1Format).Alignment = Xceed.Document.NET.Alignment.center; Xceed.Document.NET.Image imgBar = doc.AddImage($"{picturePath}{country}_bar.png"); Xceed.Document.NET.Picture barPic = imgBar.CreatePicture(); barPic.Width = 200; barPic.Height = 200; Xceed.Document.NET.Paragraph barPar = doc.InsertParagraph(); barPar.AppendPicture(barPic).Alignment = Xceed.Document.NET.Alignment.center; table1.Rows[0].Cells[0].Paragraphs.First().Append("Confirmed Cases: ").Font(font).FontSize(fontSize); table1.Rows[1].Cells[0].Paragraphs.First().Append("Number of Recoveries: ").Font(font).FontSize(fontSize); table1.Rows[2].Cells[0].Paragraphs.First().Append("Number of Deaths: ").Font(font).FontSize(fontSize); table1.Rows[0].Cells[1].Paragraphs.First().Append(numConfirmed.ToString()).Font(font).FontSize(fontSize); table1.Rows[1].Cells[1].Paragraphs.First().Append(numRecoveries.ToString()).Font(font).FontSize(fontSize); table1.Rows[2].Cells[1].Paragraphs.First().Append(deathCount.ToString()).Font(font).FontSize(fontSize); doc.InsertTable(table1); doc.InsertParagraph(" "); Xceed.Document.NET.Formatting table2Format = new Xceed.Document.NET.Formatting(); table2Format.FontFamily = new Xceed.Document.NET.Font(font); table2Format.Size = fontTitleSize; doc.InsertParagraph($"Complete Stats of Covid-19 in {country}", false, table2Format).Alignment = Xceed.Document.NET.Alignment.left; doc.InsertParagraph(" "); Xceed.Document.NET.Table table2 = doc.AddTable(numRows, 7); table2.Alignment = Xceed.Document.NET.Alignment.left; table2.Rows[0].Cells[0].Paragraphs.First().Append("Dates").Font(font).FontSize(fontSize); table2.Rows[0].Cells[1].Paragraphs.First().Append("Confirmed Cases").Font(font).FontSize(fontSize); table2.Rows[0].Cells[2].Paragraphs.First().Append("Recoveries").Font(font).FontSize(fontSize); table2.Rows[0].Cells[3].Paragraphs.First().Append("Deaths").Font(font).FontSize(fontSize); table2.Rows[0].Cells[4].Paragraphs.First().Append("Number of Increase in Confirmed Cases").Font(font).FontSize(fontSize); table2.Rows[0].Cells[5].Paragraphs.First().Append("Number of Increase in Recoveries").Font(font).FontSize(fontSize); table2.Rows[0].Cells[6].Paragraphs.First().Append("Number of Increase in Deaths").Font(font).FontSize(fontSize); foreach (var data in confirmed) { if (country == data.Key) { int i = 1; foreach (var day in data.Value) { if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key) { table2.Rows[i].Cells[0].Paragraphs.First().Append(day.Key.ToShortDateString()).Font(font).FontSize(fontSize); table2.Rows[i].Cells[1].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize); i++; } } } } foreach (var data in recoveries) { if (country == data.Key) { int i = 1; foreach (var day in data.Value) { if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key) { table2.Rows[i].Cells[2].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize); i++; } } } } foreach (var data in deaths) { if (country == data.Key) { int i = 1; foreach (var day in data.Value) { if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key) { table2.Rows[i].Cells[3].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize); i++; } } } } foreach (var data in incConfirmed) { if (country == data.Key) { int i = 1; foreach (var day in data.Value) { if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key) { table2.Rows[i].Cells[4].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize); i++; } } } } foreach (var data in incRecoveries) { if (country == data.Key) { int i = 1; foreach (var day in data.Value) { if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key) { table2.Rows[i].Cells[5].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize); i++; } } } } foreach (var data in incDeaths) { if (country == data.Key) { int i = 1; foreach (var day in data.Value) { if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key) { table2.Rows[i].Cells[6].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize); i++; } } } } table2.Alignment = Xceed.Document.NET.Alignment.left; doc.InsertTable(table2); doc.Save(); MessageBox.Show($"File saved at {reportsPath}\\{country} Report.docx.\nChoose either to Upload or Reset the Report", "Save Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); } } processBtn.Enabled = false; saveBtn.Enabled = false; uploadBtn.Enabled = true; resetBtn.Enabled = true; countryBox.Enabled = false; startDateBox.Enabled = false; endDateBox.Enabled = false; }