public void MergeDoc(string outPutFilePath, params string[] filePath) { object oMissing = System.Reflection.Missing.Value; object oObject = System.Reflection.Missing.Value; Word.ApplicationClass oWord = new Word.ApplicationClass(); Word._Document oDoc = null; oWord.Visible = false; Word.Documents oDocs = oWord.Documents; try { oDoc = oDocs.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); foreach (string fs in filePath) { if (File.Exists(fs)) { oWord.Selection.InsertFile(fs, ref oObject, ref oObject, ref oObject, ref oObject); object obj = Word.WdBreakType.wdPageBreak; //oWord.Selection.InsertBreak(ref obj); } } object objFinalFile = (object)outPutFilePath; oDoc.SaveAs(ref objFinalFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); } catch (Exception e) { } finally { oDoc.Close(ref oMissing, ref oMissing, ref oMissing); } }
public void checkin(Word._Document activeDocument) { try { if (MessageBox.Show(resources.GetString("sure_check_in"), resources.GetString("checkin"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK) { object saveChanges = Word.WdSaveOptions.wdSaveChanges; object missing = Type.Missing; String localFileName = activeDocument.FullName; activeDocument.Close(ref saveChanges, ref missing, ref missing); // Always we save document docXML.refresh(); // Refresh document list if (docXML.isOpenKMDocument(localFileName)) { OKMDocument oKMDocument = docXML.getOpenKMDocument(localFileName); docXML.remove(oKMDocument); DocumentLogic.checkin(oKMDocument, configXML.getHost(), configXML.getUser(), configXML.getPassword()); if (File.Exists(localFileName)) { File.Delete(localFileName); } } } } catch (Exception e) { String errorMsg = "OpenKMWordAddIn - (checkinButton_Click)\n" + e.Message + "\n\n" + e.StackTrace; MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
protected static string OpenWord(string Path) { Word._Application application = null;; Word._Document document = null;; Object _Path = Path; try { application = new Word.Application(); if (!string.IsNullOrEmpty(_Path.ToString())) { document = application.Documents.Open(ref _Path, Type.Missing, (object)false); } application.Visible = true; } catch (Exception error) { try { document.Close(); } catch { } try { application.Quit(); } catch { } document = null; application = null; return(error.Message + "innerExeption: " + error.InnerException.Message); } return("Succed"); }
private void OnNewDoc(Word._Document doc) { if (!deactivateevents) { deactivateevents = true; object dummy = null; doc.Close(ref dummy, ref dummy, ref dummy); deactivateevents = false; } }
/* * public static List<EnvelopeSource> WordImportSourceEnvelopes(string fileName) * { * List<EnvelopeSource> sources = new List<EnvelopeSource>(); * Word._Application objApp = new Word.Application(); * objApp.Visible = false; * objApp.ScreenUpdating = false; * * try * { * Word._Document objDoc = null; * * object objDocName = fileName; * * objDoc = UtilWord.WordOpen(objApp, objDocName); * * int nCountRows = 0; * foreach (Word.Table t in objDoc.Tables) * { * nCountRows += t.Rows.Count; * } * * string sColId = null, sColWho = null, sColAdr = null; * string sColIdPrev = null, sColIdBase; * * foreach (Word.Table t in objDoc.Tables) * { * int tableFirstRow = 3; * for (int i = tableFirstRow; i <= t.Rows.Count; i++) * { * try * { * EnvelopeSource source = new EnvelopeSource(); * * sColIdBase = t.Cell(i, 1).Range.Text; * sColId = Util.TrimId(sColIdBase); * sColWho = t.Cell(i, 2).Range.Text; * sColAdr = t.Cell(i, 3).Range.Text; * * if (string.IsNullOrEmpty(sColId)) * sColId = sColIdPrev; * * source.Adres = sColAdr; * source.Adresat = sColWho; * source.Id = sColId; * * sources.Add(source); * * sColIdPrev = sColId; * } * catch (COMException) * { * if (i > t.Rows.Count) * { * break; * } * } * } * } * objDoc.Close(ref ObjMissing, ref ObjMissing, ref ObjMissing); * } * catch (COMException) * { * } * finally * { * objApp.Quit(ref ObjMissing, ref ObjMissing, ref ObjMissing); * } * return sources; * } */ /* * public static void WordSaveEnvelopes(string fileName, List<Envelope> envelopes) * { * Word._Application app = new Word.Application(); * app.Visible = true; * Word._Document doc = * app.Documents.Add( * ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing); * * Word.Table tab = null; * if (envelopes.Count > 0) * tab = doc.Tables.Add(app.Selection.Range, * envelopes.Count, 3, ref ObjMissing, ref ObjMissing); * * int nRow = 1; * foreach (Envelope envelope in envelopes) * { * tab.Cell(nRow, 1).Range.Text = envelope.Id; * if (envelope.Text != null) * { * tab.Cell(nRow, 2).Range.Text = envelope.Adresat; * tab.Cell(nRow, 3).Range.Text = envelope.Adres; * } * else * { * tab.Cell(nRow, 2).Range.Text = envelope.Adresat; * tab.Cell(nRow, 3).Range.Text = envelope.Adres; * } * * nRow++; * } * WordSaveAs(doc, fileName); * } */ #endregion #region Notification /* * public static string WordShowNotification(string notification, string adresat, string adres) * { * Word._Application wordApp = new Word.Application(); * wordApp.Visible = true; * * bool found = false; * string message = ""; * try * { * Word._Document objDoc = null; * object objStrDoc = notification; * objDoc = WordOpen(wordApp, objStrDoc); * * wordApp.Selection.Find.ClearFormatting(); * wordApp.Selection.Find.Replacement.ClearFormatting(); * * object objMatchText = Properties.Settings.Default.AddressPattern; * object objReplaceWith = adresat; * * found = wordApp.Selection.Find.ExecuteOld(ref objMatchText, * ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, * ref ObjTrue, ref ObjMissing, ref ObjMissing, ref objReplaceWith, ref ObjMissing); * * if (found) * { * if (adresat != "") * wordApp.Selection.TypeText(adresat); * * string[] rows = adres.Split((char)13); * foreach (string row in rows) * { * wordApp.Selection.TypeParagraph(); * wordApp.Selection.TypeText(Util.TrimAdres(row)); * } * } * } * catch (COMException com) * { * return com.Message; * } * finally * { * } * return found ? message : * "Nie znaleziono wyra¿enia do zamiany.\nZawiadomienie powinno zawieraæ ci¹g do podmiany " + * Properties.Settings.Default.AddressPattern; * } */ /* * public static string WordPrintNotification(string notification, string adresat, string adres) * { * Word._Application wordApp = new Word.Application(); * wordApp.Visible = false; * * bool found = false; * string message = ""; * try * { * Word._Document objDoc = null; * object objStrDoc = notification; * objDoc = WordOpen(wordApp, objStrDoc); * * wordApp.Selection.Find.ClearFormatting(); * wordApp.Selection.Find.Replacement.ClearFormatting(); * * object objMatchText = Properties.Settings.Default.AddressPattern; * object objReplaceWith = adresat; * * found = wordApp.Selection.Find.ExecuteOld(ref objMatchText, * ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, * ref ObjTrue, ref ObjMissing, ref ObjMissing, ref objReplaceWith, ref ObjMissing); * * if (found) * { * if (adresat != "") * wordApp.Selection.TypeText(adresat); * * string[] rows = adres.Split((char)13); * foreach (string row in rows) * { * wordApp.Selection.TypeParagraph(); * wordApp.Selection.TypeText(Util.TrimAdres(row)); * } * * objDoc.PrintOutOld(ref ObjTrue, ref ObjMissing, ref ObjMissing, * ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, * ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, * ref ObjMissing); * } * * objDoc.Close(ref ObjFalse, ref ObjMissing, ref ObjMissing); * } * catch (COMException com) * { * message = com.Message; * } * finally * { * while (wordApp.BackgroundPrintingStatus > 0) * { * continue; * } * WordQuit(wordApp); * } * return found ? message : * "Nie znaleziono wyra¿enia do zamiany.\nZawiadomienie powinno zawieraæ ci¹g do podmiany " + * Properties.Settings.Default.AddressPattern; * } */ public static string WordSaveNotificationAsRtf(string notification, string adresat, string adres) { Word._Application wordApp = new Word.Application(); wordApp.Visible = false; string message = ""; try { Word._Document objDoc = null; object objStrDoc = notification; objDoc = WordOpenForWrite(wordApp, objStrDoc); wordApp.Selection.Find.ClearFormatting(); wordApp.Selection.Find.Replacement.ClearFormatting(); object objMatchText = "";// Properties.Settings.Default.AddressPattern; object objReplaceWith = adresat; wordApp.Selection.Find.ExecuteOld(ref objMatchText, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjMissing, ref ObjTrue, ref ObjMissing, ref ObjMissing, ref objReplaceWith, ref ObjMissing); if (adresat != "") { wordApp.Selection.TypeText(adresat); } string[] rows = adres.Split((char)13); foreach (string row in rows) { wordApp.Selection.TypeParagraph(); //wordApp.Selection.TypeText(Util.TrimAdres(row)); } WordSaveAsRtf(objDoc, notification + ".rtf"); objDoc.Close(ref ObjTrue, ref ObjMissing, ref ObjMissing); } catch (COMException com) { message = com.Message; } finally { WordQuit(wordApp); } return(message); }
public string CopyToWord() { object filename = @"C:\" + System.DateTime.Now.ToFileTime() + ".doc"; Word._Application application = new Word.ApplicationClass(); Word._Document document = application.Documents.Add(ref missing, ref missing, ref missing, ref missing); foreach (Excel.Worksheet sheet in wbb.Sheets) { if (sheet.Index == wbb.Sheets.Count) { continue; } for (int i = 1; i < sheet.UsedRange.Rows.Count; i++) { Word.Paragraph para = document.Paragraphs.Add(ref missing); string text = ""; for (int j = 1; j < sheet.UsedRange.Columns.Count; j++) { Excel.Range range = (Excel.Range)sheet.Cells[i, j]; if (range.Value2 != null) { text += range.Value2.ToString() + "\t"; if (range.Value2.ToString().StartsWith("#picture")) { string[] value = System.Text.RegularExpressions.Regex.Split(range.Value2.ToString(), "_"); Excel.Shape shape = sheet.Shapes.Item(int.Parse(value[1])) as Excel.Shape; shape.CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlBitmap); Word.Paragraph picture = document.Paragraphs.Add(ref missing); picture.Range.Paste(); picture.Format.CharacterUnitFirstLineIndent = 2; picture.Range.InsertParagraphAfter(); text = ""; i += int.Parse(value[2]) - 1; break; } } } para.Range.Text = text; para.Format.CharacterUnitFirstLineIndent = 2; para.Range.InsertParagraphAfter(); } } document.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); document.Close(ref missing, ref missing, ref missing); application.Quit(ref missing, ref missing, ref missing); return(filename.ToString()); }
public void CloseControl() { try { deactivateevents = true; object dummy = null; object dummy2 = (object)false; document.Close(ref dummy, ref dummy, ref dummy); applicationClass.Quit(ref dummy2, ref dummy, ref dummy); deactivateevents = false; } catch (Exception ex) { String strErr = ex.Message; } }
private void butPreview_Click(object sender, System.EventArgs e) { #if !DISABLE_MICROSOFT_OFFICE if (listLetters.SelectedIndex == -1) { MsgBox.Show(this, "Please select a letter first."); return; } LetterMerge letterCur = ListForCat[listLetters.SelectedIndex]; letterCur.ImageFolder = comboImageCategory.SelectedTag <Def>().DefNum; string templateFile = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.TemplateName); string dataFile = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.DataFileName); if (!File.Exists(templateFile)) { MsgBox.Show(this, "Template file does not exist."); return; } if (!CreateDataFile(dataFile, letterCur)) { return; } Word.MailMerge wrdMailMerge; //Create an instance of Word. Word.Application WrdApp; try{ WrdApp = LetterMerges.WordApp; } catch { MsgBox.Show(this, "Error. Is Word installed?"); return; } string errorMessage = ""; //Open a document. try { Object oName = templateFile; wrdDoc = WrdApp.Documents.Open(ref oName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdDoc.Select(); } catch (Exception ex) { errorMessage = Lan.g(this, "Error opening document:") + "\r\n" + ex.Message; MessageBox.Show(errorMessage); return; } //Attach the data file. try { wrdMailMerge = wrdDoc.MailMerge; wrdDoc.MailMerge.OpenDataSource(dataFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument; wrdMailMerge.Execute(ref oFalse); } catch (Exception ex) { errorMessage = Lan.g(this, "Error attaching data file:") + "\r\n" + ex.Message; MessageBox.Show(errorMessage); return; } if (letterCur.ImageFolder != 0) //if image folder exist for this letter, save to AtoZ folder //Open document from the atoz folder. { try { WrdApp.Activate(); string tempFilePath = ODFileUtils.CreateRandomFile(Path.GetTempPath(), GetFileExtensionForWordDoc(templateFile)); Object oFileName = tempFilePath; WrdApp.ActiveDocument.SaveAs(oFileName); //save the document to temp location Document doc = SaveToImageFolder(tempFilePath, letterCur); string patFolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath()); string fileName = ImageStore.GetFilePath(doc, patFolder); if (!FileAtoZ.Exists(fileName)) { throw new ApplicationException(Lans.g("LetterMerge", "Error opening document" + " " + doc.FileName)); } FileAtoZ.StartProcess(fileName); WrdApp.ActiveDocument.Close(); //Necessary since we created an extra document try { File.Delete(tempFilePath); //Clean up the temp file } catch (Exception ex) { ex.DoNothing(); } } catch (Exception ex) { FriendlyException.Show(Lan.g(this, "Error saving file to the Image module:") + "\r\n" + ex.Message, ex); } } //Close the original form document since just one record. try { wrdDoc.Saved = true; wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing); } catch (Exception ex) { errorMessage = Lan.g(this, "Error closing document:") + "\r\n" + ex.Message; MessageBox.Show(errorMessage); return; } //At this point, Word remains open with just one new document. try { WrdApp.Activate(); if (WrdApp.WindowState == Word.WdWindowState.wdWindowStateMinimize) { WrdApp.WindowState = Word.WdWindowState.wdWindowStateMaximize; } } catch (Exception ex) { errorMessage = Lan.g(this, "Error showing Microsoft Word:") + "\r\n" + ex.Message; MessageBox.Show(errorMessage); return; } wrdMailMerge = null; wrdDoc = null; Commlog CommlogCur = new Commlog(); CommlogCur.CommDateTime = DateTime.Now; CommlogCur.CommType = Commlogs.GetTypeAuto(CommItemTypeAuto.MISC); CommlogCur.Mode_ = CommItemMode.Mail; CommlogCur.SentOrReceived = CommSentOrReceived.Sent; CommlogCur.PatNum = PatCur.PatNum; CommlogCur.Note = "Letter sent: " + letterCur.Description + ". "; CommlogCur.UserNum = Security.CurUser.UserNum; Commlogs.Insert(CommlogCur); #else MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word."); #endif //this window now closes regardless of whether the user saved the comm item. DialogResult = DialogResult.OK; }
private void butPrint_Click(object sender, System.EventArgs e) { #if DISABLE_MICROSOFT_OFFICE MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word."); return; #endif if (listLetters.SelectedIndex == -1) { MsgBox.Show(this, "Please select a letter first."); return; } LetterMerge letterCur = ListForCat[listLetters.SelectedIndex]; letterCur.ImageFolder = comboImageCategory.SelectedTag <Def>().DefNum; string templateFile = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.TemplateName); string dataFile = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.DataFileName); if (!File.Exists(templateFile)) { MsgBox.Show(this, "Template file does not exist."); return; } PrintDocument pd = new PrintDocument(); if (!PrinterL.SetPrinter(pd, PrintSituation.Default, PatCur.PatNum, "Letter merge " + letterCur.Description + " printed")) { return; } if (!CreateDataFile(dataFile, letterCur)) { return; } Word.MailMerge wrdMailMerge; //Create an instance of Word. Word.Application WrdApp; try { WrdApp = LetterMerges.WordApp; } catch { MsgBox.Show(this, "Error. Is MS Word installed?"); return; } //Open a document. Object oName = templateFile; wrdDoc = WrdApp.Documents.Open(ref oName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdDoc.Select(); wrdMailMerge = wrdDoc.MailMerge; //Attach the data file. wrdDoc.MailMerge.OpenDataSource(dataFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter; //WrdApp.ActivePrinter=pd.PrinterSettings.PrinterName; //replaced with following 4 lines due to MS bug that changes computer default printer object oWBasic = WrdApp.WordBasic; object[] oWBValues = new object[] { pd.PrinterSettings.PrinterName, 1 }; String[] sWBNames = new String[] { "Printer", "DoNotSetAsSysDefault" }; oWBasic.GetType().InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null, oWBasic, oWBValues, null, null, sWBNames); wrdMailMerge.Execute(ref oFalse); if (letterCur.ImageFolder != 0) //if image folder exist for this letter, save to AtoZ folder { try { wrdDoc.Select(); wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument; wrdMailMerge.Execute(ref oFalse); WrdApp.Activate(); string tempFilePath = ODFileUtils.CreateRandomFile(Path.GetTempPath(), GetFileExtensionForWordDoc(templateFile)); Object oFileName = tempFilePath; WrdApp.ActiveDocument.SaveAs(oFileName); //save the document WrdApp.ActiveDocument.Close(); SaveToImageFolder(tempFilePath, letterCur); } catch (Exception ex) { FriendlyException.Show(Lan.g(this, "Error saving file to the Image module:") + "\r\n" + ex.Message, ex); } } //Close the original form document since just one record. wrdDoc.Saved = true; wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing); //At this point, Word remains open with no documents. WrdApp.WindowState = Word.WdWindowState.wdWindowStateMinimize; wrdMailMerge = null; wrdDoc = null; Commlog CommlogCur = new Commlog(); CommlogCur.CommDateTime = DateTime.Now; CommlogCur.CommType = Commlogs.GetTypeAuto(CommItemTypeAuto.MISC); CommlogCur.Mode_ = CommItemMode.Mail; CommlogCur.SentOrReceived = CommSentOrReceived.Sent; CommlogCur.PatNum = PatCur.PatNum; CommlogCur.Note = "Letter sent: " + letterCur.Description + ". "; CommlogCur.UserNum = Security.CurUser.UserNum; Commlogs.Insert(CommlogCur); DialogResult = DialogResult.OK; }
private void butPrint_Click(object sender, System.EventArgs e) { #if DISABLE_MICROSOFT_OFFICE MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word."); return; #endif if(listLetters.SelectedIndex==-1){ MsgBox.Show(this,"Please select a letter first."); return; } LetterMerge letterCur=ListForCat[listLetters.SelectedIndex]; string templateFile=ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath),letterCur.TemplateName); string dataFile=ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath),letterCur.DataFileName); if(!File.Exists(templateFile)){ MsgBox.Show(this,"Template file does not exist."); return; } PrintDocument pd=new PrintDocument(); if(!PrinterL.SetPrinter(pd,PrintSituation.Default)){ return; } if(!CreateDataFile(dataFile,letterCur)){ return; } Word.MailMerge wrdMailMerge; //Create an instance of Word. Word.Application WrdApp=LetterMerges.WordApp; //Open a document. Object oName=templateFile; wrdDoc=WrdApp.Documents.Open(ref oName,ref oMissing,ref oMissing, ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing, ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing); wrdDoc.Select(); wrdMailMerge=wrdDoc.MailMerge; //Attach the data file. wrdDoc.MailMerge.OpenDataSource(dataFile,ref oMissing,ref oMissing,ref oMissing, ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing, ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing); wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter; //WrdApp.ActivePrinter=pd.PrinterSettings.PrinterName; //replaced with following 4 lines due to MS bug that changes computer default printer object oWBasic = WrdApp.WordBasic; object[] oWBValues = new object[] { pd.PrinterSettings.PrinterName, 1 }; String[] sWBNames = new String[] { "Printer", "DoNotSetAsSysDefault" }; oWBasic.GetType().InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null, oWBasic, oWBValues, null, null, sWBNames); wrdMailMerge.Execute(ref oFalse); //Close the original form document since just one record. wrdDoc.Saved=true; wrdDoc.Close(ref oFalse,ref oMissing,ref oMissing); //At this point, Word remains open with no documents. WrdApp.WindowState=Word.WdWindowState.wdWindowStateMinimize; wrdMailMerge=null; wrdDoc=null; Commlog CommlogCur=new Commlog(); CommlogCur.CommDateTime=DateTime.Now; CommlogCur.CommType=Commlogs.GetTypeAuto(CommItemTypeAuto.MISC); CommlogCur.Mode_=CommItemMode.Mail; CommlogCur.SentOrReceived=CommSentOrReceived.Sent; CommlogCur.PatNum=PatCur.PatNum; CommlogCur.Note="Letter sent: "+letterCur.Description+". "; CommlogCur.UserNum=Security.CurUser.UserNum; Commlogs.Insert(CommlogCur); DialogResult=DialogResult.OK; }
private void butPreview_Click(object sender, System.EventArgs e) { #if !DISABLE_MICROSOFT_OFFICE if(listLetters.SelectedIndex==-1){ MsgBox.Show(this,"Please select a letter first."); return; } LetterMerge letterCur=ListForCat[listLetters.SelectedIndex]; string templateFile=ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath),letterCur.TemplateName); string dataFile=ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath),letterCur.DataFileName); if(!File.Exists(templateFile)){ MsgBox.Show(this,"Template file does not exist."); return; } if(!CreateDataFile(dataFile,letterCur)){ return; } Word.MailMerge wrdMailMerge; //Create an instance of Word. Word.Application WrdApp; try{ WrdApp=LetterMerges.WordApp; } catch{ MsgBox.Show(this,"Error. Is Word installed?"); return; } //Open a document. Object oName=templateFile; wrdDoc=WrdApp.Documents.Open(ref oName,ref oMissing,ref oMissing, ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing, ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing); wrdDoc.Select(); wrdMailMerge=wrdDoc.MailMerge; //Attach the data file. wrdDoc.MailMerge.OpenDataSource(dataFile,ref oMissing,ref oMissing,ref oMissing, ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing, ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing); wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument; wrdMailMerge.Execute(ref oFalse); //Close the original form document since just one record. wrdDoc.Saved=true; wrdDoc.Close(ref oFalse,ref oMissing,ref oMissing); //At this point, Word remains open with just one new document. WrdApp.Activate(); if(WrdApp.WindowState==Word.WdWindowState.wdWindowStateMinimize){ WrdApp.WindowState=Word.WdWindowState.wdWindowStateMaximize; } wrdMailMerge=null; wrdDoc=null; Commlog CommlogCur=new Commlog(); CommlogCur.CommDateTime=DateTime.Now; CommlogCur.CommType=Commlogs.GetTypeAuto(CommItemTypeAuto.MISC); CommlogCur.Mode_=CommItemMode.Mail; CommlogCur.SentOrReceived=CommSentOrReceived.Sent; CommlogCur.PatNum=PatCur.PatNum; CommlogCur.Note="Letter sent: "+letterCur.Description+". "; CommlogCur.UserNum=Security.CurUser.UserNum; Commlogs.Insert(CommlogCur); #else MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word."); #endif //this window now closes regardless of whether the user saved the comm item. DialogResult=DialogResult.OK; }
private void butPreview_Click(object sender, System.EventArgs e) { #if !DISABLE_MICROSOFT_OFFICE if (listLetters.SelectedIndex == -1) { MsgBox.Show(this, "Please select a letter first."); return; } LetterMerge letterCur = ListForCat[listLetters.SelectedIndex]; string templateFile = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.TemplateName); string dataFile = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.DataFileName); if (!File.Exists(templateFile)) { MsgBox.Show(this, "Template file does not exist."); return; } if (!CreateDataFile(dataFile, letterCur)) { return; } Word.MailMerge wrdMailMerge; //Create an instance of Word. Word.Application WrdApp; try{ WrdApp = LetterMerges.WordApp; } catch { MsgBox.Show(this, "Error. Is Word installed?"); return; } //Open a document. Object oName = templateFile; wrdDoc = WrdApp.Documents.Open(ref oName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdDoc.Select(); wrdMailMerge = wrdDoc.MailMerge; //Attach the data file. wrdDoc.MailMerge.OpenDataSource(dataFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument; wrdMailMerge.Execute(ref oFalse); //Close the original form document since just one record. wrdDoc.Saved = true; wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing); //At this point, Word remains open with just one new document. WrdApp.Activate(); if (WrdApp.WindowState == Word.WdWindowState.wdWindowStateMinimize) { WrdApp.WindowState = Word.WdWindowState.wdWindowStateMaximize; } wrdMailMerge = null; wrdDoc = null; Commlog CommlogCur = new Commlog(); CommlogCur.CommDateTime = DateTime.Now; CommlogCur.CommType = Commlogs.GetTypeAuto(CommItemTypeAuto.MISC); CommlogCur.Mode_ = CommItemMode.Mail; CommlogCur.SentOrReceived = CommSentOrReceived.Sent; CommlogCur.PatNum = PatCur.PatNum; CommlogCur.Note = "Letter sent: " + letterCur.Description + ". "; CommlogCur.UserNum = Security.CurUser.UserNum; Commlogs.Insert(CommlogCur); #else MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word."); #endif //this window now closes regardless of whether the user saved the comm item. DialogResult = DialogResult.OK; }
private void butPrint_Click(object sender, System.EventArgs e) { if (listLetters.SelectedIndex == -1) { MsgBox.Show(this, "Please select a letter first."); return; } LetterMerge letterCur = ListForCat[listLetters.SelectedIndex]; string templateFile = PrefB.GetString("LetterMergePath") + letterCur.TemplateName; string dataFile = PrefB.GetString("LetterMergePath") + letterCur.DataFileName; if (!File.Exists(templateFile)) { MsgBox.Show(this, "Template file does not exist."); return; } PrintDocument pd = new PrintDocument(); if (!Printers.SetPrinter(pd, PrintSituation.Default)) { return; } if (!CreateDataFile(dataFile, letterCur)) { return; } Word.MailMerge wrdMailMerge; //Create an instance of Word. Word.Application WrdApp = LetterMerges.WordApp; //Open a document. Object oName = templateFile; wrdDoc = WrdApp.Documents.Open(ref oName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdDoc.Select(); wrdMailMerge = wrdDoc.MailMerge; //Attach the data file. wrdDoc.MailMerge.OpenDataSource(dataFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter; WrdApp.ActivePrinter = pd.PrinterSettings.PrinterName; wrdMailMerge.Execute(ref oFalse); //Close the original form document since just one record. wrdDoc.Saved = true; wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing); //At this point, Word remains open with no documents. WrdApp.WindowState = Word.WdWindowState.wdWindowStateMinimize; wrdMailMerge = null; wrdDoc = null; Commlog CommlogCur = new Commlog(); CommlogCur.CommDateTime = DateTime.Now; CommlogCur.CommType = CommItemType.Misc; CommlogCur.Mode_ = CommItemMode.Mail; CommlogCur.SentOrReceived = CommSentOrReceived.Sent; CommlogCur.PatNum = PatCur.PatNum; CommlogCur.Note = "Letter sent: " + letterCur.Description + ". "; Commlogs.Insert(CommlogCur); DialogResult = DialogResult.OK; }
private void CheckSpelling() { TextDocumentHandler handler = new TextDocumentHandler(this.dte); if (handler.HasNonEmptySelection) { try { // Launch Word. Word._Application wordApp = new Word.Application(); // Add a document. Word._Document wordDoc = wordApp.Documents.Add(); // Clear current contents. Word.Range range = wordApp.Selection.Range; range.WholeStory(); range.Delete(); range = null; // Add the text the user selected. wordApp.Selection.Text = handler.SelectedText; // Show it wordApp.Visible = true; wordApp.Activate(); wordDoc.Activate(); // Check spelling wordDoc.CheckSpelling(); // Get the edited text back wordApp.Selection.WholeStory(); string newText = wordApp.Selection.Text; // Word always adds an extra CR, so strip that off. // Also it converts all LFs to CRs, so change // that back. if (!string.IsNullOrEmpty(newText)) { if (newText.EndsWith("\r")) { newText = newText.Substring(0, newText.Length - 1); } newText = newText.Replace("\r", "\r\n"); } handler.SetSelectedTextIfUnchanged(newText, "Check Spelling"); // Tell the doc and Word to go away. object saveChanges = false; wordDoc.Close(ref saveChanges); wordApp.Visible = false; wordApp.Quit(); } catch (COMException ex) { // If we get REGDB_E_CLASSNOTREG, then Word probably isn't installed. const uint REGDB_E_CLASSNOTREG = 0x80040154; if (unchecked ((uint)ex.ErrorCode) == REGDB_E_CLASSNOTREG) { this.package.ShowMessageBox( "Microsoft Word is required in order to check spelling, but it isn't available.\r\n\r\nDetails:\r\n" + ex.Message, true); } else { throw; } } } }
public static bool WordImportUmowa(string fileName, ref string rodzaj, ref string numer, ref string konto, ref string osoba) { Word._Application wordApp = new Word.Application(); wordApp.Visible = true; wordApp.ScreenUpdating = true; object wdStory = Word.WdUnits.wdStory; object wdLine = Word.WdUnits.wdLine; object wdMove = Word.WdMovementType.wdMove; object count1 = (object)1; object wdExtend = Word.WdMovementType.wdExtend; try { Word._Document objDoc = null; object objDocName = fileName; objDoc = WordOpen(wordApp, objDocName); string text = ""; int granica; bool isend = false; granica = 0; while (true)//while szukaj kopert { wordApp.Selection.HomeKey(ref wdLine, ref wdMove); wordApp.Selection.EndKey(ref wdLine, ref wdExtend); if (++granica > 30) { isend = true; } //if(wordApp.Selection.End == ((Word.Range)objDoc.Range).End) // isend = true; text = wordApp.Selection.Text.Trim(); if (text.Contains("UMOWA")) { if (text.Contains("DZIE£O")) { rodzaj = "Umowa o dzie³o"; } else if (text.Contains("ZLECENIE")) { rodzaj = "Umowa na zlecenie"; if (text.Contains("student")) { rodzaj = "Umowa na zlecenie - student"; } } //numer = text.Substring(text.Length - 14); numer = text; } else if (text.Contains("konta")) { konto = text; } if (text.Contains(osoba)) { osoba = text; } wordApp.Selection.HomeKey(ref wdLine, ref wdMove); wordApp.Selection.MoveDown(ref wdLine, ref count1, ref wdMove); if (isend) { break; } }//end while szukaj kopert objDoc.Close(ref ObjMissing, ref ObjMissing, ref ObjMissing); } catch (COMException) { return(false); } finally { wordApp.Quit(ref ObjMissing, ref ObjMissing, ref ObjMissing); } return(true); }