Inserire tabella in documento word.

giovedì 19 luglio 2012 - 13.33

Geronimo79 Profilo | Junior Member

Amici di Dotnethell ho il seguente problema e spero che qualcuno di voi possa aiutarmi. Ho un'applicazione asp.net 4.0 che fa uso di bookmark per compilare file in word. Creo tramite il seguente codice un nuovo file word con una tabella che contiene 4 colonne di dati provenienti da un gridview:

Dim percorso As String = "c:\" Dim AppWord As New Microsoft.Office.Interop.Word.Application AppWord.Visible = False Dim nomeFileOutput As String = "TABELLA.doc" Dim wordDoc As Microsoft.Office.Interop.Word.Document wordDoc = AppWord.Documents.Add Dim R As Microsoft.Office.Interop.Word.Range = wordDoc.Range Dim T As Microsoft.Office.Interop.Word.Table = wordDoc.Tables.Add(R, 1, 4) T.Rows(1).Range.Bold = 1 T.Cell(1, 1).Range.Text = "COLONNA1" T.Cell(1, 2).Range.Text = "COLONNA2" T.Cell(1, 3).Range.Text = "COLONNA3" T.Cell(1, 4).Range.Text = "COLONNA4" 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 T.Cell(i + 1, 1).Range.Text = GridView1.Rows(i).Cells(0).Text & i T.Cell(i + 1, 2).Range.Text = GridView1.Rows(i).Cells(1).Text & i T.Cell(i + 1, 3).Range.Text = GridView1.Rows(i).Cells(2).Text & i T.Cell(i + 1, 4).Range.Text = GridView1.Rows(i).Cells(3).Text & i Next wordDoc.SaveAs(percorso & nomeFileOutput) wordDoc.Close() System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc) AppWord.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(AppWord)


Il problema è che vorrei creare questa tabella in un file word esistente e ovviamente in un punto stabilito. Dovrei forse inserire un bookmark esattamente nel punto in cui vorrei che la tabella fosse posizionata?? Se si qualcuno potrebbe farmi un esempio??
Grazie a tutti un saluto.


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