static void Main(string[] args) { using (WordDocument document = new WordDocument()) { document.EnsureMinimal(); document.LastSection.PageSetup.Margins.All = 72; WParagraph para = document.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = document.LastSection.AddParagraph() as WParagraph; //Creates the new custom styles. WParagraphStyle pStyle1 = (WParagraphStyle)document.AddParagraphStyle("MyStyle1"); pStyle1.CharacterFormat.FontSize = 18f; WParagraphStyle pStyle2 = (WParagraphStyle)document.AddParagraphStyle("MyStyle2"); pStyle2.CharacterFormat.FontSize = 16f; WParagraphStyle pStyle3 = (WParagraphStyle)document.AddParagraphStyle("MyStyle3"); pStyle3.CharacterFormat.FontSize = 14f; para = document.LastSection.AddParagraph() as WParagraph; //Insert TOC field in the Word document. TableOfContent toc = para.AppendTOC(1, 3); //Sets the Heading Styles to false, to define custom levels for TOC. toc.UseHeadingStyles = false; //Sets the TOC level style which determines; based on which the TOC should be created. toc.SetTOCLevelStyle(1, "MyStyle1"); toc.SetTOCLevelStyle(2, "MyStyle2"); toc.SetTOCLevelStyle(3, "MyStyle3"); //Adds content to the Word document with custom styles. WSection section = document.LastSection; WParagraph newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); AddHeading(section, "MyStyle1", "Document with custom styles", "This is the 1st custom style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can insert TOC field in a word document. It can refresh or update TOC field by using UpdateTableOfContents method. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); AddHeading(section, "MyStyle2", "Section 1", "This is the 2nd custom style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); AddHeading(section, "MyStyle3", "Paragraph 1", "This is the 3rd custom style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); AddHeading(section, "MyStyle3", "Paragraph 2", "This is the 3rd custom style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); AddHeading(section, "Normal", "Paragraph with normal", "This is the paragraph with normal style. This demonstrates the paragraph with outline level 4 and normal style. This can be attained by formatting outline level of the paragraph."); //Adds a new section to the Word document. section = document.AddSection() as WSection; section.PageSetup.Margins.All = 72; section.BreakCode = SectionBreakCode.NewPage; AddHeading(section, "MyStyle2", "Section 2", "This is the 2nd custom style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); AddHeading(section, "MyStyle3", "Paragraph 1", "This is the 3rd custom style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); AddHeading(section, "MyStyle3", "Paragraph 2", "This is the 3rd custom style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); //Updates the table of contents. document.UpdateTableOfContents(); //Saves the file in the given path Stream docStream = File.Create(Path.GetFullPath(@"../../../TOC-custom-style.docx")); document.Save(docStream, FormatType.Docx); docStream.Dispose(); } }
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(); } }
public MemoryStream CreateWord() { //Creating a new document WordDocument document = new WordDocument(); //Adding a new section to the document WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, AdventureWorks Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the AdventureWorks Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; //Saves the Word document to MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); //Closes the Word document document.Close(); stream.Position = 0; return(stream); }
/// <summary> /// Create a simple Word document /// </summary> /// <returns>Return the created Word document as stream</returns> public MemoryStream CreateWordDocument(string documentType) { //Creating a new document WordDocument document = new WordDocument(); //Adding a new section to the document WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); string basePath = _hostingEnvironment.WebRootPath + @"/images/DocIO/"; FileStream imageStream = new FileStream(basePath + @"AdventureCycle.jpg", FileMode.Open, FileAccess.Read); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -45; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph imageStream = new FileStream(basePath + @"Mountain-200.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph imageStream = new FileStream(basePath + @"Mountain-300.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph imageStream = new FileStream(basePath + @"Road-550-W.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends paragraph section.AddParagraph(); 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 document.Save(stream, formatType); document.Close(); stream.Position = 0; return(stream); } }
private void button1_Click(object sender, System.EventArgs e) { try { //Getting Image files path. string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\images\DocIO\"; //A new document is created. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); WPicture picture = paragraph.AppendPicture(Image.FromFile(dataPath + "AdventureCycle.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -45; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Color.Red; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Mountain-200.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Mountain-300.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Road-550-W.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. section.AddParagraph(); //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); } }
private void button1_Click(object sender, EventArgs e) { try { WordDocument doc = new WordDocument(); doc.EnsureMinimal(); WParagraph para = doc.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = doc.LastSection.AddParagraph() as WParagraph; para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); if (!this.checkBox6.Checked) { para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Color.Yellow; } para = doc.LastSection.AddParagraph() as WParagraph; string title = this.textBox1.Text + "\n"; para.AppendText(title); para.ApplyStyle(BuiltinStyle.Heading4); //Insert TOC TableOfContent toc = para.AppendTOC(1, 3); para.ApplyStyle(BuiltinStyle.Heading4); //Apply built-in paragraph formatting WSection section = doc.LastSection; // Set Margin of the document section.PageSetup.Margins.All = 72; if (radioButton1.Checked) { #region Default Styles WParagraph newPara = section.AddParagraph() as WParagraph; newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading1); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); section.AddParagraph(); section = doc.AddSection() as WSection; section.BreakCode = SectionBreakCode.NewPage; newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); #endregion } else { #region Custom styles //Custom styles. WParagraphStyle pStyle1 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle1"); WParagraphStyle pStyle2 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle2"); WParagraphStyle pStyle3 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle3"); //Set the Heading Styles to false in order to define custom levels to TOC. toc.UseHeadingStyles = false; //Set the TOC level style which determines; based on which the TOC should be created. toc.SetTOCLevelStyle(1, "MyStyle1"); toc.SetTOCLevelStyle(2, "MyStyle2"); toc.SetTOCLevelStyle(3, "MyStyle3"); section = doc.AddSection() as WSection; pStyle1.CharacterFormat.FontName = "Cambria"; pStyle1.CharacterFormat.FontSize = 30f; para = section.AddParagraph() as WParagraph; WTextRange text = para.AppendText("Document with Custom Styles") as WTextRange; para.ApplyStyle("MyStyle1"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); pStyle2.CharacterFormat.FontName = "Cambria"; pStyle2.CharacterFormat.FontSize = 20f; doc.LastSection.AddParagraph(); para = doc.LastSection.AddParagraph() as WParagraph; text = para.AppendText("Section1") as WTextRange; para.ApplyStyle("MyStyle2"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); pStyle3.CharacterFormat.FontName = "Cambria"; pStyle3.CharacterFormat.FontSize = 14f; doc.LastSection.AddParagraph(); para = doc.LastSection.AddParagraph() as WParagraph; text = para.AppendText("Section2") as WTextRange; para.ApplyStyle("MyStyle3"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); #endregion } if (this.numericUpDown2.Value < this.numericUpDown1.Value) { MessageBoxAdv.Show("Not a valid heading level range. UpperHeadingLevel must be greater than LowerHeadingLevel"); } else { toc.IncludePageNumbers = checkBox1.Checked; toc.RightAlignPageNumbers = checkBox2.Checked; toc.UseHyperlinks = checkBox3.Checked; toc.LowerHeadingLevel = Convert.ToInt32(this.numericUpDown1.Value); toc.UpperHeadingLevel = Convert.ToInt32(this.numericUpDown2.Value); //Right click text. Select Paragraph option. Set OutlineLevel. Update TOC toc see the text added in TOC. toc.UseOutlineLevels = this.checkBox4.Checked; //Select the text that should be marked as Table of contents. //Press ALT+SHIFT+O. A dialog box will appear with options to enter the text, select the table identifier and level. //Choose the table identifier and level for the test and click �Mark�. Update TOC toc see the text added in TOC. //Sets the Table Identifier if necessary. //toc.TableID = "B"; toc.UseTableEntryFields = this.checkBox5.Checked; //Updates the table of contents. if (this.checkBox6.Checked) { doc.UpdateTableOfContents(); } //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. doc.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 doc.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(doc); //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 MemoryStream CreateWord(List <Lokaal> lokalen) { //Creating a new document WordDocument document = new WordDocument(); //Adding a new section to the document WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 16f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 18f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; WTextRange textRange = paragraph.AppendText("Overzicht") as WTextRange; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); //Appends paragraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; textRange = paragraph.AppendText("Inventaris Lokalen") as WTextRange; textRange.CharacterFormat.FontSize = 20f; textRange.CharacterFormat.FontName = "Calibri"; //Eerste cel van tabel IWTable table = section.AddTable(); table.ResetCells(lokalen.Count(), 3); WTableCell firstCell = table.Rows[0].Cells[0]; firstCell.Width = 100; paragraph = firstCell.AddParagraph(); paragraph.ApplyStyle("Normal"); textRange = paragraph.AppendText("Lokaal") as WTextRange; textRange.CharacterFormat.Bold = true; //Tweede cel van tabel WTableCell secondCell = table.Rows[0].Cells[1]; secondCell.Width = 180; paragraph = secondCell.AddParagraph(); paragraph.ApplyStyle("Normal"); textRange = paragraph.AppendText("Details") as WTextRange; textRange.CharacterFormat.Bold = true; //Derde cel van tabel WTableCell thirdCell = table.Rows[0].Cells[2]; thirdCell.Width = 170; paragraph = thirdCell.AddParagraph(); paragraph.ApplyStyle("Normal"); textRange = paragraph.AppendText("Voorwerpen") as WTextRange; textRange.CharacterFormat.Bold = true; for (int i = 1; i < lokalen.Count(); i++) { //Lokaal firstCell = table.Rows[i].Cells[0]; firstCell.Width = 100; paragraph = firstCell.AddParagraph(); textRange = paragraph.AppendText("Lokaal " + lokalen[i].lokaalNr) as WTextRange; textRange.CharacterFormat.FontSize = 14f; //Details per lokaal secondCell = table.Rows[i].Cells[1]; secondCell.Width = 180; paragraph = secondCell.AddParagraph(); textRange = paragraph.AppendText("Nummer : " + lokalen[i].lokaalNr + "\n" + "Verantwoordelijke : " + lokalen[i].lokaalVerantwoordelijke + "\n" + "Actief/Inactief : " + (lokalen[i].isActief ? "Actief" : "Inactief")) as WTextRange; textRange.CharacterFormat.FontSize = 13f; //Voorwerpen per lokaal for (int j = 0; j < lokalen[i].Voorwerpen.Count(); j++) { thirdCell = table.Rows[i].Cells[2]; thirdCell.Width = 170; paragraph = thirdCell.AddParagraph(); textRange = paragraph.AppendText("- " + lokalen[i].Voorwerpen[j].aantal + " x " + lokalen[i].Voorwerpen[j].voorwerpNaam + "\n" + (lokalen[i].Voorwerpen[j].defect ? "defect" : "niet defect")) as WTextRange; textRange.CharacterFormat.FontSize = 13f; } } //Saves the Word document to MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); //Closes the Word document document.Close(); stream.Position = 0; return(stream); }
async void OnButtonClicked(object sender, EventArgs args) { //"App" is the class of Portable project Assembly assembly = typeof(App).GetTypeInfo().Assembly; //Creating a new document WordDocument document = new WordDocument(); //Adding a new section to the document WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 10; //Set page size of the section section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); await Nosi.GetNosiScraped(); WTextRange textRange = new WTextRange(document); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); //Appends paragraph foreach (Nosi n in Scraper.NosiList) { paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; textRange = paragraph.AppendText(n.Head) as WTextRange; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Justify; textRange = paragraph.AppendText(n.Content) as WTextRange; } //Appends paragraph section.AddParagraph(); //Saves the Word document to MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); //Save the stream as a file in the device and invoke it for viewing await Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView("Nosi.docx", "application/msword", stream); }
protected void Button1_Click(object sender, EventArgs e) { ErrorMessage.InnerText = ""; if (hdnGroup.Value == "Word") { CheckFileStatus FileStatus = new CheckFileStatus(); string path = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None)); ErrorMessage.InnerText = FileStatus.CheckFile(path); if (ErrorMessage.InnerText == "") { try { //Create a new document WordDocument document = new WordDocument(); //Adding new table to the document WTable doctable = new WTable(document); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(800, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; //Create a character format for declaring font color and style for the text inside the cell WCharacterFormat charFormat = new WCharacterFormat(document); charFormat.TextColor = System.Drawing.Color.White; charFormat.Bold = true; //Initializing the hive server connection HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2); //To initialize a Hive server connection with secured cluster //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>"); //To initialize a Hive server connection with Azure cluster //HqlConnection con = new HqlConnection("<FQDN name of Azure cluster>", 8004, HiveServer.HiveServer2,"<username>","<password>"); con.Open(); //Create table for adventure person contacts HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con); createCommand.ExecuteNonQuery(); HqlCommand command = new HqlCommand("Select * from AdventureWorks_Person_Contact", con); //Executing the query HqlDataReader reader = command.ExecuteReader(); reader.FetchSize = 100; //Fetches the result from the reader and store it in HiveResultSet HiveResultSet result = reader.FetchResult(); //Adding headertext for the table doctable.AddRow(true, false); //Creating new cell WTableCell cell = new WTableCell(document); cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat); cell.Width = 75; //Adding cell to the row doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat); cell.Width = 75; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat); cell.Width = 75; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat); cell.Width = 75; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat); cell.Width = 75; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat); cell.Width = 75; doctable.Rows[0].Cells.Add(cell); //Reading each row from the fetched result for (int i = 0; i < result.Count(); i++) { HiveRecord records = result[i]; doctable.AddRow(true, false); //Reading each data from the row for (int j = 0; j < records.Count; j++) { Object fields = records[j]; //Adding new cell to the document cell = new WTableCell(document); //Adding each data to the cell cell.AddParagraph().AppendText(fields.ToString()); cell.Width = 75; //Adding cell to the table doctable.Rows[i + 1].Cells.Add(cell); doctable.Rows[0].Cells[j].CellFormat.BackColor = Color.FromArgb(51, 153, 51); } } //Adding table to the section section.Tables.Add(doctable); //Save as word 2007 format if (rBtnWord2003.Checked == true) { document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment); } else if (rBtnWord2007.Checked == true) { document.Save("Sample.docx", FormatType.Word2007, Response, HttpContentDisposition.Attachment); } //Save as word 2010 format else if (rbtnWord2010.Checked == true) { document.Save("Sample.docx", FormatType.Word2010, Response, HttpContentDisposition.Attachment); } //Save as word 2013 format else if (rbtnWord2013.Checked == true) { document.Save("Sample.docx", FormatType.Word2013, Response, HttpContentDisposition.Attachment); } //Closing the hive connection con.Close(); } catch (HqlConnectionException) { ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard."; } } } else if (hdnGroup.Value == "Excel") { ErrorMessage.InnerText = ""; CheckFileStatus FileStatus = new CheckFileStatus(); string path = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None)); ErrorMessage.InnerText = FileStatus.CheckFile(path); if (ErrorMessage.InnerText == "") { try { //Instantiate the spreadsheet creation engine. ExcelEngine excelEngine = new ExcelEngine(); //Instantiate the excel application object. IApplication application = excelEngine.Excel; //A new workbook is created.[Equivalent to creating a new workbook in MS Excel] //The new workbook will have 1 worksheets IWorkbook workbook = application.Workbooks.Create(1); //The first worksheet object in the worksheets collection is accessed. IWorksheet worksheet = workbook.Worksheets[0]; //Adding header text for worksheet worksheet[1, 1].Text = "ContactID"; worksheet[1, 2].Text = "FullName"; worksheet[1, 3].Text = "Age"; worksheet[1, 4].Text = "EmailAddress"; worksheet[1, 5].Text = "PhoneNo"; worksheet[1, 6].Text = "ModifiedDate"; //Initializing the hive server connection HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2); //To initialize a Hive server connection with secured cluster //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>"); con.Open(); //Create table for adventure person contacts HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con); createCommand.ExecuteNonQuery(); //Passing the hive query HqlCommand command = new HqlCommand("Select * from AdventureWorks_Person_Contact", con); //Executing the query HqlDataReader reader = command.ExecuteReader(); reader.FetchSize = 100; //Fetches the result from the reader and store it in a seperate set HiveResultSet result = reader.FetchResult(); //Reading each row from the fetched result for (int i = 0; i < result.Count(); i++) { HiveRecord records = result[i]; //Reading each field from the row for (int j = 0; j < records.Count; j++) { Object fields = records[j]; //Assigning each field value to the worksheet based on index worksheet[i + 2, j + 1].Text = fields.ToString(); } } worksheet.Range["A1:F1"].CellStyle.Font.Color = Syncfusion.XlsIO.ExcelKnownColors.White; worksheet.Range["A1:F1"].CellStyle.Font.Bold = true; worksheet.Range["A1:F1"].CellStyle.Color = System.Drawing.Color.FromArgb(51, 153, 51); worksheet.UsedRange.AutofitColumns(); //Saving workbook on user relevant name string fileName = "Sample.xlsx"; //conditions for selecting version //Save as Excel 97to2003 format if (rBtn2003.Checked == true) { workbook.Version = ExcelVersion.Excel97to2003; workbook.SaveAs("Sample.xls", Response, ExcelDownloadType.PromptDialog); } //Save as Excel 2007 formt else if (rBtn2007.Checked == true) { workbook.Version = ExcelVersion.Excel2007; workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog); } //Save as Excel 2010 format else if (rbtn2010.Checked == true) { workbook.Version = ExcelVersion.Excel2010; workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog); } //Save as Excel 2013 format else if (rbtn2013.Checked == true) { workbook.Version = ExcelVersion.Excel2013; workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog); } //closing the workwook workbook.Close(); //Closing the excel engine excelEngine.Dispose(); //Closing the hive connection con.Close(); } catch (HqlConnectionException) { ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard."; } } } }
public ActionResult HelloWorld(string Group1) { if (Group1 == null) { return(View()); } dataPath3 = ResolveApplicationDataPath("", "Images\\DocIO"); // Creating a new document. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new System.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = System.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); WPicture picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "AdventureCycle.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -45; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = System.Drawing.Color.Red; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Mountain-200.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Mountain-300.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Road-550-W.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. section.AddParagraph(); #region saveOption //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)); } #endregion saveOption return(View()); }
public ActionResult DocIOFeatures(string Group1) { if (Group1 == null) { return(View()); } string dataPath3 = ResolveApplicationDataPath("", "Content\\Images\\DocIO"); //A new document is created. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; //Appends paragraph. IWParagraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; WTextRange textRange = paragraph.AppendText("Syncfusion Metro Studio") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Syncfusion Metro Studio is a collection of over 1700 Metro-style icon templates that can be easily customized to create thousands of unique Metro icons. Metro is a design language so it can be applied to any platform or technology. At Syncfusion we have used these icons in everything from PowerPoint presentations to applications written in all .NET platforms including WPF, Silverlight, Windows Phone, Windows Forms, ASP.NET, and ASP.NET MVC.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; #region Insert Table. //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph. WPicture picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio1.png"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Developer-friendly icon editor "); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Metro Studio includes a powerful icon editor that lets you quickly find and customize all the icons that you need in only a few minutes. ") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Convert fonts to icons "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Easily customize thousands of font characters as icons and export them to the desired formats. ") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio2.png"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio3.png"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -4.9f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Organize icons as projects "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Organize icons into projects that can be serialized for modification at a later time. Multiple icons in a project can be exported with a single click. ") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; #endregion //Appends paragraph. section.AddParagraph(); #region saveOption if (Group1 == "Word97To2003") { //Save as .doc Word 97-2003 format return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2007 format else if (Group1 == "Word2007") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2007, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2010 format else if (Group1 == "Word2010") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2010, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2013 format else if (Group1 == "Word2013") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } #endregion saveOption return(View()); }
public ActionResult ExportDefault(string SaveOption) { if (SaveOption == null) { ErrorMessage = ""; return(View()); } else if (SaveOption == "Excel 2013" || SaveOption == "Excel 2010" || SaveOption == "Excel 2007" || SaveOption == "Excel 2003" || SaveOption == "CSV") { ErrorMessage = ""; string path = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv").FullName; CheckFileStatus CheckFile = new CheckFileStatus(); ErrorMessage = CheckFile.CheckFile(path); if (ErrorMessage == "") { try { //Instantiate the spreadsheet creation engine. ExcelEngine excelEngine = new ExcelEngine(); //Instantiate the excel application object. IApplication application = excelEngine.Excel; //A new workbook is created.[Equivalent to creating a new workbook in MS Excel] //The new workbook will have 1 worksheets IWorkbook workbook = application.Workbooks.Create(1); //The first worksheet object in the worksheets collection is accessed. IWorksheet worksheet = workbook.Worksheets[0]; var result = CustomersData.list(); ErrorMessage = null; //Adding header text for worksheet worksheet[1, 1].Text = "Contact Id"; worksheet[1, 2].Text = "Full Name"; worksheet[1, 3].Text = "Age"; worksheet[1, 4].Text = "Phone Number"; worksheet[1, 5].Text = "Email Id"; worksheet[1, 6].Text = "Modified Date"; int i = 1; //Reading each row from the fetched result foreach (PersonDetail records in result) { //Reading each data from the row //Assigning each data to the worksheet based on index worksheet[i + 1, 1].Text = records.ContactId; worksheet[i + 1, 2].Text = records.FullName; worksheet[i + 1, 3].Text = records.Age; worksheet[i + 1, 4].Text = records.PhoneNumber; worksheet[i + 1, 5].Text = records.EmailId; worksheet[i + 1, 6].Text = records.ModifiedDate; i++; } //Assigning Header text with cell color worksheet.Range["A1:F1"].CellStyle.Color = System.Drawing.Color.FromArgb(51, 153, 51); worksheet.Range["A1:F1"].CellStyle.Font.Color = Syncfusion.XlsIO.ExcelKnownColors.White; worksheet.Range["A1:F1"].CellStyle.Font.Bold = true; worksheet.UsedRange.AutofitColumns(); #endregion //Save as .xls format if (SaveOption == "Excel 2003") { return(excelEngine.SaveAsActionResult(workbook, "Sample.xls", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel97)); } //Save as .xlsx format else if (SaveOption == "Excel 2007") { workbook.Version = ExcelVersion.Excel2007; return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2007)); } //Save as .xlsx format else if (SaveOption == "Excel 2010") { workbook.Version = ExcelVersion.Excel2010; return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2010)); } //Save as .xlsx format else if (SaveOption == "Excel 2013") { workbook.Version = ExcelVersion.Excel2013; return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2013)); } //Save as .csv format else if (SaveOption == "CSV") { return(excelEngine.SaveAsActionResult(workbook, "Sample.csv", ",", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.CSV)); } //Close the workbook workbook.Close(); //Close the excelengine excelEngine.Dispose(); } catch (HqlConnectionException) { ErrorMessage = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard."; } } return(View()); } else { ErrorMessage = ""; string path = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv").FullName; CheckFileStatus CheckFile = new CheckFileStatus(); ErrorMessage = CheckFile.CheckFile(path); //A new document is created. if (ErrorMessage == "") { try { WordDocument document = new WordDocument(); //Adding new table to the document WTable doctable = new WTable(document); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(800, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; //Reading the data from the table var result = CustomersData.list(); doctable.AddRow(true, false); //creating new cell WTableCell cell = new WTableCell(document); //Create a character format for declaring font color and style for the text inside the cell WCharacterFormat charFormat = new WCharacterFormat(document); charFormat.TextColor = System.Drawing.Color.White; charFormat.Bold = true; //Adding header text for the table cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat); cell.Width = 75; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); //Adding cell to rows doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat); cell.Width = 90; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat); cell.Width = 75; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat); cell.Width = 90; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat); cell.Width = 180; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat); cell.Width = 125; cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); doctable.Rows[0].Cells.Add(cell); int i = 1; //Reading each row from the fetched result foreach (PersonDetail records in result) { doctable.AddRow(true, false); //Assigning fetched result to the cell cell = new WTableCell(document); cell.AddParagraph().AppendText(records.ContactId.ToString()); cell.Width = 75; doctable.Rows[i].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText(records.FullName.ToString()); cell.Width = 90; doctable.Rows[i].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText(records.Age.ToString()); cell.Width = 75; doctable.Rows[i].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText(records.PhoneNumber.ToString()); cell.Width = 90; doctable.Rows[i].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText(records.EmailId.ToString()); cell.Width = 180; doctable.Rows[i].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText(records.ModifiedDate.ToString()); cell.Width = 125; doctable.Rows[i].Cells.Add(cell); i++; } //Adding table to the section section.Tables.Add(doctable); #region saveOption //Save as .doc Word 97-2003 format if (SaveOption == "Word 97-2003") { return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2007 format else if (SaveOption == "Word 2007") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2007, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2010 format else if (SaveOption == "Word 2010") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2010, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2013 format else if (SaveOption == "Word 2013") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } #endregion saveOption } catch (HqlConnectionException) { ErrorMessage = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard."; } } return(View()); } }
protected void Button1_Click(object sender, EventArgs e) { ErrorMessage.InnerText = ""; if (hdnGroup.Value == "Word") { string path = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hbase samples" }, StringSplitOptions.None)); try { //Create a new document WordDocument document = new WordDocument(); //Adding new table to the document WTable doctable = new WTable(document); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(800, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; //Create a character format for declaring font color and style for the text inside the cell WCharacterFormat charFormat = new WCharacterFormat(document); charFormat.TextColor = System.Drawing.Color.White; charFormat.Bold = true; #region creating connection HBaseConnection con = new HBaseConnection("localhost", 10003); con.Open(); #endregion creating connection #region parsing csv input file csv csvObj = new csv(); object[,] cells; cells = null; cells = csvObj.Table(path, false, ','); #endregion parsing csv input file #region creating table String tableName = "AdventureWorks_Person_Contact"; List <string> columnFamilies = new List <string>(); columnFamilies.Add("info"); columnFamilies.Add("contact"); columnFamilies.Add("others"); if (!HBaseOperation.IsTableExists(tableName, con)) { if (columnFamilies.Count > 0) { HBaseOperation.CreateTable(tableName, columnFamilies, con); } else { throw new HBaseException("ERROR: Table must have at least one column family"); } } # endregion #region Inserting Values string[] column = new string[] { "CONTACTID", "FULLNAME", "AGE", "EMAILID", "PHONE", "MODIFIEDDATE" }; Dictionary <string, IList <HMutation> > rowCollection = new Dictionary <string, IList <HMutation> >(); string rowKey; for (int i = 0; i < cells.GetLength(0); i++) { List <HMutation> mutations = new List <HMutation>(); rowKey = cells[i, 0].ToString(); for (int j = 1; j < column.Length; j++) { HMutation mutation = new HMutation(); mutation.ColumnFamily = j < 3 ? "info" : j < 5 ? "contact" : "others"; mutation.ColumnName = column[j]; mutation.Value = cells[i, j].ToString(); mutations.Add(mutation); } rowCollection[rowKey] = mutations; } HBaseOperation.InsertRows(tableName, rowCollection, con); #endregion Inserting Values #region scan values HBaseOperation.FetchSize = 100; HBaseResultSet table = HBaseOperation.ScanTable(tableName, con); //Adding headertext for the table doctable.AddRow(true, false); //Creating new cell WTableCell cell = new WTableCell(document); cell.AddParagraph().AppendText("ContactId").ApplyCharacterFormat(charFormat); cell.Width = 100; //Adding cell to the row doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("contact:EmailId").ApplyCharacterFormat(charFormat); cell.Width = 200; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("contact:PhoneNo").ApplyCharacterFormat(charFormat); cell.Width = 150; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("info:Age").ApplyCharacterFormat(charFormat); cell.Width = 100; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("info:FullName").ApplyCharacterFormat(charFormat); cell.Width = 150; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("others:ModifiedDate").ApplyCharacterFormat(charFormat); cell.Width = 200; doctable.Rows[0].Cells.Add(cell); //Reading each row from the fetched result for (int i = 0; i < table.Count(); i++) { HBaseRecord records = table[i]; doctable.AddRow(true, false); //Reading each data from the row for (int j = 0; j < records.Count; j++) { Object fields = records[j]; //Adding new cell to the document cell = new WTableCell(document); //Adding each data to the cell cell.AddParagraph().AppendText(fields.ToString()); if (j != 1 && j != 2 && j != 4 && j != 5) { cell.Width = 100; } else if (j == 2 || j == 4) { cell.Width = 150; } else { cell.Width = 200; } //Adding cell to the table doctable.Rows[i + 1].Cells.Add(cell); doctable.Rows[0].Cells[j].CellFormat.BackColor = Color.FromArgb(51, 153, 51); } } //Adding table to the section section.Tables.Add(doctable); //Save as word 2007 format if (rBtnWord2003.Checked == true) { document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment); } else if (rBtnWord2007.Checked == true) { document.Save("Sample.docx", FormatType.Word2007, Response, HttpContentDisposition.Attachment); } //Save as word 2010 format else if (rbtnWord2010.Checked == true) { document.Save("Sample.docx", FormatType.Word2010, Response, HttpContentDisposition.Attachment); } //Save as word 2013 format else if (rbtnWord2013.Checked == true) { document.Save("Sample.docx", FormatType.Word2013, Response, HttpContentDisposition.Attachment); } #endregion scan values #region close connection //Closing the hive connection con.Close(); #endregion close connection }
private void btnCreate_Click(object sender, EventArgs e) { // Creating a new document. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; // style.CharacterFormat.TextColor = Color.FromArgb(46, 116, 181); style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); // Gets the image stream. /* * IWPicture picture = paragraph.AppendPicture(new Bitmap("AdventureCycle.jpg")) as WPicture; * * picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; * picture.VerticalOrigin = VerticalOrigin.Margin; * picture.VerticalPosition = -45; * picture.HorizontalOrigin = HorizontalOrigin.Column; * picture.HorizontalPosition = 263.5f; * picture.WidthScale = 20; * picture.HeightScale = 15; */ paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, AdventureWorks Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the AdventureWorks Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph. /* * picture = paragraph.AppendPicture(new Bitmap("Mountain-200.jpg")) as WPicture; * picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; * picture.VerticalOrigin = VerticalOrigin.Paragraph; * picture.VerticalPosition = 4.5f; * picture.HorizontalOrigin = HorizontalOrigin.Column; * picture.HorizontalPosition = -2.15f; * picture.WidthScale = 79; * picture.HeightScale = 79; */ //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. /* * picture = paragraph.AppendPicture(new Bitmap("Mountain-300.jpg")) as WPicture; * picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; * picture.VerticalOrigin = VerticalOrigin.Paragraph; * picture.VerticalPosition = 8.2f; * picture.HorizontalOrigin = HorizontalOrigin.Column; * picture.HorizontalPosition = -14.95f; * picture.WidthScale = 75; * picture.HeightScale = 75; */ //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. /* * picture = paragraph.AppendPicture(new Bitmap("Road-550-W.jpg")) as WPicture; * picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; * picture.VerticalOrigin = VerticalOrigin.Paragraph; * picture.VerticalPosition = 3.75f; * picture.HorizontalOrigin = HorizontalOrigin.Column; * picture.HorizontalPosition = -5f; * picture.WidthScale = 92; * picture.HeightScale = 92; */ //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. section.AddParagraph(); //Saves the Word document //document.Save("Sample.docx"); // создаем каталог для файла string path = @"C:\SomeDir2"; DirectoryInfo dirInfo = new DirectoryInfo(path); if (!dirInfo.Exists) { dirInfo.Create(); } // запись в файл using (FileStream fstream = new FileStream($"{path}\\Sample.docx", FileMode.OpenOrCreate)) { document.Save(fstream, 0); } }
protected void Button1_Click(object sender, EventArgs e) { WordDocument doc = new WordDocument(); doc.EnsureMinimal(); WParagraph para = doc.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = doc.LastSection.AddParagraph() as WParagraph; para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); if (!this.CheckBox7.Checked) { para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Color.Yellow; } para = doc.LastSection.AddParagraph() as WParagraph; string title = this.TextBox1.Text + "\n"; para.AppendText(title); para.ApplyStyle(BuiltinStyle.Heading4); //Insert TOC TableOfContent toc = para.AppendTOC(1, 3); para.ApplyStyle(BuiltinStyle.Heading4); //Apply built-in paragraph formatting WSection section = doc.LastSection; if (this.RadioButton1.Checked) { #region Default Styles WParagraph newPara = section.AddParagraph() as WParagraph; newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading1); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); section.AddParagraph(); section = doc.AddSection() as WSection; section.BreakCode = SectionBreakCode.NewPage; newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); #endregion } else { #region Custom styles //Custom styles. WParagraphStyle pStyle1 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle1"); WParagraphStyle pStyle2 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle2"); WParagraphStyle pStyle3 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle3"); //Set the Heading Styles to false in order to define custom levels to TOC. toc.UseHeadingStyles = false; //Set the TOC level style which determines; based on which the TOC should be created. toc.SetTOCLevelStyle(1, "MyStyle1"); toc.SetTOCLevelStyle(2, "MyStyle2"); toc.SetTOCLevelStyle(3, "MyStyle3"); section = doc.AddSection() as WSection; pStyle1.CharacterFormat.FontName = "Cambria"; pStyle1.CharacterFormat.FontSize = 30f; para = section.AddParagraph() as WParagraph; WTextRange text = para.AppendText("Document with Custom Styles") as WTextRange; para.ApplyStyle("MyStyle1"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); pStyle2.CharacterFormat.FontName = "Cambria"; pStyle2.CharacterFormat.FontSize = 20f; doc.LastSection.AddParagraph(); para = doc.LastSection.AddParagraph() as WParagraph; text = para.AppendText("Section1") as WTextRange; para.ApplyStyle("MyStyle2"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); pStyle3.CharacterFormat.FontName = "Cambria"; pStyle3.CharacterFormat.FontSize = 14f; doc.LastSection.AddParagraph(); para = doc.LastSection.AddParagraph() as WParagraph; text = para.AppendText("Section2") as WTextRange; para.ApplyStyle("MyStyle3"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); #endregion } if (Convert.ToInt32(this.DropDownList2.Text) < Convert.ToInt32(this.DropDownList1.Text)) { Response.Write("Not a valid heading level range. UpperHeadingLevel must be greater than LowerHeadingLevel"); } else { toc.IncludePageNumbers = this.CheckBox2.Checked; toc.RightAlignPageNumbers = this.CheckBox3.Checked; toc.UseHyperlinks = this.CheckBox4.Checked; toc.LowerHeadingLevel = Convert.ToInt32(this.DropDownList1.Text); toc.UpperHeadingLevel = Convert.ToInt32(this.DropDownList2.Text); //Used to set levels for a word or paragraph through OutLine Levels //Right click text. Select Paragraph option. Set OutlineLevel. Update TOC toc see the text added in TOC. toc.UseOutlineLevels = this.CheckBox5.Checked; //Used to set levels for a word or paragraph through Table Entry Fields //Select the text that should be marked as Table of contents. //Press ALT+SHIFT+O. A dialog box will appear with options to enter the text, select the table identifier and level. //Choose the table identifier and level for the test and click �Mark�. Update TOC toc see the text added in TOC. //Sets the Table Identifier if necessary. //toc.TableID = "B"; toc.UseTableEntryFields = this.CheckBox6.Checked; //Updates the table of contents. if (this.CheckBox7.Checked) { doc.UpdateTableOfContents(); } if (rdButtonDoc.Checked) { //Save as .doc format doc.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment); } //Save as .docx format else if (rdButtonDocx.Checked) { try { doc.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()); } } //Save as WordML(.xml) format if (rdButtonWordML.Checked) { try { doc.Save("Sample.xml", FormatType.WordML, Response, HttpContentDisposition.Attachment); } catch (Win32Exception ex) { Response.Write("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } //Save as .pdf format else if (rdButtonPdf.Checked) { try { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(doc); pdfDoc.Save("Sample.pdf", Response, HttpReadType.Save); } catch (Win32Exception ex) { Response.Write("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } }
void OnButtonClicked(object sender, EventArgs e) { Assembly assembly = typeof(App).GetTypeInfo().Assembly; // Creating a new document. // Creating a new document. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); Stream imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.AdventureCycle.jpg"); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -24; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Mountain-200.jpg"); //Appends picture to the paragraph. picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Mountain-300.jpg"); //Appends picture to the paragraph. picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Road-550-W.jpg"); //Appends picture to the paragraph. picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -4.9f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends paragraph. section.AddParagraph(); MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Word2013); document.Close(); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("GettingStarted.docx", "application/msword", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("GettingStarted.docx", "application/msword", stream); } }
/// <summary> /// Creates a simple Word document with text, image and table. /// </summary> private void Button_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { //Creates a new Word document. using WordDocument document = new(); //Adds a new section to the document. WSection section = document.AddSection() as WSection; //Sets margin of the section. section.PageSetup.Margins.All = 72; //Sets page size of the section. section.PageSetup.PageSize = new SizeF(612, 792); //Creates normal paragraph styles. WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; //Creates heading paragraph style. style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; //Creates paragraph in the Word document. CreateParagraph(section); //Creates product overview table in the Word document. CreateProductOverviewTable(section); #region Document SaveOption using MemoryStream ms = new(); string filename = string.Empty; //Saves as .docx format. if (worddocx.IsChecked == true) { filename = "Hello World.docx"; //Saves the Word document to the memory stream. document.Save(ms, FormatType.Docx); } //Saves as .doc format. else if (worddoc.IsChecked == true) { filename = "Hello World.doc"; //Saves the Word document to the memory stream. document.Save(ms, FormatType.Doc); } //Saves as .pdf format. else if (pdf.IsChecked == true) { filename = "Hello World.pdf"; //Creates a new DocIORenderer instance. using DocIORenderer renderer = new(); //Converts Word document into PDF. using PdfDocument pdfDoc = renderer.ConvertToPDF(document); //Saves the PDF document to the memory stream. pdfDoc.Save(ms); } ms.Position = 0; //Saves the memory stream as file. SaveHelper.SaveAndLaunch(filename, ms); #endregion Document SaveOption }
//Exporting data to word public void ExportToWord() { //A new document is created. WordDocument document = new WordDocument(); //Adding new table to the document WTable doctable = new WTable(document); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(800, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; WCharacterFormat charFormat = new WCharacterFormat(document); charFormat.TextColor = System.Drawing.Color.White; charFormat.Bold = true; doctable.AddRow(true, false); WTableCell cell = new WTableCell(document); cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat); cell.Width = 90; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat); cell.Width = 90; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat); cell.Width = 90; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat); cell.Width = 180; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat); cell.Width = 90; doctable.Rows[0].Cells.Add(cell); cell = new WTableCell(document); cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat); cell.Width = 90; doctable.Rows[0].Cells.Add(cell); //Reading each row from the fetched result for (int i = 0; i < result.Count(); i++) { HiveRecord records = result[i]; doctable.AddRow(true, false); //Reading each field from the row for (int j = 0; j < records.Count; j++) { Object fields = records[j]; //Adding new cell to the document cell = new WTableCell(document); //Adding each field to the cell cell.AddParagraph().AppendText(fields.ToString()); if (j == 3) { cell.Width = 180; } else { cell.Width = 90; } //Adding cell to the table doctable.Rows[i + 1].Cells.Add(cell); doctable.Rows[0].Cells[j].CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51); } } //Adding table to the section section.Tables.Add(doctable); //Save as word 2003 format if (rdbWord2003.IsChecked.Value) { //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 MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] System.Diagnostics.Process.Start("Sample.doc"); //Exit this.Close(); } } //Save as word 2007 format else if (rdbWord2007.IsChecked.Value) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Word2007); //Message box confirmation to view the created document. if (MessageBox.Show("Do you want to view the MS 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] System.Diagnostics.Process.Start("Sample.docx"); //Exit this.Close(); } catch (Win32Exception ex) { MessageBox.Show("Word 2007 is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as word 2010 format else if (rdbWord2010.IsChecked.Value) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Word2010); //Message box confirmation to view the created document. if (MessageBox.Show("Do you want to view the MS 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] System.Diagnostics.Process.Start("Sample.docx"); //Exit this.Close(); } catch (Win32Exception ex) { MessageBox.Show("Word 2010 is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as word 2013 format else if (rdbWord2013.IsChecked.Value) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Word2013); //Message box confirmation to view the created document. if (MessageBox.Show("Do you want to view the MS 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] System.Diagnostics.Process.Start("Sample.docx"); //Exit this.Close(); } catch (Win32Exception ex) { MessageBox.Show("Word 2013 is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } }
public ActionResult ExportFile(int id) { try { //string editor = ""; //editor = "<table><th>1</th><th>2</th></table>"; //// Create a unique file name //string fileName = Guid.NewGuid() + ".docx"; //// Convert HTML text to byte array //byte[] byteArray = Encoding.UTF8.GetBytes(editor.Contains("<html>") ? editor : "<html>" + editor + "</html>"); //// Generate Word document from the HTML //MemoryStream stream = new MemoryStream(byteArray); //Document document = new Document(stream); //// Create memory stream for the Word file //var outputStream = new MemoryStream(); //document.Save(outputStream, SaveFormat.Docx); //outputStream.Position = 0; //// Return generated Word file //return File(outputStream, System.Net.Mime.MediaTypeNames.Application.Rtf, fileName); Package package = null; DateTime date; string addressFrom = "", addressTo; Person From, To; using (ModelDBContainer db = new ModelDBContainer()) { package = db.Packages.Find(id); From = package.PersonFrom; To = package.PersonTo; if (package == null) { throw new Exception("The package was not found"); } var maxDate = package.Records.Select(a => a.DateAndTime).Max(); date = package.Records.Where(a => a.DateAndTime == maxDate).Single().DateAndTime; if (From.CentreId != null) { DistributionCentre c = db.DistributionCentres.Find(From.CentreId); addressFrom = c.City.Region.Country.NameCountry + ", " + c.City.Region.NameRegion + ", " + c.City.NameCity + ", " + c.Address; } else { addressFrom = From.City.Region.Country.NameCountry + ", " + From.City.Region.NameRegion + ", " + From.City.NameCity + ", " + From.Address; } if (To.CentreId != null) { DistributionCentre c = db.DistributionCentres.Find(To.CentreId); addressTo = c.City.Region.Country.NameCountry + ", " + c.City.Region.NameRegion + ", " + c.City.NameCity + ", " + c.Address; } else { addressTo = To.City.Region.Country.NameCountry + ", " + To.City.Region.NameRegion + ", " + To.City.NameCity + ", " + To.Address; } } string companyName = Properties.Settings.Default.CompanyName; // Creating a new document. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 50; //Set page size of the section //section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; // style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = Syncfusion.DocIO.OutlineLevel.Level1; IWParagraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText(companyName) as WTextRange; textRange.CharacterFormat.FontSize = 14f; textRange.CharacterFormat.FontName = "Calibri"; paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left; textRange = paragraph.AppendText("#" + package.Id) as WTextRange; textRange.CharacterFormat.FontSize = 14f; textRange.CharacterFormat.FontName = "Calibri"; paragraph.ApplyStyle("Normal"); //Appends table. IWTable table = section.AddTable(); table.ResetCells(16, 4); table.TableFormat.Borders.BorderType = BorderStyle.Single; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); textRange = paragraph.AppendText("ФИО") as WTextRange; paragraph = table[2, 0].AddParagraph(); textRange = paragraph.AppendText("Компания") as WTextRange; paragraph = table[3, 0].AddParagraph(); textRange = paragraph.AppendText("Адрес") as WTextRange; paragraph = table[4, 0].AddParagraph(); textRange = paragraph.AppendText("Телефон") as WTextRange; string name1 = (From.Name == null ? "" : From.Name) + " " + (From.MiddleName == null ? "" : From.MiddleName) + " " + (From.Surname == null ? "" : From.Surname); paragraph = table[1, 1].AddParagraph(); textRange = paragraph.AppendText(name1) as WTextRange; paragraph = table[2, 1].AddParagraph(); textRange = paragraph.AppendText(From.Company == null ? "":From.Company) as WTextRange; paragraph = table[3, 1].AddParagraph(); textRange = paragraph.AppendText(addressFrom) as WTextRange; paragraph = table[4, 1].AddParagraph(); textRange = paragraph.AppendText(From.Phone == null ? "" : From.Phone) as WTextRange; paragraph = table[6, 0].AddParagraph(); textRange = paragraph.AppendText("ФИО") as WTextRange; paragraph = table[7, 0].AddParagraph(); textRange = paragraph.AppendText("Компания") as WTextRange; paragraph = table[8, 0].AddParagraph(); textRange = paragraph.AppendText("Адрес") as WTextRange; paragraph = table[9, 0].AddParagraph(); textRange = paragraph.AppendText("Телефон") as WTextRange; string name2 = (To.Name == null ? "" : To.Name) + " " + (To.MiddleName == null ? "" : To.MiddleName) + " " + (To.Surname == null ? "" : To.Surname); paragraph = table[6, 1].AddParagraph(); textRange = paragraph.AppendText(name2) as WTextRange; paragraph = table[7, 1].AddParagraph(); textRange = paragraph.AppendText(To.Company == null ? "" : To.Company) as WTextRange; paragraph = table[8, 1].AddParagraph(); textRange = paragraph.AppendText(addressTo) as WTextRange; paragraph = table[9, 1].AddParagraph(); textRange = paragraph.AppendText(To.Phone == null ? "" : To.Phone) as WTextRange; paragraph = table[11, 0].AddParagraph(); textRange = paragraph.AppendText("Дата " + date.ToShortDateString()) as WTextRange; paragraph = table[11, 1].AddParagraph(); textRange = paragraph.AppendText("Время") as WTextRange; paragraph = table[12, 1].AddParagraph(); textRange = paragraph.AppendText("Подпись") as WTextRange; paragraph = table[1, 2].AddParagraph(); textRange = paragraph.AppendText("Объяв.стоимость") as WTextRange; paragraph = table[2, 2].AddParagraph(); textRange = paragraph.AppendText("Описание") as WTextRange; paragraph = table[3, 2].AddParagraph(); textRange = paragraph.AppendText("Вес") as WTextRange; paragraph = table[4, 2].AddParagraph(); textRange = paragraph.AppendText("Размеры") as WTextRange; paragraph = table[5, 2].AddParagraph(); textRange = paragraph.AppendText("Количество") as WTextRange; paragraph = table[6, 2].AddParagraph(); textRange = paragraph.AppendText("Стоимость") as WTextRange; paragraph = table[7, 2].AddParagraph(); textRange = paragraph.AppendText("Курьер") as WTextRange; paragraph = table[7, 3].AddParagraph(); textRange = paragraph.AppendText("Подпись") as WTextRange; paragraph = table[1, 3].AddParagraph(); textRange = paragraph.AppendText(package.DeclaredValue == null ? "" : (package.DeclaredValue.ToString() + " руб")) as WTextRange; paragraph = table[2, 3].AddParagraph(); textRange = paragraph.AppendText(package.Description) as WTextRange; paragraph = table[3, 3].AddParagraph(); textRange = paragraph.AppendText(package.Weight.ToString() + " кг") as WTextRange; paragraph = table[4, 3].AddParagraph(); textRange = paragraph.AppendText(package.Width + "*" + package.Length + "*" + package.Height + " см") as WTextRange; paragraph = table[5, 3].AddParagraph(); textRange = paragraph.AppendText(package.NumberOfPackages.ToString()) as WTextRange; paragraph = table[6, 3].AddParagraph(); textRange = paragraph.AppendText(package.Cost == null ? "" : (package.Cost.ToString() + " руб")) as WTextRange; paragraph = table[15, 2].AddParagraph(); textRange = paragraph.AppendText("Дата Время") as WTextRange; paragraph = table[15, 3].AddParagraph(); textRange = paragraph.AppendText("Подпись") as WTextRange; paragraph = table[14, 2].AddParagraph(); textRange = paragraph.AppendText("Получатель(ФИО)") as WTextRange; paragraph = table[0, 0].AddParagraph(); textRange = paragraph.AppendText("Отправитель") as WTextRange; textRange.CharacterFormat.Bold = true; paragraph = table[5, 0].AddParagraph(); textRange = paragraph.AppendText("Получатель") as WTextRange; textRange.CharacterFormat.Bold = true; paragraph = table[13, 0].AddParagraph(); textRange = paragraph.AppendText("Примечания") as WTextRange; textRange.CharacterFormat.Bold = true; paragraph = table[0, 2].AddParagraph(); textRange = paragraph.AppendText("Информация об отправлении") as WTextRange; textRange.CharacterFormat.Bold = true; paragraph = table[13, 2].AddParagraph(); textRange = paragraph.AppendText("Подтверждение доставки") as WTextRange; textRange.CharacterFormat.Bold = true; //Specifies the horizontal merge table.ApplyHorizontalMerge(0, 0, 1); table.ApplyHorizontalMerge(5, 0, 1); table.ApplyHorizontalMerge(13, 0, 1); table.ApplyHorizontalMerge(0, 2, 3); table.ApplyHorizontalMerge(13, 2, 3); //Appends paragraph. section.AddParagraph(); //Saves the Word document to MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); stream.Position = 0; string fileName = Guid.NewGuid() + ".docx"; //Download Word document in the browser return(File(stream, "application/msword", fileName)); } catch (Exception exp) { TempData["alertMessage"] = "Произошла ошибка при создании файла. Возможно не хватает информации об отправлении."; return(RedirectToAction("Index")); } }