/// <summary> /// Create a document and add headers/footers with tables and pictures, paragraphs and charts. /// </summary> public static void CompanyReport() { Console.WriteLine("\tCompanyReport()"); // Create a new document. using (var document = DocX.Create(MiscellaneousSample.MiscellaneousSampleOutputDirectory + @"CompanyReport.docx")) { // Add headers and footers. document.AddHeaders(); document.AddFooters(); // Define the pages header's picture in a Table. Odd and even pages will have the same headers. var oddHeader = document.Headers.Odd; var headerFirstTable = oddHeader.InsertTable(1, 2); headerFirstTable.Design = TableDesign.ColorfulGrid; headerFirstTable.AutoFit = AutoFit.Window; var upperLeftParagraph = oddHeader.Tables[0].Rows[0].Cells[0].Paragraphs[0]; var logo = document.AddImage(MiscellaneousSample.MiscellaneousSampleResourcesDirectory + @"Phone.png"); upperLeftParagraph.AppendPicture(logo.CreatePicture(30, 100)); upperLeftParagraph.Alignment = Alignment.left; // Define the pages header's text in a Table. Odd and even pages will have the same footers. var upperRightParagraph = oddHeader.Tables[0].Rows[0].Cells[1].Paragraphs[0]; upperRightParagraph.Append("Toms Telecom Annual report").Color(Color.White); upperRightParagraph.SpacingBefore(5d); upperRightParagraph.Alignment = Alignment.right; // Define the pages footer's picture in a Table. var oddFooter = document.Footers.Odd; var footerFirstTable = oddFooter.InsertTable(1, 2); footerFirstTable.Design = TableDesign.ColorfulGrid; footerFirstTable.AutoFit = AutoFit.Window; var lowerRightParagraph = oddFooter.Tables[0].Rows[0].Cells[1].Paragraphs[0]; lowerRightParagraph.AppendPicture(logo.CreatePicture(30, 100)); lowerRightParagraph.Alignment = Alignment.right; // Define the pages footer's text in a Table var lowerLeftParagraph = oddFooter.Tables[0].Rows[0].Cells[0].Paragraphs[0]; lowerLeftParagraph.Append("Toms Telecom 2016").Color(Color.White); lowerLeftParagraph.SpacingBefore(5d); // Define Data in first page : a Paragraph. var paragraph = document.InsertParagraph(); paragraph.AppendLine("Toms Telecom Annual report\n2016").Bold().FontSize(35).SpacingBefore(150d); paragraph.Alignment = Alignment.center; paragraph.InsertPageBreakAfterSelf(); // Define Data in second page : a Bar Chart. document.InsertParagraph("").SpacingAfter(150d); var barChart = new BarChart(); var sales = CompanyData.CreateSales(); var salesSeries = new Series("Sales Per Month"); salesSeries.Color = Color.GreenYellow; salesSeries.Bind(sales, "Month", "Sales"); barChart.AddSeries(salesSeries); document.InsertChart(barChart); document.InsertParagraph("Sales were 11% greater in 2016 compared to 2015, with the usual drop during spring time.").SpacingBefore(35d).InsertPageBreakAfterSelf(); // Define Data in third page : a Line Chart. document.InsertParagraph("").SpacingAfter(150d); var lineChart = new LineChart(); var calls = CompanyData.CreateCallNumber(); var callSeries = new Series("Call Number Per Month"); callSeries.Bind(calls, "Month", "Calls"); lineChart.AddSeries(callSeries); document.InsertChart(lineChart); document.InsertParagraph("The number of calls received was much lower in 2016 compared to 2015, by 31%. Winter is still the busiest time of year.").SpacingBefore(35d); // Save this document to disk. document.Save(); Console.WriteLine("\tCreated: CompanyReport.docx\n"); } }