Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
ASP.NET 1.0/1.1
Scrivere in un template di excel???
martedì 13 settembre 2005 - 10.53
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
andreapavia
Profilo
| Senior Member
203
messaggi | Data Invio:
mar 13 set 2005 - 10:53
problema.... se creo un file excel (nuovo)... con questo codice il file mi viene creato tranquillamente e le risorse vengono rilascite correttamente....
supponiamo che io voglia riempire un tempate exel e darlo in pasto ad un utente.....
il file esempio
C:\templete esiste gia' e ha un'intestazione predefinita e devo riempire determinate celle col contenuto di un dataset.....
*********************************************************************
Public Sub CreateExcelFromDadaset(ByVal ds As DataSet, ByVal path As String)
Dim objBooks As Excel.Workbooks
Dim objSheets As Excel.Sheets
Dim objSheet As Excel._Worksheet
Dim range, range1 As Excel.Range
Dim objApp As Excel.Application
Dim objBook As Excel._Workbook
objApp = New Excel.Application
objBooks = objApp.Workbooks
If System.IO.File.Exists(path) Then
objBook = objBooks.Open(path)
objSheet = objApp.ActiveSheet()
Else
objBook = objBooks.Add
objSheets = objBook.Worksheets
objSheet = objSheets(1)
End If
Try
Dim iii As Integer
For iii = 0 To ds.Tables(0).Rows.Count - 1
Dim rangeDs As Excel.Range
rangeDs = objSheet.Range(ds.Tables(0).Rows(iii).Item(1).trim)
rangeDs.Value = ds.Tables(0).Rows(iii).Item(2)
Next
' range1 = objSheet.Range("D11")
'range1.Value() = "ciao"
'Return control of Excel to the user.
objApp.Visible = True
objApp.UserControl = True
objBook.SaveAs(path.Trim)
Catch ex As Exception
Dim msg As String
msg = ex.Message.ToString()
Finally
objSheet = Nothing
objSheets = Nothing
objBooks = Nothing
objApp.Quit()
End Try
End Sub
********************************************************************
se il file è vuoto funziona e lo salva....
se uso il templete non funziona.... si blocca
objBook.SaveAs(path.Trim)
qualcuno sa dirmi dove sbaglio?????
GRAZIE 1000
Torna su
Stanze Forum
Elenco Threads
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 !