Stampare documento Word in C#

giovedì 21 febbraio 2008 - 10.53

dipy Profilo | Junior Member

Salve a tutti!
come posso fare per stampare un file word da C#?

Ferux Profilo | Newbie

Salve,
prova con gli interop:

//References
using word = Microsoft.Office.Interop.Word;

//Paste this code in your function
word.ApplicationClass ac = new word.ApplicationClass();
word.Application app = ac.Application;;
object missingValue = Type.Missing;
object myTrue = true;
object myFalse = false;

try
{
app.DisplayAlerts = word.WdAlertLevel.wdAlertsNone;
object filename = thePathFileToPrint;

// Using OpenOld so as to be compatible with other versions of Word
ord.Document document = app.Documents.OpenOld(ref filename,
ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);

app.ActivePrinter = thePrinterName;

// Using PrintOutOld to be version independant
app.ActiveDocument.PrintOutOld(ref myTrue, ref myFalse, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref myFalse, ref missingValue, ref missingValue, ref missingValue);

document.Close(ref missingValue, ref missingValue, ref missingValue);

while(app.BackgroundPrintingStatus > 0)
{
System.Threading.Thread.Sleep(250);
}

app.Quit(ref missingValue, ref missingValue, ref missingValue);
}
catch(Exception exc)
{
app.Documents.Close(ref myFalse,ref myFalse,ref myFalse);
app.Quit(ref missingValue, ref missingValue, ref missingValue);
}

Spero ti aiuti
Saluti
Ing Ferux
[MCP MCAD]
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5