private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); //load a document document.LoadFromFile(@"..\..\..\..\..\..\Data\Editing.doc"); //Get a paragraph Paragraph paragraph = document.Sections[0].AddParagraph(); //Append Text paragraph.AppendText("Editing sample"); //Save doc file. document.SaveToFile("Sample.doc", FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Open a blank word document as template Document document = new Document(@"..\..\..\..\..\..\Data\Blank.doc"); //Get the first secition Section section = document.Sections[0]; //Create a new paragraph or get the first paragraph Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph(); //Append Text paragraph.AppendText("Builtin Style:"); foreach (BuiltinStyle builtinStyle in Enum.GetValues(typeof(BuiltinStyle))) { paragraph = section.AddParagraph(); //Append Text paragraph.AppendText(builtinStyle.ToString()); //Apply Style paragraph.ApplyStyle(builtinStyle); } //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { List<DictionaryEntry> list = new List<DictionaryEntry>(); DataSet dsData = new DataSet(); dsData.ReadXml(@"..\..\..\..\..\..\Data\Orders.xml"); //Create word document Document document = new Document(); document.LoadFromFile(@"..\..\..\..\..\..\Data\Invoice.doc"); DictionaryEntry dictionaryEntry = new DictionaryEntry("Customer", string.Empty); list.Add(dictionaryEntry); dictionaryEntry = new DictionaryEntry("Order", "Customer_Id = %Customer.Customer_Id%"); list.Add(dictionaryEntry); document.MailMerge.ExecuteWidthNestedRegion(dsData, list); //Save doc file. document.SaveToFile("Sample.doc", FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); Section section = document.AddSection(); //page setup SetPage(section); //insert header and footer InsertHeaderAndFooter(section); //add content InsertContent(section); //encrypt document with password specified by textBox1 document.Encrypt(this.textBox1.Text); //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { string fileName = OpenFile(); string fileMerge = OpenFile(); if ((!string.IsNullOrEmpty(fileName)) && (!string.IsNullOrEmpty(fileMerge))) { //Create word document Document document = new Document(); document.LoadFromFile(fileName,FileFormat.Doc); Document documentMerge = new Document(); documentMerge.LoadFromFile(fileMerge, FileFormat.Doc); foreach( Section sec in documentMerge.Sections) { document.Sections.Add(sec.Clone()); } //Save doc file. document.SaveToFile("Sample.doc", FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); } }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); Section section = document.AddSection(); section.PageSetup.PageSize = PageSize.A4; section.PageSetup.Margins.Top = 72f; section.PageSetup.Margins.Bottom = 72f; section.PageSetup.Margins.Left = 89.85f; section.PageSetup.Margins.Right = 89.85f; Paragraph paragraph = section.AddParagraph(); paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; paragraph.AppendPicture(ToPDF.Properties.Resources.Word); String p1 = "Microsoft Word is a word processor designed by Microsoft. " + "It was first released in 1983 under the name Multi-Tool Word for Xenix systems. " + "Subsequent versions were later written for several other platforms including " + "IBM PCs running DOS (1983), the Apple Macintosh (1984), the AT&T Unix PC (1985), " + "Atari ST (1986), SCO UNIX, OS/2, and Microsoft Windows (1989). "; String p2 = "Microsoft Office Word instead of merely Microsoft Word. " + "The 2010 version appears to be branded as Microsoft Word, " + "once again. The current versions are Microsoft Word 2010 for Windows and 2008 for Mac."; section.AddParagraph().AppendText(p1).CharacterFormat.FontSize = 14; section.AddParagraph().AppendText(p2).CharacterFormat.FontSize = 14; //Save doc file to pdf. document.SaveToFile("Sample.pdf", FileFormat.PDF); //Launching the pdf reader to open. FileViewer("Sample.pdf"); }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); Section section = document.AddSection(); //the unit of all measures below is point, 1point = 0.3528 mm section.PageSetup.PageSize = PageSize.A4; section.PageSetup.Margins.Top = 72f; section.PageSetup.Margins.Bottom = 72f; section.PageSetup.Margins.Left = 89.85f; section.PageSetup.Margins.Right = 89.85f; //insert header and footer InsertHeaderAndFooter(section); addTable(section); //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); Section section = document.AddSection(); //page setup SetPage(section); //insert header and footer InsertHeaderAndFooter(section); //add cover InsertCover(section); //insert a break code section = document.AddSection(); section.BreakCode = SectionBreakType.NewPage; //add content InsertContent(section); //Save doc file. document.SaveToFile("Sample.doc", FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //open form Document document = new Document(@"..\..\..\..\..\..\Data\UserForm.doc"); //load data using (Stream stream = File.OpenRead(@"..\..\..\..\..\..\Data\User.xml")) { XPathDocument xpathDoc = new XPathDocument(stream); XPathNavigator user = xpathDoc.CreateNavigator().SelectSingleNode("/user"); //fill data foreach (FormField field in document.Sections[0].Body.FormFields) { String path = String.Format("{0}/text()", field.Name); XPathNavigator propertyNode = user.SelectSingleNode(path); if (propertyNode != null) { switch (field.Type) { case FieldType.FieldFormTextInput: field.Text = propertyNode.Value; break; case FieldType.FieldFormDropDown: DropDownFormField combox = field as DropDownFormField; for(int i = 0; i < combox.DropDownItems.Count; i++) { if (combox.DropDownItems[i].Text == propertyNode.Value) { combox.DropDownSelectedIndex = i; break; } if (field.Name == "country" && combox.DropDownItems[i].Text == "Others") { combox.DropDownSelectedIndex = i; } } break; case FieldType.FieldFormCheckBox: if (Convert.ToBoolean(propertyNode.Value)) { CheckBoxFormField checkBox = field as CheckBoxFormField; checkBox.Checked = true; } break; } } } } //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); document.LoadFromFile(@"..\..\..\..\..\..\Data\Word.doc"); //Save doc file. document.SaveToFile("Sample.html", FileFormat.Html); //Launching the MS Word file. WordDocViewer("Sample.html"); }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); addTable(document.AddSection()); //Save xml file. document.SaveToFile("Sample.xml",FileFormat.Xml); //Launching the xml file. XMLViewer("Sample.xml"); }
private void button1_Click(object sender, EventArgs e) { //Open a blank word document as template Document document = new Document(@"..\..\..\..\..\..\Data\Blank.doc"); InsertHyberlink(document.Sections[0]); //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
/******************************************************************************* * This is a test button labeled "save as pdf" on the create new progress note form * This is the code to load from a file and read from that file to a new fileformat ********************************************************************************/ private void button2_Click(object sender, EventArgs e) { try { Document document = new Document(); document.LoadFromFile("Test.txt"); document.SaveToFile("PDFTest.pdf", FileFormat.PDF); } catch (Exception ex) { MessageBox.Show("The file could not be saved: " + ex.Message); } }
private void button1_Click(object sender, EventArgs e) { string fileName = OpenFile(); if (!string.IsNullOrEmpty(fileName)) { //Create word document Document document = new Document(); document.LoadFromFile(fileName,FileFormat.Doc,this.textBox1.Text); //Save doc file. document.SaveToFile("Sample.doc", FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); } }
private void button1_Click(object sender, EventArgs e) { Document document = new Document(); //Loading documetn with macros. document.LoadFromFile(@"../../../../../../Data/Macros.docm", FileFormat.Docm); //Removes the macros from the document. document.ClearMacros(); //Save docm file. document.SaveToFile("Sample.docm", FileFormat.Docm); //Launching the MS Word file. WordDocViewer("Sample.docm"); }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); //load a document document.LoadFromFile(@"..\..\..\..\..\..\Data\FindAndReplace.doc"); //Replace text document.Replace(this.textBox1.Text, this.textBox2.Text,true,true); //Save doc file. document.SaveToFile("Sample.doc", FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); document.LoadFromFile(@"..\..\..\..\..\..\Data\Fax.doc"); string[] filedNames = new string[]{"Contact Name","Fax","Date"}; string[] filedValues = new string[]{"John Smith","+1 (69) 123456",System.DateTime.Now.Date.ToString()}; document.MailMerge.Execute(filedNames, filedValues); //Save doc file. document.SaveToFile("Sample.doc", FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Open a blank word document as template Document document = new Document(@"..\..\..\..\..\..\Data\Blank.doc"); document.BuiltinDocumentProperties.Title = "Document Demo Document"; document.BuiltinDocumentProperties.Subject = "demo"; document.BuiltinDocumentProperties.Author = "James"; document.BuiltinDocumentProperties.Company = "e-iceblue"; document.BuiltinDocumentProperties.Manager = "Jakson"; document.BuiltinDocumentProperties.Category = "Doc Demos"; document.BuiltinDocumentProperties.Keywords = "Document, Property, Demo"; document.BuiltinDocumentProperties.Comments = "This document is just a demo."; Section section = document.Sections[0]; section.PageSetup.Margins.Top = 72f; section.PageSetup.Margins.Bottom = 72f; section.PageSetup.Margins.Left = 89.85f; section.PageSetup.Margins.Right = 89.85f; String p1 = "Microsoft Word is a word processor designed by Microsoft. " + "It was first released in 1983 under the name Multi-Tool Word for Xenix systems. " + "Subsequent versions were later written for several other platforms including " + "IBM PCs running DOS (1983), the Apple Macintosh (1984), the AT&T Unix PC (1985), " + "Atari ST (1986), SCO UNIX, OS/2, and Microsoft Windows (1989). "; String p2 = "Microsoft Office Word instead of merely Microsoft Word. " + "The 2010 version appears to be branded as Microsoft Word, " + "once again. The current versions are Microsoft Word 2010 for Windows and 2008 for Mac."; Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph(); paragraph.AppendText(p1).CharacterFormat.FontSize = 14; section.AddParagraph().AppendText(p2).CharacterFormat.FontSize = 14; //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); //Create a new secition Section section = document.AddSection(); //Create a new paragraph Paragraph paragraph = section.AddParagraph(); //Append Text paragraph.AppendText("Hello World!"); //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Open a blank word document as template Document document = new Document(@"..\..\..\..\..\..\Data\Blank.doc"); //Get the first secition Section section = document.Sections[0]; //Create a new paragraph or get the first paragraph Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph(); //Append Text paragraph.AppendText("Using items list to show Indent demo."); paragraph.ApplyStyle(BuiltinStyle.Heading3); paragraph = section.AddParagraph(); for (int i = 0; i < 10; i++) { paragraph = section.AddParagraph(); paragraph.AppendText(String.Format("Indent Demo Node{0}", i)); if(i == 0) { paragraph.ListFormat.ApplyBulletStyle(); } else { paragraph.ListFormat.ContinueListNumbering(); } paragraph.ListFormat.CurrentListLevel.NumberPosition = -10; } //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Open a blank word document as template Document document = new Document(@"..\..\..\..\..\..\Data\Blank.doc"); //Get the first secition Section section = document.Sections[0]; //Create a new paragraph or get the first paragraph Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph(); //Append Text String text = "This paragraph is demo of text font and color. " + "The font name of this paragraph is Tahoma. " + "The font size of this paragraph is 20. " + "The under line style of this paragraph is DotDot. " + "The color of this paragraph is Blue. "; TextRange txtRange = paragraph.AppendText(text); //Font name txtRange.CharacterFormat.FontName = "Tahoma"; //Font size txtRange.CharacterFormat.FontSize = 20; //Underline txtRange.CharacterFormat.UnderlineStyle = UnderlineStyle.DotDot; //Change text color txtRange.CharacterFormat.TextColor = Color.Blue; //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); //load a document document.LoadFromFile(@"..\..\..\..\..\..\Data\FindAndReplace.doc"); //Find text TextSelection[] textSelections = document.FindAllString(this.textBox1.Text, true, true); //Set hightlight foreach(TextSelection selection in textSelections) { selection.GetAsOneRange().CharacterFormat.HighlightColor = Color.Yellow; } //Save doc file. document.SaveToFile("Sample.doc", FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private string ConvertWordToCSVFile(OpenFileDialog file) { string filename = ""; string newFilename = ""; if (file.OpenFile() != null) { //string for converted filename filename = @"tmp\" + Path.GetFileNameWithoutExtension(file.FileName) + "_converted.txt"; //Start new document and load from selected file Document doc = new Document(); doc.LoadFromFile(Path.GetFullPath(@"" + file.FileName)); //check to see if file exists, if it does clear it if (!File.Exists(@"" + filename)) { //Log file did not exist Directory.CreateDirectory(@"tmp"); File.Create(@"" + filename).Close(); Debug.WriteLine("File doesn't exist"); } else { //Clear File File.WriteAllText(@"" + filename, string.Empty); Debug.WriteLine("File Cleared"); } //save converted format to new text file doc.SaveToFile(@"" + filename, FileFormat.Txt); } file.FileName = @"" + filename; Stream convertFile = null; if ((convertFile = file.OpenFile()) != null) { try { //items for string line; string newLine; string finalLine = ""; List<string> lineList = new List<string>(); char[] seperators = ",".ToCharArray(); //streamReader to read csv file StreamReader textReader = new StreamReader(convertFile); while ((line = textReader.ReadLine()) != null) { //check if line is empty of if first character is a number if (!string.IsNullOrEmpty(line) && char.IsDigit(line[0])) { finalLine = ""; lineList.Clear(); newLine = line.Trim().Replace("\t", ",").Replace(",,", ",").Replace(",,,", ","); newFilename = @"tmp\" + Path.GetFileNameWithoutExtension(file.FileName) + "_import.csv"; //if last character is a comma delete the comma while (newLine[newLine.Length - 1].Equals(",")) { newLine = newLine.Remove(newLine.Length - 1, 1); } string[] lineArray = newLine.Split(seperators, 3); foreach (string value in lineArray) { lineList.Add(value.Trim()); } //final line with commas seperating values finalLine = string.Join(",", lineList); if (!File.Exists(@"" + newFilename)) { //Log file did not exist Directory.CreateDirectory(@"outputs"); Debug.WriteLine("Log files does not exist"); File.Create(@"" + newFilename).Close(); } //Write to log file using (StreamWriter csvWriter = File.AppendText(@"" + newFilename)) { //Log Format csvWriter.WriteLine("{0}", finalLine); csvWriter.Close(); } } } textReader.Close(); convertFile.Close(); //delete file after use if (File.Exists(Path.GetFullPath(filename))) { File.Delete(Path.GetFullPath(filename)); Debug.WriteLine("File Deleted"); } } catch (Exception error) { MainForm.LogFile(error.Message); } } return newFilename; }
private void importButton_Click(object sender, EventArgs e) { // clears the textbox before a contract is loaded contract_tb.Clear(); // opening the openfiledialog1 control to allow the user to select a file if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { //Create a document object Document document = new Document(); document.LoadFromFile(openFileDialog1.FileName); /************************************************************ * Drashtee this is where the file gets saved as a .txt files * named Test, we need it to be saved as something that changes * so that we dont get the file is in use by another process * error, do this however you see fit. To test if it works, * open 1 contract and then try to open another after the first * contract is successfully loaded *************************************************************/ //Save doc file to a txt format. document.SaveToFile("Test.txt", FileFormat.Txt); } catch (Exception ex) { MessageBox.Show("The file could not be read: " + ex.Message); } TextToBox(); } }
private void button1_Click(object sender, EventArgs e) { //Create word document Document document = new Document(); document.LoadFromFile(@"..\..\..\..\..\..\Data\Fax2.doc"); lastIndex = 0; List<CustomerRecord> customerRecords = new List<CustomerRecord>(); CustomerRecord c1 = new CustomerRecord(); c1.ContactName = "Lucy"; c1.Fax = "786-324-10"; c1.Date = DateTime.Now; customerRecords.Add(c1); CustomerRecord c2 = new CustomerRecord(); c2.ContactName = "Lily"; c2.Fax = "779-138-13"; c2.Date = DateTime.Now; customerRecords.Add(c2); CustomerRecord c3 = new CustomerRecord(); c3.ContactName = "James"; c3.Fax = "363-287-02"; c3.Date = DateTime.Now; customerRecords.Add(c3); //Execute mailmerge document.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField); document.MailMerge.ExecuteGroup(new MailMergeDataTable("Customer", customerRecords)); //Save doc file. document.SaveToFile(@"Sample.doc", FileFormat.Doc); //Launching the MS Word file. WordDocViewer(@"Sample.doc"); }
private void importButton_Click(object sender, EventArgs e) { // clears the textbox before a contract is loaded contract_tb.Clear(); // opening the openfiledialog1 control to allow the user to select a file if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { //Create a document object Document document = new Document(); document.LoadFromFile(openFileDialog1.FileName); docToTxtName = openFileDialog1.FileName + ".txt"; //Save doc file to a txt format. document.SaveToFile(docToTxtName, FileFormat.Txt); document.Close(); } catch (Exception ex) { MessageBox.Show("The file could not be read: " + ex.Message); } TextToBox(); } }
private void button1_Click(object sender, EventArgs e) { Document document = new Document(); Section section = document.AddSection(); //page setup SetPage(section); //insert header and footer. InsertHeaderAndFooter(section); //add title AddTitle(section); //add form AddForm(section); //protect document, only form fields could be edited. document.Protect(ProtectionType.AllowOnlyFormFields, "e-iceblue"); //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }
private void button1_Click(object sender, EventArgs e) { //Open a blank word document as template Document document = new Document(@"..\..\..\..\..\..\Data\Blank.doc"); //Get the first secition Section section = document.Sections[0]; //Create a new paragraph or get the first paragraph Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph(); //Append Text paragraph.AppendText("The various ways to format paragraph text in Microsoft Word:"); paragraph.ApplyStyle(BuiltinStyle.Heading1); //Append alignment text AppendAligmentText(section); //Append indentation text AppendIndentationText(section); AppendBulletedList(section); //Save doc file. document.SaveToFile("Sample.doc",FileFormat.Doc); //Launching the MS Word file. WordDocViewer("Sample.doc"); }