Problema nel caricare i dati di un dataset in un file Excel

lunedì 22 giugno 2009 - 12.18

Silvia Terzi Profilo | Newbie

Salve, nel mio website ho creato una procedura che carica i dati di un dataset in un file Excel; dopo molto cercare ho deciso di utilizzare il riferimento: Microsoft.Office.Interop.Excel.dll, tramite il quale ho fatto una procedura che apre e salva dati sul file Excel:

Protected Sub btnConExc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport2.Click
'Keep the application object and the workbook object global, so you can
'retrieve the data in Button2_Click that was set in Button1_Click.

Dim objApp As Excel.Application

Dim objBooks As Excel.Workbooks
Dim objBook As Excel._Workbook

Dim objSheets As Excel.Sheets
Dim objSheet As Excel._Worksheet
Dim range As Excel.Range

' Create a new instance of Excel and start a new workbook.
objApp = New Excel.Application()
objBooks = objApp.Workbooks
objBook = objBooks.Add(System.Reflection.Missing.Value)
objSheets = objBook.Worksheets
objSheet = objSheets(1)

'Get the range where the starting cell has the address
'm_sStartingCell and its dimensions are m_iNumRows x m_iNumCols.
range = objSheet.Range("A1", Reflection.Missing.Value)
range = range.Resize(5, 5)

If (Me.FillWithStrings.Checked = False) Then
'Create an array.
Dim saRet(5, 5) As Double

'Fill the array.
Dim iRow As Long
Dim iCol As Long
For iRow = 0 To 5
For iCol = 0 To 5

'Put a counter in the cell.
saRet(iRow, iCol) = iRow * iCol
Next iCol
Next iRow

'Set the range value to the array.
range.Value = saRet

Else
'Create an array.
Dim saRet(5, 5) As String

'Fill the array.
Dim iRow As Long
Dim iCol As Long
For iRow = 0 To 5
For iCol = 0 To 5

'Put the row and column address in the cell.
saRet(iRow, iCol) = iRow.ToString() + "|" + iCol.ToString()
Next iCol
Next iRow

'Set the range value to the array.
range.Value = saRet
End If

'Return control of Excel to the user.
objApp.Visible = True
objApp.UserControl = True

'Clean up a little.
range = Nothing
objSheet = Nothing
objSheets = Nothing
objBooks = Nothing
End Sub

Finchè testo la procedura sul mio pc è tutto ok.

Quando però ho provato a pubblicare il mio sito su windows server 2008 mi è uscito l’errore:

“Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.”

Non volendo utilizzare una licenza di office su un server che non utilizzo se non come, appunto, server, ho provato ad includere nella cartella bin del mio progetto la dll: Microsoft.Office.Interop.Excel.dll residente sul mio pc; a questo punto mi viene fuori l'errore:

"Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154."

sulla riga:

"Line 271:
Line 272: ' Create a new instance of Excel and start a new workbook.
Line 273: objApp = New Excel.Application()
Line 274: objBooks = objApp.Workbooks
Line 275: objBook = objBooks.Add(System.Reflection.Missing.Value)"

Devo dedurre che su un server su cui pubblico un sito che utilizza tali oggetti devo aver installato Office? Oppure devo semplicemente installare qualche componente??

Grazie mille,

Silvia Terzi
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