Microsoft Developer Network >
포럼 홈
>
Visual C# General
>
can I create & print Word document without saving it as file?
can I create & print Word document without saving it as file?
- Hi,
I wan't to print a word xml (2003) file from memory without saving it to the disk before.
My code now - with physical file:
Microsoft.Office.Interop.Word.Application oApp=new Application();
Microsoft.Office.Interop.Word.Document oDoc=new Document();
oDoc = oApp.Documents.Open(ref FileName.... Can I use here memory stream or something like that?
oDoc.PrintOut(ref objTrue...
Thanks,
Yoss
답변
- Hi,
You can use the code like following.
Note:This is for Office 2007 but using in office 2003 is same.Only parameters may differ.
Microsoft.Office.Interop.Word.Application insApplication = new Microsoft.Office.Interop.Word.Application(); System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture; object missing = System.Reflection.Missing.Value; object objFalse = false; object objTrue = false; try { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); Microsoft.Office.Interop.Word.Document insDocument; insApplication.Visible = false; object Template = Type.Missing; object newTemplate = false; object DocumentType = Microsoft.Office.Interop.Word.WdDocumentType.wdTypeDocument; object Visible = true; insDocument = insApplication.Documents.Add(ref Template, ref newTemplate, ref DocumentType, ref Visible); Microsoft.Office.Interop.Word.Range r; object start = 0; object end = 0; r = insDocument.Range(ref start, ref end); r.Text = "Sample"; insDocument.PrintOut(ref objTrue, ref objTrue, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); insApplication.Quit(ref objFalse, ref missing, ref missing); System.Threading.Thread.CurrentThread.CurrentCulture = oldCI; } catch (Exception ex) { System.Threading.Thread.CurrentThread.CurrentCulture = oldCI; Console.WriteLine(ex); }
- 답변으로 제안됨Tamer OzMVP2009년 11월 6일 금요일 오후 6:28
- 답변으로 표시됨Yoss613 2009년 11월 8일 일요일 오전 5:44
모든 응답
- Hi,
You can use the code like following.
Note:This is for Office 2007 but using in office 2003 is same.Only parameters may differ.
Microsoft.Office.Interop.Word.Application insApplication = new Microsoft.Office.Interop.Word.Application(); System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture; object missing = System.Reflection.Missing.Value; object objFalse = false; object objTrue = false; try { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); Microsoft.Office.Interop.Word.Document insDocument; insApplication.Visible = false; object Template = Type.Missing; object newTemplate = false; object DocumentType = Microsoft.Office.Interop.Word.WdDocumentType.wdTypeDocument; object Visible = true; insDocument = insApplication.Documents.Add(ref Template, ref newTemplate, ref DocumentType, ref Visible); Microsoft.Office.Interop.Word.Range r; object start = 0; object end = 0; r = insDocument.Range(ref start, ref end); r.Text = "Sample"; insDocument.PrintOut(ref objTrue, ref objTrue, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); insApplication.Quit(ref objFalse, ref missing, ref missing); System.Threading.Thread.CurrentThread.CurrentCulture = oldCI; } catch (Exception ex) { System.Threading.Thread.CurrentThread.CurrentCulture = oldCI; Console.WriteLine(ex); }
- 답변으로 제안됨Tamer OzMVP2009년 11월 6일 금요일 오후 6:28
- 답변으로 표시됨Yoss613 2009년 11월 8일 일요일 오전 5:44
- Hi Tamer,
Thank you very much!
Yoss.

