//Exports and saves the chart as Word document. #region DocIO private void buttonDocIO_Click(object sender, EventArgs e) { try { exportFileName = fileName + ".doc"; string file = fileName + ".gif"; if (!System.IO.File.Exists(file)) { this.chartControl1.SaveImage(file); } //Create a new document WordDocument document = new WordDocument(); //Adding a new section to the document. IWSection section = document.AddSection(); //Adding a paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Writing text. paragraph.AppendText("Essential Chart"); //Adding a new paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting chart. paragraph.AppendPicture(Image.FromFile(file)); //Save the Document to disk. document.Save(exportFileName, Syncfusion.DocIO.FormatType.Doc); OpenFile("DocIO", exportFileName); } catch (Exception ex) { this.toolStripStatusLabel1.Text = "Chart Export failed."; Console.WriteLine(ex.ToString()); } }
private void OnButtonClicked(object sender, EventArgs e) { Assembly assembly = Assembly.GetExecutingAssembly(); //A new document is created. WordDocument document = new WordDocument(); //Add new section to the Word document IWSection section = document.AddSection(); //Set page margins of the section section.PageSetup.Margins.All = 72; //Add new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Apply heading style to the title paragraph paragraph.ApplyStyle(BuiltinStyle.Heading1); //Apply center alignment to the paragraph paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; //Append text to the paragraph paragraph.AppendText("Northwind Management Report").CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); //Add new paragraph paragraph = section.AddParagraph(); //Get chart data from xml file List <ProductDetail> Products = LoadXMLData(); //Create and Append chart to the paragraph WChart pieChart = document.LastParagraph.AppendChart(446, 270); //Set chart data pieChart.ChartType = OfficeChartType.Pie; pieChart.ChartTitle = "Best Selling Products"; pieChart.ChartTitleArea.FontName = "Calibri (Body)"; pieChart.ChartTitleArea.Size = 14; for (int i = 0; i < Products.Count; i++) { ProductDetail product = Products[i]; pieChart.ChartData.SetValue(i + 2, 1, product.ProductName); pieChart.ChartData.SetValue(i + 2, 2, product.Sum); } //Create a new chart series with the name “Sales” IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales"); pieSeries.Values = pieChart.ChartData[2, 2, 11, 2]; //Setting data label pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true; pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; //Setting background color pieChart.ChartArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.PlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1]; MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Word2013); document.Close(); if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save("PieChart.docx", "application/msword", stream, m_context); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { Assembly execAssem = typeof(BarChartDemo).GetTypeInfo().Assembly; //A new document is created. WordDocument document = new WordDocument(); //Add new section to the Word document IWSection section = document.AddSection(); //Set page margins of the section section.PageSetup.Margins.All = 72; //Add new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Apply heading style to the title paragraph paragraph.ApplyStyle(BuiltinStyle.Heading1); //Apply center alignment to the paragraph paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Append text to the paragraph paragraph.AppendText("Northwind Management Report").CharacterFormat.TextColor = Syncfusion.DocIO.DLS.Color.FromArgb(46, 116, 181); //Add new paragraph paragraph = section.AddParagraph(); //Set before spacing to the paragraph paragraph.ParagraphFormat.BeforeSpacing = 20; //Load the excel template as stream Stream excelStream = execAssem.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Excel_Template.xlsx"); //Create and Append chart to the paragraph with excel stream as parameter WChart barChart = paragraph.AppendChart(excelStream, 1, "B2:C6", 470, 300); //Set chart data barChart.ChartType = OfficeChartType.Bar_Clustered; barChart.ChartTitle = "Purchase Details"; barChart.ChartTitleArea.FontName = "Calibri (Body)"; barChart.ChartTitleArea.Size = 14; //Set name to chart series barChart.Series[0].Name = "Sum of Purchases"; barChart.Series[1].Name = "Sum of Future Expenses"; //Set Chart Data table barChart.HasDataTable = true; barChart.DataTable.HasBorders = true; barChart.DataTable.HasHorzBorder = true; barChart.DataTable.HasVertBorder = true; barChart.DataTable.ShowSeriesKeys = true; barChart.HasLegend = false; //Setting background color barChart.ChartArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(208, 206, 206); barChart.PlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(208, 206, 206); //Setting line pattern to the chart area barChart.PrimaryCategoryAxis.Border.LinePattern = OfficeChartLinePattern.None; barChart.PrimaryValueAxis.Border.LinePattern = OfficeChartLinePattern.None; barChart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; barChart.PrimaryValueAxis.MajorGridLines.Border.LineColor = Syncfusion.Drawing.Color.FromArgb(175, 171, 171); //Set label for primary catagory axis barChart.PrimaryCategoryAxis.CategoryLabels = barChart.ChartData[2, 1, 6, 1]; #region Saving Document SaveDocx(document); #endregion }
private void Button_Click_1(object sender, RoutedEventArgs e) { Assembly execAssem = typeof(Common.MainPage).GetTypeInfo().Assembly; //A new document is created. WordDocument document = new WordDocument(); //Add new section to the Word document IWSection section = document.AddSection(); //Set page margins of the section section.PageSetup.Margins.All = 72; //Add new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Apply heading style to the title paragraph paragraph.ApplyStyle(BuiltinStyle.Heading1); //Apply center alignment to the paragraph paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Append text to the paragraph paragraph.AppendText("Northwind Management Report").CharacterFormat.TextColor = Syncfusion.DocIO.DLS.Color.FromArgb(46, 116, 181); //Add new paragraph paragraph = section.AddParagraph(); //Get chart data from xml file List <ProductDetail> Products = LoadXMLData(); //Create and Append chart to the paragraph WChart pieChart = document.LastParagraph.AppendChart(446, 270); //Set chart data pieChart.ChartType = OfficeChartType.Pie; pieChart.ChartTitle = "Best Selling Products"; pieChart.ChartTitleArea.FontName = "Calibri (Body)"; pieChart.ChartTitleArea.Size = 14; for (int i = 0; i < Products.Count; i++) { ProductDetail product = Products[i]; pieChart.ChartData.SetValue(i + 2, 1, product.ProductName); pieChart.ChartData.SetValue(i + 2, 2, product.Sum); } //Create a new chart series with the name “Sales” IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales"); pieSeries.Values = pieChart.ChartData[2, 2, 11, 2]; //Setting data label pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true; pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; //Setting background color pieChart.ChartArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.PlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1]; #region Saving Document MemoryStream ms = new MemoryStream(); SaveDocx(document); #endregion }
private void AddSubsectionTitle(IWSection section, string subsectionTile) { IWParagraph spacingParagraph = section.AddParagraph(); spacingParagraph.AppendText("\n"); IWParagraph title_paragraph = section.AddParagraph(); IWTextRange title_text = title_paragraph.AppendText(subsectionTile); title_text.CharacterFormat.Bold = false; title_text.CharacterFormat.FontName = "Times New Roman"; title_text.CharacterFormat.UnderlineStyle = UnderlineStyle.Single; title_text.CharacterFormat.FontSize = 14; title_paragraph.AppendText("\n"); }
async void GerarArquivoWord() { WordDocument localdocumento = new WordDocument(); IWSection localSection = localdocumento.AddSection(); IWParagraph localparagraph = localSection.AddParagraph(); //CachedImage localimagem = new CachedImage(); //localimagem.Source = "ESFJPDocumento"; // //var localbyte = await localimagem.GetImageAsJpgAsync(); //IWPicture localpicture = localparagraph.AppendPicture(localbyte); var auxiliartexto = "Geral;\r\nProjetos;\r\nMarketing;\r\nPessoas;"; IWTextRange localtexto = localparagraph.AppendText(auxiliartexto); localtexto.CharacterFormat.FontSize = 14; localtexto.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Black; MemoryStream arquivostream = new MemoryStream(); arquivostream.Position = 0; localdocumento.Save(arquivostream, Syncfusion.DocIO.FormatType.Docx); localdocumento.Close(); await DependencyService.Get <ISave>().Save("TesteESFJPDocumento.docx", "application/msword", arquivostream); //Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "TesteESFJPDocumento.docx"); //localdocumento.Open(docStream, Syncfusion.DocIO.FormatType.Docx); }
public ActionResult HeaderandFooter(string Group1) { if (Group1 == null) { return(View()); } // Creating a new document. WordDocument doc = new WordDocument(); // Add a new section to the document. IWSection section1 = doc.AddSection(); // Set the header/footer setup. section1.PageSetup.DifferentFirstPage = true; // Inserting Header Footer to first page InsertFirstPageHeaderFooter(doc, section1); // Inserting Header Footer to all pages InsertPageHeaderFooter(doc, section1); // Add text to the document body section. IWParagraph par; par = section1.AddParagraph(); string basePath = _hostingEnvironment.WebRootPath; string dataPath = basePath + @"/DocIO/WinFAQ.txt"; //Insert Text into the word Document. StreamReader reader = new StreamReader(new FileStream(dataPath, FileMode.Open), System.Text.Encoding.ASCII); string text = reader.ReadToEnd(); par.AppendText(text); reader.Dispose(); reader = null; FormatType type = FormatType.Docx; string filename = "Sample.docx"; string contenttype = "application/vnd.ms-word.document.12"; #region Document SaveOption //Save as .doc format if (Group1 == "WordDoc") { type = FormatType.Doc; filename = "Sample.doc"; contenttype = "application/msword"; } //Save as .xml format else if (Group1 == "WordML") { type = FormatType.WordML; filename = "Sample.xml"; contenttype = "application/msword"; } #endregion Document SaveOption MemoryStream ms = new MemoryStream(); doc.Save(ms, type); doc.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }
/// <summary> /// Encrypt and decrypt in the Word document /// </summary> /// <returns>Return the resultant Word document as stream</returns> public MemoryStream EncryptDecryptDocument(string Group) { WordDocument document = null; if (Group == "Encrypt") { document = new WordDocument(); document.EnsureMinimal(); // Getting last section of the document. IWSection section = document.LastSection; // Adding a paragraph to the section. IWParagraph paragraph = section.AddParagraph(); // Writing text IWTextRange text = paragraph.AppendText("This document was encrypted with password"); text.CharacterFormat.FontSize = 16f; text.CharacterFormat.FontName = "Bitstream Vera Serif"; // Encrypt the document by giving password document.EncryptDocument("syncfusion"); } else { string basePath = @"wwwroot/"; string dataPath = basePath + @"data/docio/security-settings.docx"; FileStream fileStream = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); document = new WordDocument(); //Open an existing template document. document.Open(fileStream, FormatType.Docx, "syncfusion"); // Getting last section of the document. IWSection section = document.LastSection; // Adding a paragraph to the section. IWParagraph paragraph = section.AddParagraph(); // Writing text IWTextRange text = paragraph.AppendText("\nDemo For Document Decryption with Essential DocIO"); text.CharacterFormat.FontSize = 16f; text.CharacterFormat.FontName = "Bitstream Vera Serif"; text = paragraph.AppendText("\nThis document is Decrypted"); text.CharacterFormat.FontSize = 16f; text.CharacterFormat.FontName = "Bitstream Vera Serif"; } FormatType formatType = FormatType.Docx; //Save the document as a stream and retrun the stream using (MemoryStream stream = new MemoryStream()) { //Save the created Word document to MemoryStream document.Save(stream, formatType); document.Close(); stream.Position = 0; return(stream); } }
/// <summary> /// Adds new paragraph into the section /// </summary> /// <param name="section">Represents a section in Word document</param> /// <param name="text">Represents a text to append in paragraph</param> /// <returns>Returns a paragraph to add equation</returns> private IWParagraph AddParagraph(IWSection section, string text) { //Adds new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Adds new paragraph to add text paragraph = section.AddParagraph(); //Appends text to paragraph paragraph.AppendText(text); paragraph.ParagraphFormat.AfterSpacing = 12; paragraph.ParagraphFormat.BeforeSpacing = 12; //Adds new paragraph to add equation paragraph = section.AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 12; return(paragraph); }
private async void MergeCellsOrizzTabellaWord() { //Crea una istanza della classe WordDocument WordDocument document = new WordDocument(); IWSection section = document.AddSection(); section.AddParagraph().AppendText("Horizontal merging of Table cells"); IWTable table = section.AddTable(); table.ResetCells(5, 5); //Specifica il merge orizzontale dalla seconda cella alla quinta cella nella terza riga table.ApplyHorizontalMerge(2, 1, 4); ////Salva e chiudi l'istanza del documento //document.Save("HorizontalMerge.docx", FormatType.Docx); //document.Close(); //Salva il documento su memory stream MemoryStream stream = new MemoryStream(); await document.SaveAsync(stream, FormatType.Docx); //Libera le risorse impegnate dall'istanza WordDocument document.Close(); //Salva lo stream come file di documento Word nella macchina locale StorageFile stFile = await Save(stream, "HorizontalMerge.docx"); DefaultLaunch("HorizontalMerge.docx"); }
public MemoryStream ExportQuizQuestions(DetailsQuizViewModel model) { WordDocument document = new WordDocument(); //Adds new section to the document IWSection section = document.AddSection(); IWParagraph paragraph = section.AddParagraph(); paragraph.ApplyStyle(BuiltinStyle.Heading1); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; paragraph.AppendText($"{model.CategoryName} - {model.Title}"); foreach (var question in model.Questions) { paragraph = section.AddParagraph(); //Applies default numbered list style paragraph.ListFormat.ApplyDefNumberedStyle(); //Adds text to the paragraph paragraph.AppendText($"{question.Value}"); //Continues the list defined paragraph.ListFormat.ContinueListNumbering(); paragraph = section.AddParagraph(); paragraph.ListFormat.IncreaseIndentLevel(); foreach (var answer in question.Answers) { paragraph.AppendText($"{answer.Value}"); //Continues the list defined paragraph.ListFormat.ContinueListNumbering(); paragraph = section.AddParagraph(); } paragraph.ListFormat.DecreaseIndentLevel(); } //Saves the Word document to MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); stream.Position = 0; //Download Word document in the browser return(stream); }
static void Main(string[] args) { //Creates a new Word document WordDocument document = new WordDocument(); //Adds the section into the Word document IWSection section = document.AddSection(); string paraText = "AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."; //Adds the paragraph into the created section IWParagraph paragraph = section.AddParagraph(); //Appends the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries paragraph.AppendTOC(1, 3); //Adds the section into the Word document section = document.AddSection(); //Adds the paragraph into the created section paragraph = section.AddParagraph(); //Adds the text for the headings paragraph.AppendText("First Chapter"); //Sets a built-in heading style. paragraph.ApplyStyle(BuiltinStyle.Heading1); //Adds the text into the paragraph section.AddParagraph().AppendText(paraText); //Adds the section into the Word document section = document.AddSection(); //Adds the paragraph into the created section paragraph = section.AddParagraph(); //Adds the text for the headings paragraph.AppendText("Second Chapter"); //Sets a built-in heading style. paragraph.ApplyStyle(BuiltinStyle.Heading2); //Adds the text into the paragraph section.AddParagraph().AppendText(paraText); //Adds the section into the Word document section = document.AddSection(); //Adds the paragraph into the created section paragraph = section.AddParagraph(); //Adds the text into the headings paragraph.AppendText("Third Chapter"); //Sets a built-in heading style paragraph.ApplyStyle(BuiltinStyle.Heading3); //Adds the text into the paragraph. section.AddParagraph().AppendText(paraText); //Updates the table of contents document.UpdateTableOfContents(); //Finds the TOC from Word document. TableOfContent toc = FindTableOfContent(document); //Change tab leader for table of contents in the Word document if (toc != null) { ChangeTabLeaderForTableOfContents(toc, TabLeader.Hyphenated); } //Saves and closes the Word document document.Save("Result.docx"); document.Close(); System.Diagnostics.Process.Start("Result.docx"); }
public MemoryStream GetWord(List <Book> books) { var word = new WordDocument(); IWSection section = word.AddSection(); IWTextRange title = section.AddParagraph().AppendText("Filtered Books"); title.CharacterFormat.Bold = true; section.AddParagraph(); IWTable table = section.AddTable(); table.Title = "Filtered books"; table.Description = "Books found based on applied filters"; var headers = new List <string>() { "Title", "Author", "Price", "Bestseller", "Availability" }; table.ResetCells(books.Count + 1, headers.Count); //Add table row with headers for (int i = 0; i < headers.Count; i++) { table[0, i].AddParagraph().AppendText(headers[i]); } //Add table rows with book values for (int i = 0; i < books.Count; i++) { table[i + 1, 0].AddParagraph().AppendText(books[i].Title); table[i + 1, 1].AddParagraph().AppendText(GetAuthorString(books[i].Author));; table[i + 1, 2].AddParagraph().AppendText(GetPriceString(books[i].Price)); table[i + 1, 3].AddParagraph().AppendText(GetBestsellerString(books[i].IsBestSeller)); table[i + 1, 4].AddParagraph().AppendText(GetStockString(books[i].AvailableStock)); } MemoryStream stream = new MemoryStream(); word.Save(stream, FormatType.Docx); return(stream); }
public ActionResult HeaderandFooter(string Group1) { if (Group1 == null) { return(View()); } // Creating a new document. WordDocument doc = new WordDocument(); // Add a new section to the document. IWSection section1 = doc.AddSection(); // Set the header/footer setup. section1.PageSetup.DifferentFirstPage = true; // Inserting Header Footer to first page InsertFirstPageHeaderFooter(doc, section1); // Inserting Header Footer to all pages InsertPageHeaderFooter(doc, section1); // Add text to the document body section. IWParagraph par; par = section1.AddParagraph(); //Insert Text into the word Document. StreamReader reader = new StreamReader(ResolveApplicationDataPath("WinFAQ.txt", "App_Data\\DocIO"), System.Text.Encoding.ASCII); string text = reader.ReadToEnd(); par.AppendText(text); //Save as .doc format if (Group1 == "WordDoc") { return(doc.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx format else if (Group1 == "WordDocx") { return(doc.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(doc.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .pdf format else if (Group1 == "Pdf") { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(doc); return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } return(View()); }
private void Button_Click_1(object sender, RoutedEventArgs e) { //Creates a new word document instance WordDocument document = new WordDocument(); //Adds new section to the document IWSection section = document.AddSection(); //Sets page margins document.LastSection.PageSetup.Margins.All = 72; //Adds new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Appends text to paragraph IWTextRange textRange = paragraph.AppendText("Mathematical equations"); textRange.CharacterFormat.FontSize = 28; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; paragraph.ParagraphFormat.AfterSpacing = 12; #region Sum to the power of n //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n."); //Creates an equation with sum to the power of N CreateSumToThePowerOfN(paragraph); #endregion #region Fourier series //Adds new paragraph to the section paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L"); //Creates a Fourier series equation CreateFourierseries(paragraph); #endregion #region Triple scalar product //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of triple scalar product"); //Creates a triple scalar product equation CreateTripleScalarProduct(paragraph); #endregion #region Gamma function //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of gamma function"); //Creates a gamma function equation CreateGammaFunction(paragraph); #endregion #region Vector relation //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of vector relation "); //Creates a vector relation equation CreateVectorRelation(paragraph); #endregion SaveDocx(document); }
public async Task <IActionResult> OnPostGenerateVolunteerReport() { //Initializing database variables var volunteers = _context.Volunteer; var volunteerActivities = _context.VolunteerActivity; var initiatives = _context.Initiative; //Pulling currently logged in user var user = await _userManager.GetUserAsync(User); Volunteer loggedin = await _context.Volunteer .FirstOrDefaultAsync(m => m.UserName.ToLower() == user.UserName.ToLower()); //Creating and formatting document WordDocument report = new WordDocument(); IWSection section = report.AddSection(); section.PageSetup.Margins.All = 50f; IWParagraph name = section.AddParagraph(); name.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; name.ParagraphFormat.AfterSpacing = 18f; IWTextRange nameText = name.AppendText(loggedin.FullName); //Creating and formatting table IWTable info = section.AddTable(); info.ResetCells(1, 5); AddTitlesToTable(info); info.Rows[0].Height = 20; //Looping through initiatives and filling the table int row = 0; foreach (CoHO.Models.VolunteerActivity activity in volunteerActivities.ToArray()) { if (activity.VolunteerId == loggedin.VolunteerID) { row = AddDataToTable(info, row, activity, initiatives); } } //Assigning font nameText.CharacterFormat.FontName = "Times New Roman"; nameText.CharacterFormat.FontSize = 14; //Saving document and downloading to user's computer MemoryStream stream = new MemoryStream(); report.Save(stream, FormatType.Docx); report.Close(); stream.Position = 0; return(File(stream, "application/msword", "UserReport.docx")); }
private async void Button_Click_1(object sender, RoutedEventArgs e) { Assembly execAssem = typeof(EncryptAndDecryptDemo).GetTypeInfo().Assembly; WordDocument document = null; if (rdEncrypt.IsChecked == true) { document = new WordDocument(); document.EnsureMinimal(); // Getting last section of the document. IWSection section = document.LastSection; // Adding a paragraph to the section. IWParagraph paragraph = section.AddParagraph(); // Writing text IWTextRange text = paragraph.AppendText("This document was encrypted with password"); text.CharacterFormat.FontSize = 16f; text.CharacterFormat.FontName = "Bitstream Vera Serif"; // Encrypt the document by giving password document.EncryptDocument("syncfusion"); } else { // Open an existing template document with single section. document = new WordDocument(); Stream inputStream = execAssem.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Security Settings.docx"); // Open an existing template document. await document.OpenAsync(inputStream, FormatType.Docx, "syncfusion"); inputStream.Dispose(); // Getting last section of the document. IWSection section = document.LastSection; // Adding a paragraph to the section. IWParagraph paragraph = section.AddParagraph(); // Writing text IWTextRange text = paragraph.AppendText("\nDemo For Document Decryption with Essential DocIO"); text.CharacterFormat.FontSize = 16f; text.CharacterFormat.FontName = "Bitstream Vera Serif"; text = paragraph.AppendText("\nThis document is Decrypted"); text.CharacterFormat.FontSize = 16f; text.CharacterFormat.FontName = "Bitstream Vera Serif"; } Save(document); }
static void Main(string[] args) { using (WordDocument document = new WordDocument()) { document.EnsureMinimal(); IWSection section = document.LastSection; IWParagraph paragraph = document.LastParagraph; //add text enclosed by BookmarkStart and BookmarkEnd into a paragraph paragraph.AppendBookmarkStart("Title1Mark"); paragraph.AppendText("Title paragraph"); paragraph.AppendBookmarkEnd("Title1Mark"); //Add few paragraph of textual data for (int i = 0; i < 10; i++) { section.AddParagraph().AppendText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); } paragraph = section.AddParagraph(); //Add a hyperlink with the specified display text and targets to Bookmark named "Title1Mark" paragraph.AppendHyperlink("Title1Mark", "Link to Title", HyperlinkType.Bookmark); document.Save("output.docx", FormatType.Docx); } }
/// <summary> /// Create a simple Word document /// </summary> /// <returns>Return the created Word document as stream</returns> public MemoryStream HeaderandFooter(string documentType) { // Creating a new document. WordDocument doc = new WordDocument(); // Add a new section to the document. IWSection section1 = doc.AddSection(); // Set the header/footer setup. section1.PageSetup.DifferentFirstPage = true; // Inserting Header Footer to first page InsertFirstPageHeaderFooter(doc, section1); // Inserting Header Footer to all pages InsertPageHeaderFooter(doc, section1); // Add text to the document body section. IWParagraph par; par = section1.AddParagraph(); string basePath = _hostingEnvironment.WebRootPath; string dataPath = basePath + @"/data/docio/win-faq.txt"; //Insert Text into the word Document. StreamReader reader = new StreamReader(new FileStream(dataPath, FileMode.Open), System.Text.Encoding.ASCII); string text = reader.ReadToEnd(); par.AppendText(text); reader.Dispose(); reader = null; FormatType formatType = FormatType.Docx; //Save as .doc format if (documentType == "WordDoc") { formatType = FormatType.Doc; } //Save as .xml format else if (documentType == "WordML") { formatType = FormatType.WordML; } //Save the document as a stream and retrun the stream using (MemoryStream stream = new MemoryStream()) { //Save the created Word document to MemoryStream doc.Save(stream, formatType); doc.Close(); stream.Position = 0; return(stream); } }
private async void MergeCellsVertTabellaWord() { //Crea una istanza della classe WordDocument WordDocument document = new WordDocument(); IWSection section = document.AddSection(); section.AddParagraph().AppendText("Vertical merging of Table cells"); IWTable table = section.AddTable(); table.ResetCells(2, 2); //Aggiunge contenuto alle celle della tabella table[0, 0].AddParagraph().AppendText("First row, First cell"); table[0, 1].AddParagraph().AppendText("First row, Second cell"); table[1, 0].AddParagraph().AppendText("Second row, First cell"); table[1, 1].AddParagraph().AppendText("Second row, Second cell"); //Specifica che il vertical merge inizia dalla prima cella della prima riga table[0, 0].CellFormat.VerticalMerge = CellMerge.Start; //Modifica il contenuto della cella table[0, 0].Paragraphs[0].Text = "Vertically merged cell"; //Specifica che il vertical merge continua sulla prima cela della seconda riga table[1, 0].CellFormat.VerticalMerge = CellMerge.Continue; ////Salva e chiudi l'istanza del documento //Salva il documento su memory stream MemoryStream stream = new MemoryStream(); await document.SaveAsync(stream, FormatType.Docx); //Libera le risorse impegnate dall'istanza WordDocument document.Close(); //Salva lo stream come file di documento Word nella macchina locale StorageFile stFile = await Save(stream, "VerticalMerge.docx"); DefaultLaunch("VerticalMerge.docx"); }
private IWParagraph AddTitleToSection(IWSection section, string title) { IWParagraph title_paragraph = section.AddParagraph(); title_paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; IWTextRange title_text = title_paragraph.AppendText(title); title_text.CharacterFormat.Bold = true; title_text.CharacterFormat.FontName = "Times New Roman"; title_text.CharacterFormat.UnderlineStyle = UnderlineStyle.Single; title_text.CharacterFormat.FontSize = 16; title_paragraph.AppendText("\n"); return(title_paragraph); }
private void Button_Click_1(object sender, RoutedEventArgs e) { // Creating a new document. WordDocument doc = new WordDocument(); // Add a new section to the document. IWSection section1 = doc.AddSection(); Assembly execAssm = typeof(HeadersAndFootersDemo).GetTypeInfo().Assembly; #region Header Footer //Add different Header Footer for first and other pages if (checkBox1.IsChecked == true && checkBox2.IsChecked == true) { // Set the header/footer setup. section1.PageSetup.DifferentFirstPage = true; // Inserting Header Footer to first page InsertFirstPageHeaderFooter(doc, section1); // Inserting Header Footer to all pages InsertPageHeaderFooter(doc, section1); } //Add Header Footer only for first page if (checkBox1.IsChecked == true && checkBox2.IsChecked != true) { // Set the header/footer setup. section1.PageSetup.DifferentFirstPage = true; // Inserting Header Footer to first page InsertFirstPageHeaderFooter(doc, section1); } //Add same Header Footer for all the pages if (checkBox2.IsChecked == true && checkBox1.IsChecked != true) { // Inserting Header Footer to all pages InsertPageHeaderFooter(doc, section1); } #endregion // Add text to the document body section. IWParagraph par; par = section1.AddParagraph(); //Insert Text into the word Document. Stream inputStream = execAssm.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.WinFAQ.txt"); StreamReader reader = new StreamReader(inputStream, System.Text.Encoding.Unicode); string text = reader.ReadToEnd(); par.AppendText(text); Save(rdDoc.IsChecked == true, doc); }
static void Main(string[] args) { //Creates new Word document instance for Word processing using (WordDocument document = new WordDocument()) { //Adds a section to the Word document IWSection section = document.AddSection(); //Sets the page margin section.PageSetup.Margins.All = 72; //Adds a paragrah to the section IWParagraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; paragraph.ParagraphFormat.AfterSpacing = 20; IWTextRange textRange = paragraph.AppendText("Suppliers"); textRange.CharacterFormat.FontSize = 14; textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(255, 50, 62, 79); //Modifies the font size as 10 for default paragraph style WParagraphStyle style = document.Styles.FindByName("Normal") as WParagraphStyle; style.CharacterFormat.FontSize = 10; //Adds a table to the section WTable table = section.AddTable() as WTable; table.ResetCells(1, 6); table[0, 0].Width = 52f; table[0, 0].AddParagraph().AppendText("Supplier ID"); table[0, 1].Width = 128f; table[0, 1].AddParagraph().AppendText("Company Name"); table[0, 2].Width = 70f; table[0, 2].AddParagraph().AppendText("Contact Name"); table[0, 3].Width = 92f; table[0, 3].AddParagraph().AppendText("Address"); table[0, 4].Width = 66.5f; table[0, 4].AddParagraph().AppendText("City"); table[0, 5].Width = 56f; table[0, 5].AddParagraph().AppendText("Country"); //Imports data to the table. ImportDataToTable(table); //Applies the built-in table style (Medium Shading 1 Accent 1) to the table table.ApplyStyle(BuiltinTableStyle.MediumShading1Accent1); //Saves the file in the given path Stream docStream = File.Create(Path.GetFullPath(@"Result.docx")); document.Save(docStream, FormatType.Docx); docStream.Dispose(); } }
protected void ClickToEncrypt_Click(object sender, EventArgs e) { if (this.FileUpload1.HasFile && System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName).StartsWith(".doc")) { Stream readFile = this.FileUpload1.PostedFile.InputStream; //Open the document WordDocument document = new WordDocument(readFile); // Getting last section of the document. IWSection section = document.LastSection; // Adding a paragraph to the section. IWParagraph paragraph = section.AddParagraph(); // Writing text IWTextRange text = paragraph.AppendText("This document was encrypted with password"); text.CharacterFormat.FontSize = 16f; text.CharacterFormat.FontName = "Bitstream Vera Serif"; // Encrypt the document by giving password document.EncryptDocument(txtEnOpen.Text); # region Save Document if (rdButtonDoc.Checked) { //Save as .doc format document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment); } //Save as .docx format else if (rdButtonDocx.Checked) { try { document.Save("Sample.docx", FormatType.Docx, Response, HttpContentDisposition.Attachment); } catch (Win32Exception ex) { Response.Write("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } # endregion }
private void button1_Click(object sender, System.EventArgs e) { try { //A new document is created. WordDocument document = new WordDocument(); //Adding a section to the document. IWSection section = document.AddSection(); //Adding a paragraph to the section. IWParagraph paragraph = section.AddParagraph(); #region DocVariable string name = "John Smith"; string address = "Cary, NC"; //Get the variables in the existing document DocVariables dVariable = document.Variables; //Add doc variables dVariable.Add("Customer Name", name); dVariable.Add("Customer Address", address); #endregion DocVariable #region Document Properties //Setting document Properties document.BuiltinDocumentProperties.Author = "Essential DocIO"; document.BuiltinDocumentProperties.ApplicationName = "Essential DocIO"; document.BuiltinDocumentProperties.Category = "Document Generator"; document.BuiltinDocumentProperties.Comments = "This document was generated using Essential DocIO"; document.BuiltinDocumentProperties.Company = "Syncfusion Inc"; document.BuiltinDocumentProperties.Subject = "Native Word Generator"; document.BuiltinDocumentProperties.Keywords = "Syncfusion"; document.BuiltinDocumentProperties.Manager = "Sync Manager"; document.BuiltinDocumentProperties.Title = "Essential DocIO"; // Add a custom document Property document.CustomDocumentProperties.Add("My_Doc_Date", DateTime.Today); document.CustomDocumentProperties.Add("My_Doc", true); document.CustomDocumentProperties.Add("My_ID", 1031); document.CustomDocumentProperties.Add("My_Comment", "Essential DocIO"); //Remove a custome property document.CustomDocumentProperties.Remove("My_Doc"); #endregion IWTextRange text = paragraph.AppendText(""); text.CharacterFormat.FontName = "Calibri"; text.CharacterFormat.FontSize = 13; text = paragraph.AppendText("This document is created with various Document Properties Summary Information and page settings information \n\n You can view Document Properties through: File -> Properties -> Summary/Custom."); text.CharacterFormat.FontName = "Calibri"; text.CharacterFormat.FontSize = 13; #region Page setup // Write section properties section.PageSetup.PageSize = new SizeF(500, 750); section.PageSetup.Orientation = PageOrientation.Landscape; section.PageSetup.Margins.Bottom = 100; section.PageSetup.Margins.Top = 100; section.PageSetup.Margins.Left = 50; section.PageSetup.Margins.Right = 50; section.PageSetup.PageBordersApplyType = PageBordersApplyType.AllPages; section.PageSetup.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DoubleWave; section.PageSetup.Borders.Color = Color.DarkBlue; section.PageSetup.VerticalAlignment = PageAlignment.Middle; #endregion paragraph = section.AddParagraph(); text = paragraph.AppendText(""); text.CharacterFormat.FontName = "Calibri"; text.CharacterFormat.FontSize = 13; text = paragraph.AppendText("\n\n You can view Page setup options through File -> PageSetup."); text.CharacterFormat.FontName = "Calibri"; text.CharacterFormat.FontSize = 13; #region Get document variables paragraph = document.LastSection.AddParagraph(); dVariable = document.Variables; text = paragraph.AppendText("\n\n Document Variables\n"); text.CharacterFormat.FontName = "Calibri"; text.CharacterFormat.FontSize = 13; text.CharacterFormat.Bold = true; text = paragraph.AppendText("\n" + dVariable.GetNameByIndex(1) + ": " + dVariable.GetValueByIndex(1)); text.CharacterFormat.FontName = "Calibri"; text.CharacterFormat.FontSize = 13; //Display the current variable count text = paragraph.AppendText("\n\nDocument Variables Count: " + dVariable.Count); text.CharacterFormat.FontName = "Calibri"; text.CharacterFormat.FontSize = 13; #endregion Get document variables //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. document.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.doc"); #endif //Exit this.Close(); } } //Save as docx format else if (wordDocxRadioBtn.Checked) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
private void button1_Click(object sender, System.EventArgs e) { try { // Create a new document. WordDocument document = new WordDocument(); // Adding a new section to the document. IWSection section = document.AddSection(); section.PageSetup.Margins.All = 50; section.PageSetup.DifferentFirstPage = true; IWTextRange textRange; IWParagraph paragraph = section.AddParagraph(); #region Table Cell Spacing. // -------------------------------------------- // Table Cell Spacing. // -------------------------------------------- paragraph.AppendText("Table Cell spacing...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); WTextBody textBody = section.Body; // Adding a new Table to the textbody. IWTable table = textBody.AddTable(); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; table.TableFormat.Paddings.All = 5.4f; RowFormat format = new RowFormat(); format.Paddings.All = 5; format.CellSpacing = 2; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; format.IsBreakAcrossPages = true; table.ResetCells(25, 5, format, 90); IWTextRange text; table.Rows[0].IsHeader = true; for (int i = 0; i < table.Rows[0].Cells.Count; i++) { paragraph = table[0, i].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Header {0}", i + 1)); text.CharacterFormat.Font = new Font("Bitstream Vera Serif", 10); text.CharacterFormat.Bold = true; text.CharacterFormat.TextColor = Color.FromArgb(0, 21, 84); table[0, i].CellFormat.BackColor = Color.FromArgb(203, 211, 226); } for (int i = 1; i < table.Rows.Count; i++) { for (int j = 0; j < 5; j++) { paragraph = table[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50); text.CharacterFormat.Bold = true; if (i % 2 != 1) { table[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245); } else { table[i, j].CellFormat.BackColor = Color.FromArgb(246, 249, 255); } } } (table as WTable).AutoFit(AutoFitType.FitToContent); #endregion Table Cell Spacing. #region Nested Table // -------------------------------------------- // Nested Table. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.PageBreakBefore = true; paragraph.AppendText("Nested Table...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); format = new RowFormat(); format.Paddings.All = 5; format.CellSpacing = 2.5f; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; table.ResetCells(5, 3, format, 100); for (int i = 0; i < table.Rows[0].Cells.Count; i++) { paragraph = table[0, i].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Header {0}", i + 1)); text.CharacterFormat.Font = new Font("Bitstream Vera Serif", 10); text.CharacterFormat.Bold = true; text.CharacterFormat.TextColor = Color.FromArgb(0, 21, 84); table[0, i].CellFormat.BackColor = Color.FromArgb(242, 151, 50); } table[0, 2].Width = 200; for (int i = 1; i < table.Rows.Count; i++) { for (int j = 0; j < 3; j++) { paragraph = table[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; if ((i == 2) && (j == 2)) { text = paragraph.AppendText("Nested Table"); } else { text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); } if ((j == 2)) { table[i, j].Width = 200; } text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50); text.CharacterFormat.Bold = true; } } // Adding a nested Table. IWTable nestTable = table[2, 2].AddTable(); format = new RowFormat(); format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; format.HorizontalAlignment = RowAlignment.Center; nestTable.ResetCells(3, 3, format, 45); for (int i = 0; i < nestTable.Rows.Count; i++) { for (int j = 0; j < 3; j++) { paragraph = nestTable[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; nestTable[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245); text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); text.CharacterFormat.TextColor = Color.Black; text.CharacterFormat.Bold = true; } } (nestTable as WTable).AutoFit(AutoFitType.FitToContent); (table as WTable).AutoFit(AutoFitType.FitToWindow); #endregion Nested Table #region Table with Images string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\images\DocIO\"; //Add a new section to the document. section = document.AddSection(); //Add paragraph to the section. paragraph = section.AddParagraph(); //Writing text. textRange = paragraph.AppendText("Table with Images"); textRange.CharacterFormat.FontSize = 13f; textRange.CharacterFormat.TextColor = Color.DarkBlue; textRange.CharacterFormat.Bold = true; //Add paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); text = null; //Adding a new Table to the paragraph. table = section.Body.AddTable(); table.ResetCells(1, 3); //Adding rows to the table. WTableRow row = table.Rows[0]; //Set heading row height row.Height = 25f; //set heading values to the Table. for (int i = 0; i < 3; i++) { //Add paragraph for writing Text to the cells. paragraph = (IWParagraph)row.Cells[i].AddParagraph(); //Set Horizontal Alignment as Center. paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Writing Row Heading switch (i) { case 0: text = paragraph.AppendText("SNO"); row.Cells[i].Width = 50f; break; case 1: text = paragraph.AppendText("Drinks"); break; case 2: text = paragraph.AppendText("Showcase Image"); row.Cells[i].Width = 200f; break; } //Set row Heading formatting text.CharacterFormat.Bold = true; text.CharacterFormat.FontName = "Cambria"; text.CharacterFormat.FontSize = 11f; text.CharacterFormat.TextColor = Color.White; //Set row cells formatting row.Cells[i].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row.Cells[i].CellFormat.BackColor = Color.FromArgb(157, 161, 190); row.Cells[i].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; } int sno = 1; //Writing Sno, Product name and Product Images to the Table. WTableRow row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Apple Juice"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Apple Juice.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Grape Juice"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Grape Juice.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Hot Soup"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Hot Soup.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; (table as WTable).AutoFit(AutoFitType.FixedColumnWidth); #endregion Table with Images //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. document.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.doc"); #endif //Exit this.Close(); } } //Save as docx format else if (wordDocxRadioBtn.Checked) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as pdf format else if (pdfRadioBtn.Checked) { DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(document); //Save the pdf file pdfDoc.Save("Sample.pdf"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.pdf"); #endif //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
public void ExportChart(string Data, string ChartModel) { // declaration ChartProperties obj = ConvertChartObject(ChartModel); string type = obj.ExportSettings.Type.ToString().ToLower(); string fileName = obj.ExportSettings.FileName; string orientation = obj.ExportSettings.Orientation.ToString(); if (type == "svg") // for svg export { StringWriter oStringWriter = new StringWriter(); string data = HttpUtility.HtmlDecode(Data); data = HttpUtility.UrlDecode(Data); data = System.Uri.UnescapeDataString(Data); oStringWriter.WriteLine(System.Uri.UnescapeDataString(Data)); Response.ContentType = "text/plain"; Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", (obj.ExportSettings.FileName + ".svg"))); Response.Clear(); using (StreamWriter writer = new StreamWriter(Response.OutputStream)) { data = oStringWriter.ToString(); writer.Write(oStringWriter.ToString()); } Response.End(); } else if (type == "xlsx") // to export chart as excel { List <ExportChartData> chartData = new List <ExportChartData>(); chartData.Add(new ExportChartData("John", 10)); chartData.Add(new ExportChartData("Jake", 12)); chartData.Add(new ExportChartData("Peter", 18)); chartData.Add(new ExportChartData("James", 11)); chartData.Add(new ExportChartData("Mary", 9.7)); ExcelExport exp = new ExcelExport(); exp.Export(obj, (IEnumerable)chartData, fileName + ".xlsx", ExcelVersion.Excel2010, null, null); } else { Data = Data.Remove(0, Data.IndexOf(',') + 1); MemoryStream stream = new MemoryStream(Convert.FromBase64String(Data)); if (type == "docx") // to export as word document { WordDocument document = new WordDocument(); IWSection section = document.AddSection(); IWParagraph paragraph = section.AddParagraph(); //Set orientation based on chart width Image img = Image.FromStream(stream); if (obj.ExportSettings.Orientation.ToString() == "Landscape" || section.PageSetup.ClientWidth < img.Width) { section.PageSetup.Orientation = PageOrientation.Landscape; } else { section.PageSetup.Orientation = PageOrientation.Portrait; } img.Dispose(); paragraph.AppendPicture(Image.FromStream(stream)); document.Save(fileName + ".doc", Syncfusion.DocIO.FormatType.Doc, HttpContext.ApplicationInstance.Response, Syncfusion.DocIO.HttpContentDisposition.Attachment); } else if (type == "pdf") // to export as PDF { PdfDocument pdfDoc = new PdfDocument(); pdfDoc.Pages.Add(); //Set chart width as pdf page width Image img = Image.FromStream(stream); pdfDoc.Pages[0].Section.PageSettings.Width = img.Width; img.Dispose(); if (obj.ExportSettings.Orientation.ToString() == "Landscape") { pdfDoc.Pages[0].Section.PageSettings.Orientation = PdfPageOrientation.Landscape; } else { pdfDoc.Pages[0].Section.PageSettings.Orientation = PdfPageOrientation.Portrait; } pdfDoc.Pages[0].Graphics.DrawImage(PdfImage.FromStream(stream), new PointF(10, 30)); pdfDoc.Save(obj.ExportSettings.FileName + ".pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save); pdfDoc.Close(); } else // to export as image { stream.WriteTo(Response.OutputStream); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", fileName + "." + type)); Response.Flush(); stream.Close(); stream.Dispose(); } } }
public ActionResult BarChart(string Group1) { if (Group1 == null) { return(View()); } //A new document is created. WordDocument document = new WordDocument(); //Add new section to the Word document IWSection section = document.AddSection(); //Set page margins of the section section.PageSetup.Margins.All = 72; //Add new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Apply heading style to the title paragraph paragraph.ApplyStyle(BuiltinStyle.Heading1); //Apply center alignment to the paragraph paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Append text to the paragraph paragraph.AppendText("Northwind Management Report").CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); //Add new paragraph paragraph = section.AddParagraph(); //Set before spacing to the paragraph paragraph.ParagraphFormat.BeforeSpacing = 20; string basePath = _hostingEnvironment.WebRootPath; string dataPath = basePath + @"/DocIO/Excel_Template.xlsx"; //Load the excel template as stream Stream excelStream = new FileStream(dataPath, FileMode.Open, FileAccess.Read); //Create and Append chart to the paragraph with excel stream as parameter WChart BarChart = paragraph.AppendChart(excelStream, 1, "B2:C6", 470, 300); //Set chart data BarChart.ChartType = OfficeChartType.Bar_Clustered; BarChart.ChartTitle = "Purchase Details"; BarChart.ChartTitleArea.FontName = "Calibri (Body)"; BarChart.ChartTitleArea.Size = 14; //Set name to chart series BarChart.Series[0].Name = "Sum of Purchases"; BarChart.Series[1].Name = "Sum of Future Expenses"; //Set Chart Data table BarChart.HasDataTable = true; BarChart.DataTable.HasBorders = true; BarChart.DataTable.HasHorzBorder = true; BarChart.DataTable.HasVertBorder = true; BarChart.DataTable.ShowSeriesKeys = true; BarChart.HasLegend = false; //Setting background color BarChart.ChartArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(208, 206, 206); BarChart.PlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(208, 206, 206); //Setting line pattern to the chart area BarChart.PrimaryCategoryAxis.Border.LinePattern = OfficeChartLinePattern.None; BarChart.PrimaryValueAxis.Border.LinePattern = OfficeChartLinePattern.None; BarChart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; BarChart.PrimaryValueAxis.MajorGridLines.Border.LineColor = Syncfusion.Drawing.Color.FromArgb(175, 171, 171); //Set label for primary catagory axis BarChart.PrimaryCategoryAxis.CategoryLabels = BarChart.ChartData[2, 1, 6, 1]; string filename = ""; string contenttype = ""; MemoryStream ms = new MemoryStream(); #region Document SaveOption if (Group1 == "WordDocx") { filename = "Sample.docx"; contenttype = "application/msword"; document.Save(ms, FormatType.Docx); } else if (Group1 == "WordML") { filename = "Sample.xml"; contenttype = "application/msword"; document.Save(ms, FormatType.WordML); } else { filename = "Sample.pdf"; contenttype = "application/pdf"; DocIORenderer renderer = new DocIORenderer(); renderer.ConvertToPDF(document).Save(ms); } #endregion Document SaveOption document.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }
public ActionResult FormatTable(string Group1) { if (Group1 == null) { return(View()); } // Create a new document. WordDocument document = new WordDocument(); // Adding a new section to the document. IWSection section = document.AddSection(); section.PageSetup.DifferentFirstPage = true; IWTextRange textRange; IWParagraph paragraph = section.AddParagraph(); // -------------------------------------------- // Table in page header // -------------------------------------------- IWParagraph hParagraph = new WParagraph(document); hParagraph.AppendText("Header text\r\n").CharacterFormat.FontSize = 14; section.HeadersFooters.FirstPageHeader.Paragraphs.Add(hParagraph); IWTable hTable = document.LastSection.HeadersFooters.FirstPageHeader.AddTable(); hTable.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; hTable.TableFormat.Paddings.All = 5.4f; hTable.ResetCells(2, 2); hTable[0, 0].AddParagraph().AppendText("1"); hTable[0, 1].AddParagraph().AppendText("2"); hTable[1, 0].AddParagraph().AppendText("3"); hTable[1, 1].AddParagraph().AppendText("4"); // -------------------------------------------- // Tiny table // -------------------------------------------- paragraph = section.AddParagraph(); paragraph.AppendText("Tiny table\r\n").CharacterFormat.FontSize = 14; paragraph = section.AddParagraph(); WTextBody textBody = section.Body; IWTable table = textBody.AddTable(); table.ResetCells(2, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; table.TableFormat.Paddings.All = 5.4f; WTableRow row_0 = table.Rows[0]; row_0.Cells[0].AddParagraph().AppendText("A"); row_0.Cells[0].AddParagraph().AppendText("AA"); row_0.Cells[0].AddParagraph().AppendText("AAA"); WTableRow row_1 = table.Rows[1]; row_1.Cells[1].AddParagraph().AppendText("B"); row_1.Cells[1].AddParagraph().AppendText("BB\r\nBBB"); row_1.Cells[1].AddParagraph().AppendText("BBB"); textBody.AddParagraph().AppendText("Text after table...").CharacterFormat.FontSize = 14; // -------------------------------------------- // Table with different formatting // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table with different formatting\r\n").CharacterFormat.FontSize = 14; paragraph = section.AddParagraph(); textBody = section.Body; table = textBody.AddTable(); table.ResetCells(3, 3); /* ------- First Row -------- */ WTableRow row0 = table.Rows[0]; paragraph = (IWParagraph)row0.Cells[0].AddParagraph(); textRange = paragraph.AppendText("1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange.CharacterFormat.FontName = "Arial"; textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.FontSize = 14f; row0.Cells[0].CellFormat.Borders.LineWidth = 2f; row0.Cells[0].CellFormat.Borders.Color = Color.Magenta; paragraph = (IWParagraph)row0.Cells[1].AddParagraph(); textRange = paragraph.AppendText("2"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; textRange.CharacterFormat.Emboss = true; textRange.CharacterFormat.FontSize = 15f; row0.Cells[1].CellFormat.Borders.LineWidth = 1.3f; row0.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DoubleWave; paragraph = (IWParagraph)row0.Cells[2].AddParagraph(); textRange = paragraph.AppendText("3"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange.CharacterFormat.Engrave = true; textRange.CharacterFormat.FontSize = 15f; row0.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Emboss3D; /* ------- Second Row -------- */ WTableRow row1 = table.Rows[1]; paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); textRange = paragraph.AppendText("4"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.SmallCaps = true; textRange.CharacterFormat.FontName = "Comic Sans MS"; textRange.CharacterFormat.FontSize = 16; row1.Cells[0].CellFormat.Borders.LineWidth = 2f; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DashDotStroker; paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); textRange = paragraph.AppendText("5"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.FontName = "Times New Roman"; textRange.CharacterFormat.Shadow = true; textRange.CharacterFormat.TextBackgroundColor = Color.Orange; textRange.CharacterFormat.FontSize = 15f; row1.Cells[1].CellFormat.Borders.LineWidth = 2f; row1.Cells[1].CellFormat.Borders.Color = Color.Brown; paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); textRange = paragraph.AppendText("6"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.FontSize = 14f; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(51, 51, 101); row1.Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Middle; /* ------- Third Row -------- */ WTableRow row2 = table.Rows[2]; paragraph = (IWParagraph)row2.Cells[0].AddParagraph(); textRange = paragraph.AppendText("7"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; textRange.CharacterFormat.FontSize = 13f; row2.Cells[0].CellFormat.Borders.LineWidth = 1.5f; row2.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DashLargeGap; paragraph = (IWParagraph)row2.Cells[1].AddParagraph(); textRange = paragraph.AppendText("8"); textRange.CharacterFormat.TextColor = Color.Blue; textRange.CharacterFormat.FontSize = 16f; row2.Cells[1].CellFormat.Borders.LineWidth = 3f; row2.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Wave; paragraph = (IWParagraph)row2.Cells[2].AddParagraph(); textRange = paragraph.AppendText("9"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; row2.Cells[2].CellFormat.Borders.LineWidth = 2f; row2.Cells[2].CellFormat.Borders.Color = Color.Cyan; row2.Cells[2].CellFormat.Borders.Shadow = true; row2.Cells[2].CellFormat.Borders.Space = 20; // -------------------------------------------- // Table Cell Merging. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table Cell Merging...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); RowFormat format = new RowFormat(); format.Paddings.All = 5; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Dot; format.Borders.LineWidth = 2; // Inserting rows to the table. table.ResetCells(6, 6, format, 80); // Table formatting with cell merging. table.Rows[0].Cells[0].CellFormat.HorizontalMerge = CellMerge.Start; table.Rows[0].Cells[1].CellFormat.HorizontalMerge = CellMerge.Continue; table.Rows[0].Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; table.Rows[0].Cells[0].CellFormat.BackColor = Color.FromArgb(218, 230, 246); IWParagraph par = table.Rows[0].Cells[0].AddParagraph(); par.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; par.AppendText("Horizontal Merge").CharacterFormat.Bold = true; table.Rows[2].Cells[3].CellFormat.VerticalMerge = CellMerge.Start; table.Rows[3].Cells[3].CellFormat.VerticalMerge = CellMerge.Continue; table.Rows[2].Cells[3].CellFormat.VerticalAlignment = VerticalAlignment.Middle; par = table.Rows[2].Cells[3].AddParagraph(); table.Rows[2].Cells[3].CellFormat.BackColor = Color.FromArgb(252, 172, 85); par.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; par.AppendText("Vertical Merge").CharacterFormat.Bold = true; #region Table Cell Spacing. // -------------------------------------------- // Table Cell Spacing. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table Cell spacing...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; table.TableFormat.Paddings.All = 5.4f; format = new RowFormat(); format.Paddings.All = 5; format.CellSpacing = 2; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; format.IsBreakAcrossPages = true; table.ResetCells(25, 5, format, 90); IWTextRange text; table.Rows[0].IsHeader = true; for (int i = 0; i < table.Rows[0].Cells.Count; i++) { paragraph = table[0, i].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Header {0}", i + 1)); text.CharacterFormat.Font = new Font("Bitstream Vera Serif", 10); text.CharacterFormat.Bold = true; text.CharacterFormat.TextColor = Color.FromArgb(0, 21, 84); table[0, i].CellFormat.BackColor = Color.FromArgb(203, 211, 226); } for (int i = 1; i < table.Rows.Count; i++) { for (int j = 0; j < 5; j++) { paragraph = table[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50); text.CharacterFormat.Bold = true; if (i % 2 != 1) { table[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245); } else { table[i, j].CellFormat.BackColor = Color.FromArgb(246, 249, 255); } } } #endregion Table Cell Spacing. #region Nested Table // -------------------------------------------- // Nested Table. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.PageBreakBefore = true; paragraph.AppendText("Nested Table...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); format = new RowFormat(); format.Paddings.All = 5; format.CellSpacing = 2.5f; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; table.ResetCells(5, 3, format, 100); for (int i = 0; i < table.Rows[0].Cells.Count; i++) { paragraph = table[0, i].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Header {0}", i + 1)); text.CharacterFormat.Font = new Font("Bitstream Vera Serif", 10); text.CharacterFormat.Bold = true; text.CharacterFormat.TextColor = Color.FromArgb(0, 21, 84); table[0, i].CellFormat.BackColor = Color.FromArgb(242, 151, 50); } table[0, 2].Width = 200; for (int i = 1; i < table.Rows.Count; i++) { for (int j = 0; j < 3; j++) { paragraph = table[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; if ((i == 2) && (j == 2)) { text = paragraph.AppendText("Nested Table"); } else { text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); } if ((j == 2)) { table[i, j].Width = 200; } text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50); text.CharacterFormat.Bold = true; } } // Adding a nested Table. IWTable nestTable = table[2, 2].AddTable(); format = new RowFormat(); format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; format.HorizontalAlignment = RowAlignment.Center; nestTable.ResetCells(3, 3, format, 45); for (int i = 0; i < nestTable.Rows.Count; i++) { for (int j = 0; j < 3; j++) { paragraph = nestTable[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; nestTable[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245); text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); text.CharacterFormat.TextColor = Color.Black; text.CharacterFormat.Bold = true; } } #endregion Nested Table #region Table with Images string dataPath = ResolveApplicationDataPath("", "Content\\DocIO"); //Add a new section to the document. section = document.AddSection(); //Add paragraph to the section. paragraph = section.AddParagraph(); //Writing text. textRange = paragraph.AppendText("Table with Images"); textRange.CharacterFormat.FontSize = 13f; textRange.CharacterFormat.TextColor = Color.DarkBlue; textRange.CharacterFormat.Bold = true; //Add paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); text = null; //Adding a new Table to the paragraph. table = section.Body.AddTable(); table.ResetCells(1, 3); //Adding rows to the table. WTableRow row = table.Rows[0]; //Set heading row height row.Height = 25f; //set heading values to the Table. for (int i = 0; i < 3; i++) { //Add paragraph for writing Text to the cells. paragraph = (IWParagraph)row.Cells[i].AddParagraph(); //Set Horizontal Alignment as Center. paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Writing Row Heading switch (i) { case 0: text = paragraph.AppendText("SNO"); row.Cells[i].Width = 50f; break; case 1: text = paragraph.AppendText("Drinks"); break; case 2: text = paragraph.AppendText("Showcase Image"); row.Cells[i].Width = 200f; break; } //Set row Heading formatting text.CharacterFormat.Bold = true; text.CharacterFormat.FontName = "Cambria"; text.CharacterFormat.FontSize = 11f; text.CharacterFormat.TextColor = Color.White; //Set row cells formatting row.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row.Cells[i].CellFormat.BackColor = Color.FromArgb(157, 161, 190); row.Cells[i].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; } int sno = 1; //Writing Sno, Product name and Product Images to the Table. row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Apple Juice"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Apple Juice.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Grape Juice"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Grape Juice.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Hot Soup"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Hot Soup.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; #endregion Table with Images //Save as .doc format if (Group1 == "WordDoc") { return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx format else if (Group1 == "WordDocx") { return(document.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(document.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .pdf format else if (Group1 == "Pdf") { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(document); return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } return(View()); }
/// <summary> /// Encrypt the word document /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void encrypt_Click(object sender, RoutedEventArgs e) { try { if (this.textBox1.Text != null && this.textBox1.Text != string.Empty) { WordDocument document = new WordDocument(this.textBox1.Text); // Getting last section of the document. IWSection section = document.LastSection; // Adding a paragraph to the section. IWParagraph paragraph = section.AddParagraph(); // Writing text IWTextRange text = paragraph.AppendText("This document was encrypted with password"); text.CharacterFormat.FontSize = 16f; text.CharacterFormat.FontName = "Bitstream Vera Serif"; // Encrypt the document by giving password document.EncryptDocument(this.passwordBox1.Password); # region Save Document //Save as doc format if (worddoc.IsChecked.Value) { try { //Saving the document to disk. document.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBox.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.doc"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBox.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } catch (Exception ex) { if (ex is IOException) { MessageBox.Show("Please close the file (" + Directory.GetCurrentDirectory() + "\\Sample.doc" + ") then try generating the document.", "File is already open", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show("Document could not be generated, Could you please email the error details to [email protected] for trouble shooting" + "\r\n" + ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } //Save as docx format else if (worddocx.IsChecked.Value) { try { //Saving the document as .docx document.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBox.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBox.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } catch (Exception ex) { if (ex is IOException) { MessageBox.Show("Please close the file (" + Directory.GetCurrentDirectory() + "\\Sample.doc" + ") then try generating the document.", "File is already open", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show("Document could not be generated, Could you please email the error details to [email protected] for trouble shooting" + "\r\n" + ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } else { // Exit this.Close(); } # endregion } else { MessageBox.Show("Please browse a Word document to encrypt"); } }