I have to print some content using word document, so that I created word document and print content and its work very fine and I able to get desired result but the thing is that when i shut down my pc(not my application) it asked me to
save book1 and this kind of many dialog boxes which automatically close and pc shut down properly .
I want to avoid this dialog boxes and the main trouble is that when i use my application on laptop it asked me same dialog box but they don't close and i have to close all this dialog boxes manually.
Actually I don't want to save any document i only want print.
so any solution to how to dispose this word document properly I tried many ways but I still getting this dialog boxes.
I only pasting here my main code
private void Print_PromNote(int iGridRowNo, decimal dInstallments)
{
#region // Create & Print Word Document
#region //The C# application developer starts Microsoft Word by creating a new Word application object:
//Microsoft.Office.Interop.Word.Application oWord = new Application();
Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
//By default Microsoft Word will be run invisibly in the background. However, it can be useful to see the document during the development phase of the project:
//oWord.Visible = true;
// the programmer just needs to create an object that will handle these missing values:
object oMissing = System.Reflection.Missing.Value;
//this object can be used when the new document is created:
Microsoft.Office.Interop.Word.Document oDoc = oWord.Documents.Add
(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
#endregion
#region //**Adding Paragraphs to a Microsoft Word Document with C#
//The C# Programmer adds content to a Microsoft Word document by adding paragraphs:
Microsoft.Office.Interop.Word.Paragraph oPara1;
oPara1 = oDoc.Paragraphs.Add(ref oMissing);
oWord.Activedocument.PageSetup.TopMargin = (float)150;
oWord.Activedocument.PageSetup.LeftMargin = (float)150;
oWord.Activedocument.PageSetup.RightMargin = (float)60;
//Any formatting of the paragraph can take place at this point. For example the paragraph can be turned into a heading:
object styleHeading1 = "Heading 1";
oPara1.Range.set_Style(ref styleHeading1);
oPara1.Range.Font.Underline = WdUnderline.wdUnderlineSingle;
//And, of course, the programmer can add text to the paragraph:
oPara1.Range.Text = "PROMISSORY NOTE";
oPara1.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
oPara1.Range.Font.Color= WdColor.wdColorBlack;
oPara1.Range.Font.Name = "Engravers MT";
oPara1.Range.Font.Size = 14;
//oPara1.LineSpacing = 0.8f;
//If further paragraphs are to be added then one final statement is required:
oPara1.Range.InsertParagraphAfter();
//This statement ensures that adding further paragraphs will not overwrite the existing one. Any new paragraphs are added in exactly the same way:
Microsoft.Office.Interop.Word.Paragraph oPara2;
oPara2 = oDoc.Paragraphs.Add(ref oMissing);
oPara2.Range.Text = sPN_Content;
oPara2.Range.Select();
oPara2.Range.Font.Size = 14;
oPara2.Range.Font.Name = "Times New Roman";
oPara2.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
oPara2.LineSpacingRule = WdLineSpacing.wdLineSpaceDouble;
//oPara2.Range.InsertAfter(" Vishu");
oPara2.Range.InsertParagraphAfter();
Microsoft.Office.Interop.Word.Paragraph oPara3;
oPara3 = oDoc.Paragraphs.Add(ref oMissing);
oPara3.Range.Text = "For " + sPNCompanyName;
oPara3.Range.Font.Size = 14;
oPara3.Range.Bold = 1;
oPara3.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle;
oPara3.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oPara3.Range.InsertParagraphAfter();
Microsoft.Office.Interop.Word.Paragraph oPara4;
oPara4 = oDoc.Paragraphs.Add(ref oMissing);
oPara4.Range.Text = System.Environment.NewLine + System.Environment.NewLine + sPNSIgnature;
oPara4.Range.Font.Size = 14;
oPara4.Range.Bold = 1;
oPara4.LineSpacingRule = WdLineSpacing.wdLineSpaceDouble;
oPara4.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oPara4.Range.InsertParagraphAfter();
Microsoft.Office.Interop.Word.Paragraph oPara5;
oPara5 = oDoc.Paragraphs.Add(ref oMissing);
string sFooter = "Important :- Please submit the Promissory Note at the time of Maturity.";
oPara5.Range.Text = sFooter;
oPara5.Range.Bold = 0;
oPara5.Range.Font.Size = 8;
oPara4.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle;
oPara5.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oPara5.Range.InsertParagraphAfter();
if (sInvestmentMode.Trim() == "CHEQUE")
{
Microsoft.Office.Interop.Word.Paragraph oPara6;
oPara6 = oDoc.Paragraphs.Add(ref oMissing);
string sFooter1 = "Subject to TDS deduction.";
oPara6.Range.Text = sFooter1;
oPara6.Range.Bold = 0;
oPara6.Range.Font.Size = 8;
oPara6.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oPara6.Range.InsertParagraphAfter();
}
object myTrue = true; // Print in background
object myFalse = false;
oDoc.PrintOutOld(ref myTrue,
ref myFalse, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref myFalse,
ref oMissing, ref oMissing, ref oMissing);
//In the example above the new paragraphs will just have the default formatting (as can be see in figure 2).
#endregion
// return;
#region //Saving a Microsoft Word Document with C#
////Once the document contains all of the necessary information then it can be saved:
//object fileName = @"C:\Documents and Settings\User\Desktop\Test.doc";
//oDoc.SaveAs(ref fileName,
//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);
////However, it should be noted that this overwrites an existing file of the same name.
////Closing a Microsoft Word Document
////Finally the document can be closed:
//oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
//oDoc = null;
//As can the Word application:
//oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
//oWord = null; // Free up any memory used
System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
#endregion
#endregion
}

New Topic/Question
Reply



MultiQuote




|