private const string OUTDIR = @"c:\temp\WinShop\"; public void GeraFacturaWord( /* acrescentar parametros que entenderem necessários */ ) { object missingValue = Type.Missing; object uchar = Word.WdUnits.wdCharacter; object i1 = 1; // dados da factura // TO DO ir buscar estes dados ao DataSet com a venda int nFactura = 1023; DateTime dataFactura = System.DateTime.Now; // gerar nome de ficheiro object filename = OUTDIR + "Factura-" + nFactura.ToString() + ".doc"; // criar objecto Word Word.Application w = new Word.ApplicationClass(); // criar novo documento w.Documents.Add(ref missingValue, ref missingValue, ref missingValue, ref missingValue); //w.Visible = true; // só para teste/"debug"!!!!! // cabeçalho da factura w.Selection.TypeText("Factura nº "); w.Selection.TypeText(nFactura.ToString()); w.Selection.TypeParagraph(); w.Selection.TypeText("Data : "); w.Selection.TypeText(dataFactura.ToLongDateString()); w.Selection.TypeParagraph(); w.Selection.TypeParagraph(); // // criar tabela (cabeçalho) // object tb = Word.WdDefaultTableBehavior.wdWord9TableBehavior; object afb = Word.WdAutoFitBehavior.wdAutoFitFixed; w.ActiveDocument.Tables.Add(w.Selection.Range, 1, 4, ref tb, ref afb); w.Selection.TypeText("Quantidade"); w.Selection.MoveRight(ref uchar, ref i1, ref missingValue); w.Selection.TypeText("Designação"); w.Selection.MoveRight(ref uchar, ref i1, ref missingValue); w.Selection.TypeText("P.U:"); w.Selection.MoveRight(ref uchar, ref i1, ref missingValue); w.Selection.TypeText("sub-total"); // TO DO adicionar as linhas de factura // TO DO formatar tabela // TO DO rodapé da factura // TO DO gravar ficheiro //terminar Word w.Quit(ref missingValue, ref missingValue, ref missingValue); }