Torna al Thread

Dim percorso As String = "c:\" Dim nomeFileOutput As String = "fileoutput.doc" Dim oWordApp As New Word.Application Dim fileName As Object = "c:\fileesistente.doc" Dim [readOnly] As Object = False Dim isVisible As Object = False Dim missing As Object = System.Reflection.Missing.Value Dim oWordDoc As Word.Document = oWordApp.Documents.Open(fileName, missing, [readOnly], missing, missing, missing, _ missing, missing, missing, missing, missing, isVisible, _ missing, missing, missing) oWordDoc.Activate() Dim oBookMark As Object = "TABELLA" Dim R As Microsoft.Office.Interop.Word.Range = oWordDoc.Bookmarks.Item(oBookMark).Range 'Creazione Tabella con Riga intestazione Dim T As Microsoft.Office.Interop.Word.Table = oWordDoc.Tables.Add(R, 1, 4) 'GRASSETTO INTESTAZIONE TABELLA' T.Rows(1).Range.Bold = 2 'FONT NAME E GRANDEZZA CARATTERI RIGHE INTESTAZIONE DELLA TABELLA' T.Cell(1, 1).Range.Font.Size = 11 T.Cell(1, 2).Range.Font.Size = 11 T.Cell(1, 3).Range.Font.Size = 11 T.Cell(1, 4).Range.Font.Size = 11 T.Cell(1, 1).Range.Font.Name = "Times New Roman" T.Cell(1, 2).Range.Font.Name = "Times New Roman" T.Cell(1, 3).Range.Font.Name = "Times New Roman" T.Cell(1, 4).Range.Font.Name = "Times New Roman" 'allineo il testo al centro nelle celle' T.Cell(1, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter T.Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter T.Cell(1, 3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter T.Cell(1, 4).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter 'IMPOSTO LA LARGHEZZA DELLE RIGHE INTESTAZIONE DELLA TABELLA' T.Columns.Item(1).Width = 50 T.Columns.Item(2).Width = 50 T.Columns.Item(3).Width = 50 T.Columns.Item(4).Width = 200 'creo le colonne' T.Cell(1, 1).Range.Text = "Dal" T.Cell(1, 2).Range.Text = "Al" T.Cell(1, 3).Range.Text = "Tipo" T.Cell(1, 4).Range.Text = "Giorni" 'Imposto la tabella in modo da essere auto-ingrandita orizzontalmente' T.AutoFitBehavior(Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitWindow) T.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle T.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle For i As Integer = 1 To 4 T.Rows.Add() T.Rows(i + 1).Range.Bold = 0 'FONT NAME E GRANDEZZA CARATTERI RIGHE DELLA TABELLA' T.Rows(i + 1).Range.Font.Size = 10 T.Rows(i + 1).Range.Font.Name = "Times New Roman" 'popolo le colonne con i dati prelevati dal gridview' T.Cell(i + 1, 1).Range.Text = GridView2.Rows(i).Cells(0).Text T.Cell(i + 1, 2).Range.Text = GridView2.Rows(i).Cells(1).Text T.Cell(i + 1, 3).Range.Text = GridView2.Rows(i).Cells(2).Text T.Cell(i + 1, 4).Range.Text = GridView2.Rows(i).Cells(3).Text Next 'Salvataggio / Chiusura Oggetti oWordDoc.SaveAs(percorso & nomeFileOutput) oWordDoc.Close() System.Runtime.InteropServices.Marshal.ReleaseComObject(oWordDoc) 'Chiusura Applicazione Word oWordApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(oWordApp)
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5