private void btnView_Click(object sender, EventArgs e) { if (dgvIssueList.SelectedRows.Count <= 0) { return; } var selectedRow = dgvIssueList.SelectedRows; var Location = selectedRow[0].Cells["Location"].Value.ToString(); var FileName = selectedRow[0].Cells["FileName"].Value.ToString(); string filePathName = Utils.getFilePathName(Location, FileName); if (!string.IsNullOrEmpty(filePathName)) { WordDocumentTasks.OpenDocument(filePathName, vkReadOnly: true); } else { MessageBox.Show(@"Document is empty."); } }
// ----------------------------------------------------------------------- // This method replicates an entire folder structure including files // It also replaces the metadata by database fields // ----------------------------------------------------------------------- private void ReplicateFolderFilesReplace() { Word.ApplicationClass vkWordApp = new Word.ApplicationClass(); string sourceFolder = "C:\\projects\\Research\\TestTemplate\\TemplateFrom"; string destinationFolder = "C:\\projects\\Research\\TestTemplate\\TemplateTo"; var ts = new List <WordDocumentTasks.TagStructure>(); ts.Add(new WordDocumentTasks.TagStructure() { Tag = "<<XX>>", TagValue = "VV1" }); ts.Add(new WordDocumentTasks.TagStructure() { Tag = "<<YY>>", TagValue = "VV2" }); ts.Add(new WordDocumentTasks.TagStructure() { Tag = "<<VV>>", TagValue = "VV3" }); WordDocumentTasks.CopyFolder(sourceFolder, destinationFolder); WordDocumentTasks.ReplaceStringInAllFiles(destinationFolder, ts, vkWordApp); }
// ----------------------------------------------------- // This method replicates folders and files for a given // folder structure (source and destination) // ----------------------------------------------------- private void ReplicateFolderFilesReplace() { Cursor.Current = Cursors.WaitCursor; Word.ApplicationClass vkWordApp = new Word.ApplicationClass(); // The source comes from the document set // The destination is selected and stored also // string sourceFolder = txtSourceFolder.Text; string destinationFolder = txtDestinationFolder.Text; if (sourceFolder == "" || destinationFolder == "") { return; } var ts = new List <WordDocumentTasks.TagStructure>(); ts.Add(new WordDocumentTasks.TagStructure() { Tag = "<<XX>>", TagValue = "VV1" }); ts.Add(new WordDocumentTasks.TagStructure() { Tag = "<<YY>>", TagValue = "VV2" }); ts.Add(new WordDocumentTasks.TagStructure() { Tag = "<<VV>>", TagValue = "VV3" }); ts.Add(new WordDocumentTasks.TagStructure() { Tag = "<<ClientNAME>>", TagValue = "Client 2" }); ts.Add(new WordDocumentTasks.TagStructure() { Tag = "<<ClientADDRESS>>", TagValue = "St Street" }); ts.Add(new WordDocumentTasks.TagStructure() { Tag = "<<ClientEMAILADDRESS>>", TagValue = "Email@com" }); ts.Add(new WordDocumentTasks.TagStructure() { Tag = "<<ClientPHONE>>", TagValue = "09393893" }); WordDocumentTasks.CopyFolder(sourceFolder, destinationFolder); WordDocumentTasks.ReplaceStringInAllFiles(destinationFolder, ts, vkWordApp); Cursor.Current = Cursors.Arrow; MessageBox.Show("Project Successfully Created."); }
/// <summary> /// Compare documents /// </summary> /// <param name="Location"></param> /// <param name="Name"></param> /// <param name="Type"></param> /// <param name="DestinationFile"></param> public static void CompareDocuments( string Source, string Destination, string Type) { if (Type == MackkadoITFramework.Helper.Utils.DocumentType.WORD) { WordDocumentTasks.CompareDocuments(Source, Destination); } }
/// <summary> /// Open document /// </summary> /// <param name="document"></param> /// <param name="vkReadOnly"></param> /// <param name="isFromWeb"></param> public static void OpenDocument(Model.ModelDocument.Document document, object vkReadOnly, bool isFromWeb) { if (document.DocumentType == MackkadoITFramework.Helper.Utils.DocumentType.WORD) { string filePathName = Utils.getFilePathName(document.Location, document.Name); WordDocumentTasks.OpenDocument(filePathName, vkReadOnly, isFromWeb); } }
///// <summary> ///// Open document for Document type ///// </summary> ///// <param name="document"></param> //public static void OpenDocument(Document.Document document, object vkReadOnly) //{ // if (document.DocumentType == Utils.DocumentType.WORD) // { // string filePathName = // Utils.getFilePathName(document.Location, // document.Name ); // WordDocumentTasks.OpenDocument(filePathName, vkReadOnly); // } //} // Open document for Location and Name // public static ResponseStatus OpenDocument(string Location, string Name, string Type, object vkReadOnly, bool isFromWeb) { if (Type == DocumentType.WORD) { string filePathName = getFilePathName(Location, Name); var response = WordDocumentTasks.OpenDocument(filePathName, vkReadOnly, isFromWeb); if (response.ReturnCode < 1) { return(response); } } if (Type == DocumentType.EXCEL) { string filePathName = getFilePathName(Location, Name); var response = ExcelSpreadsheetTasks.OpenDocument(filePathName); if (response.ReturnCode < 1) { return(response); } } if (Type == DocumentType.PDF) { string filePathName = getFilePathName(Location, Name); Process proc = new Process(); var adobe = CodeValue.GetCodeValueExtended(iCodeType: MakConstant.CodeTypeString.SYSTSET, iCodeValueID: "PDFEXEPATH"); if (!File.Exists(adobe)) { MessageBox.Show("I can't find Adobe Reader. Please configure SYSTSET.PDFEXTPATH."); var error = new ResponseStatus(MessageType.Error); error.Message = "Adobe Reader can't be found. Please configure SYSTSET.PDFEXTPATH."; return(error); } proc.StartInfo.FileName = adobe; proc.StartInfo.Arguments = filePathName; proc.Start(); } return(new ResponseStatus(MessageType.Informational)); }
private void btnEdit_Click(object sender, EventArgs e) { string filePathName = Utils.getFilePathName(txtLocation.Text, txtFileName.Text); if (!File.Exists(filePathName)) { MessageBox.Show("Document not generated. " + filePathName); return; } WordDocumentTasks.OpenDocument(filePathName, vkReadOnly: false); }
// -------------------------------------------------------- // This method copies the whole folder structure // -------------------------------------------------------- private void btnCopyFolder_Click(object sender, EventArgs e) { string newFolder = "C:\\projects\\Systems\\TemplateCopy"; WordDocumentTasks.CopyFolder( "C:\\projects\\Research\\TestTemplate\\TemplateFrom", newFolder); var parentFolder = Directory.GetParent(newFolder); if (parentFolder != null) { parentFolder.Refresh(); } }
// Open document for Location and Name // public static void OpenDocument(string Location, string Name, string Type, object vkReadOnly, bool isFromWeb = false) { if (Type == MackkadoITFramework.Helper.Utils.DocumentType.WORD) { string filePathName = Utils.getFilePathName(Location, Name); WordDocumentTasks.OpenDocument(filePathName, vkReadOnly, isFromWeb); } if (Type == MackkadoITFramework.Helper.Utils.DocumentType.EXCEL) { string filePathName = Utils.getFilePathName(Location, Name); var Response = ExcelSpreadsheetTasks.OpenDocument(filePathName); if (Response.ReturnCode < 1) { MessageBox.Show(Response.Message); } } if (Type == MackkadoITFramework.Helper.Utils.DocumentType.PDF) { string filePathName = Utils.getFilePathName(Location, Name); System.Diagnostics.Process proc = new System.Diagnostics.Process(); var adobe = CodeValue.GetCodeValueExtended(iCodeType: FCMConstant.CodeTypeString.SYSTSET, iCodeValueID: "PDFEXEPATH"); if (!File.Exists(adobe)) { MessageBox.Show("I can't find Adobe Reader. Please configure SYSTSET.PDFEXTPATH."); return; } proc.StartInfo.FileName = adobe; proc.StartInfo.Arguments = filePathName; proc.Start(); } }
// ------------------------------------------------------- // This method copies one document // ------------------------------------------------------- private void btnCopyDocument_Click(object sender, EventArgs e) { openFileDialog1.Title = "Copy document FROM"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { object fromFileName = openFileDialog1.FileName; object destinationFileName = fromFileName + "_v01.doc"; var fromString = new List <string>(); var toString = new List <string>(); fromString.Add("<<Company Name>>"); toString.Add("Hey Name"); WordDocumentTasks.CopyDocument( fromFileName, destinationFileName, fromString, toString ); } }
/// <summary> /// Get source document. Open a FileDialog window for user to select single/multiple files for /// parsing. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void butSourceDocument_Click(object sender, System.EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { object fileName = openFileDialog.FileName; object saveFile = fileName + "_Vk.doc"; object vk_read_only = false; object vk_visible = true; object vk_false = false; object vk_true = true; object vk_dynamic = 2; object vk_missing = System.Reflection.Missing.Value; // Let make the word application visible vk_word_app.Visible = true; vk_word_app.Activate(); // Let's open the document Word.Document vk_my_doc = vk_word_app.Documents.Open(ref fileName, ref vk_missing, ref vk_read_only, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_visible); // Let's create a new document Word.Document vk_new_doc = vk_word_app.Documents.Add(ref vk_missing, ref vk_missing, ref vk_missing, ref vk_visible); // Select and Copy from the original document vk_my_doc.Select(); vk_word_app.Selection.Copy(); // Paste into new document as unformatted text vk_new_doc.Select(); vk_word_app.Selection.PasteSpecial(ref vk_missing, ref vk_false, ref vk_missing, ref vk_false, ref vk_dynamic, ref vk_missing, ref vk_missing); // close the original document vk_my_doc.Close(ref vk_false, ref vk_missing, ref vk_missing); // Let try to replace Vahe with VAHE in the new document object vk_find = "^l"; object vk_replace = " "; object vk_num = 1; vk_new_doc.Select(); WordDocumentTasks.FindAndReplace( "<<Client Name>>", "tEST", vk_num, vk_word_app); // Save the new document vk_new_doc.SaveAs(ref saveFile, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing); // close the new document vk_new_doc.Close(ref vk_false, ref vk_missing, ref vk_missing); /* * // Let's get the content from the document * Word.Paragraphs vk_my_doc_p = vk_new_doc.Paragraphs; * // Count number of paragraphs in the file * long p_count = vk_my_doc_p.Count; * // step through the paragraphs * for( int i=1; i<=p_count; i++ ) * { * Word.Paragraph vk_p = vk_my_doc_p.Item( i ); * Word.Range vk_r = vk_p.Range; * string text = vk_r.Text; * * MessageBox.Show( text ); * } */ // close word application vk_word_app.Quit(ref vk_false, ref vk_missing, ref vk_missing); } }