コード例 #1
1
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        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");
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        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");
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        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");
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        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");
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        private void button1_Click(object sender, EventArgs e)
        {
            //Create word document
            Document document = new Document();
            document.LoadFromFile(@"..\..\..\..\..\..\Data\Word.doc");

            //Save doc file.
            Image img = document.SaveToImages(0, ImageType.Metafile);
            img.Save("sample.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

            //Launching the image file.
            WordDocViewer("sample.bmp");
        }
コード例 #6
0
ファイル: Form3.cs プロジェクト: OscarUrizar/LoginAndDBForms
        /*******************************************************************************
        * 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);
            }
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        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");
            }
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        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");
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        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");
        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        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");
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        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");
        }
コード例 #12
0
ファイル: MainForm.cs プロジェクト: Chiefs1982/TNG_Database
        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;
        }
コード例 #13
0
        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();

            }
        }
コード例 #14
0
        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();

            }
        }
コード例 #15
0
ファイル: Form1.cs プロジェクト: spirecomponent/Word-Library
        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");
        }