Excel._Worksheet.SaveAs

G

Guest

The applicacion sends me the next message "Method not found:
Excel._Worksheet.SaveAs (..."

I thinks that its about permissions but I do not know how to fix it.

I have the same source in two different servers, It work in one of these but
it doesn's work in the second one.

oExcel = New Excel.Application
oExcel.Visible = False : oExcel.DisplayAlerts = False
'Start a new workbook
oBooks = oExcel.Workbooks
oBooks.Open(sTemplate)
......
oSheet.SaveAs(sFile)
 
G

Guest

I just wrote the lines that have the problem, as I told you It works in one
server but when a try in another server the page send the error with the
methods Open() and SaveAs(),

I will apreciate your help
 
J

Jim Rech

Sheets do not have a save or save as method.

Actually, worksheets do have a SaveAs method, Jim. Seems to save the entire
workbook though so I have no idea why it exists.
 
G

Guest

There is my source and it works well in one machine, but I recieve the next
error message on my production server

Method not found: Void Excel._Worksheet.SaveAs(....


'' Creamos un objeto Excel
Dim oExcel As Excel.Application
Dim oBooks As Excel.Workbooks, oBook As Excel.Workbook
Dim oSheets As Excel.Sheets, oSheet As Excel.Worksheet
Dim oCells As Excel.Range
Dim sFile As String, sTemplate As String

Dim ds As DataSet
Dim iCodigoError As Integer
Dim i, j, iCuantas, iAuxiliar, iPosicion As Integer
Dim sRango1, sRango2, sLetra As String
'Dim p As System.Diagnostics.Process = New System.Diagnostics.Process
Dim vCultura As System.Globalization.CultureInfo =
System.Threading.Thread.CurrentThread.CurrentCulture
Dim dsBitacora As DataSet
Try
'idInstitucion = 9
'idDisposicion = "BANORTE0002"
'idCartera = "E"

'Se establece en inglés la información regional para el
'subproceso actual antes de crear una instancia de Excel
System.Threading.Thread.CurrentThread.CurrentCulture =
System.Globalization.CultureInfo.CreateSpecificCulture("en-US")

i = 1
'asigna rutas para la busqueda del xls base
sFile = Server.MapPath("")
iPosicion = sFile.LastIndexOf(objSeguridad.NombreSitio & "\")
sTemplate = sFile.Substring(0, iPosicion) &
objSeguridad.NombreSitio & "\LibrosExcel\base\MyTemplate.xls"
sFile = sFile.Substring(0, iPosicion) & objSeguridad.NombreSitio
& "\LibrosExcel\MyExcel.xls"

sSql = "Select cl.Descripcion, cc.idCampo from
oCesionLayoutInstitucion cl, cCamposLayoutCesion cc " & _
"where cl.idInstitucion=" & idInstitucion & _
"and cl.IndicadorTipoCartera='" & idCartera & "' and
cc.idCampo=cl.idCampo " & _
"Order by Orden"
objLector = objAccesaBD.fsqldrLeeBD(sSql)
If objLector.HasRows = True Then
ds = objCesion.fdsCesionCreaLayout(idInstitucion,
idDisposicion, idCartera)
If Not ds Is Nothing Then
If ds.Tables(0).Rows.Count <> 0 Then
oExcel = New Excel.Application
'oExcel.Visible = True
oExcel.Visible = False : oExcel.DisplayAlerts = False
'Start a new workbook
oBooks = oExcel.Workbooks
oBooks.Open(sTemplate)
oBook = oBooks.Item(1)
oSheets = oBook.Worksheets
oSheet = CType(oSheets.Item(1), Excel.Worksheet)
'oBook = oExcel.Workbooks.Add
'oSheet = oBook.Worksheets(1)
'oSheet.Visible =
Excel.XlSheetVisibility.xlSheetVisible
'oSheet.Activate()
oSheet.Name = idDisposicion
oCells = oSheet.Cells

'Campos para cabeceras
iCuantas = ds.Tables(0).Rows.Count - 1
If iCuantas = 0 Then iCuantas = 1

While objLector.Read
oSheet.Cells(1, i) = objLector.GetValue(0)
iAuxiliar = objLector.GetValue(1)
If fFormatoNumero(iAuxiliar) Then
sLetra = fEquivalenteLetra(i)
sRango1 = sLetra & 2

sRango2 = sLetra & iCuantas

oCells = oSheet.Range(sRango1, sRango2)
oCells.EntireColumn.NumberFormat =
"###,###,##0.00"
End If
i = i + 1
End While
Else
sError = "No existen datos."
Err.Raise(1)
End If
For i = 0 To ds.Tables(0).Rows.Count - 1
For j = 0 To ds.Tables(0).Columns.Count - 1
If i = 0 Then
i = 1
oSheet.Cells(i + 1, j + 1) =
ds.Tables(0).Rows(i - 1).ItemArray(j)
i = 0
Else
oSheet.Cells(i + 2, j + 1) =
ds.Tables(0).Rows(i).ItemArray(j)
End If
Next
Next
Else
sError = "Error en la generación del layout."
Err.Raise(1)
End If
Else
sError = "No existe configuración para el layout."
Err.Raise(1)
End If
' Bitacora
dsBitacora =
objAdministracion.fdsBitacora(Session("ClaveUsuario"), "Cesión -- Exportar",
"E", " Institución: " & CStr(idInstitucion) & " Disposición: " &
idDisposicion & " Cartera : " & CStr(idCartera), 0)

oSheet.SaveAs(sFile) 'Salva el archivo nuevo en LibrosExcel
 
J

Jim Rech

I don't do VB.NET and I don't know why it works on one machine and not
another. My only suggestion is to replace oSheet with oBook:
oBook.SaveAs(sFile)

--
Jim
| There is my source and it works well in one machine, but I recieve the
next
| error message on my production server
|
| Method not found: Void Excel._Worksheet.SaveAs(....
|
|
| '' Creamos un objeto Excel
| Dim oExcel As Excel.Application
| Dim oBooks As Excel.Workbooks, oBook As Excel.Workbook
| Dim oSheets As Excel.Sheets, oSheet As Excel.Worksheet
| Dim oCells As Excel.Range
| Dim sFile As String, sTemplate As String
|
| Dim ds As DataSet
| Dim iCodigoError As Integer
| Dim i, j, iCuantas, iAuxiliar, iPosicion As Integer
| Dim sRango1, sRango2, sLetra As String
| 'Dim p As System.Diagnostics.Process = New
System.Diagnostics.Process
| Dim vCultura As System.Globalization.CultureInfo =
| System.Threading.Thread.CurrentThread.CurrentCulture
| Dim dsBitacora As DataSet
| Try
| 'idInstitucion = 9
| 'idDisposicion = "BANORTE0002"
| 'idCartera = "E"
|
| 'Se establece en inglés la información regional para el
| 'subproceso actual antes de crear una instancia de Excel
| System.Threading.Thread.CurrentThread.CurrentCulture =
| System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
|
| i = 1
| 'asigna rutas para la busqueda del xls base
| sFile = Server.MapPath("")
| iPosicion = sFile.LastIndexOf(objSeguridad.NombreSitio & "\")
| sTemplate = sFile.Substring(0, iPosicion) &
| objSeguridad.NombreSitio & "\LibrosExcel\base\MyTemplate.xls"
| sFile = sFile.Substring(0, iPosicion) &
objSeguridad.NombreSitio
| & "\LibrosExcel\MyExcel.xls"
|
| sSql = "Select cl.Descripcion, cc.idCampo from
| oCesionLayoutInstitucion cl, cCamposLayoutCesion cc " & _
| "where cl.idInstitucion=" & idInstitucion & _
| "and cl.IndicadorTipoCartera='" & idCartera & "' and
| cc.idCampo=cl.idCampo " & _
| "Order by Orden"
| objLector = objAccesaBD.fsqldrLeeBD(sSql)
| If objLector.HasRows = True Then
| ds = objCesion.fdsCesionCreaLayout(idInstitucion,
| idDisposicion, idCartera)
| If Not ds Is Nothing Then
| If ds.Tables(0).Rows.Count <> 0 Then
| oExcel = New Excel.Application
| 'oExcel.Visible = True
| oExcel.Visible = False : oExcel.DisplayAlerts =
False
| 'Start a new workbook
| oBooks = oExcel.Workbooks
| oBooks.Open(sTemplate)
| oBook = oBooks.Item(1)
| oSheets = oBook.Worksheets
| oSheet = CType(oSheets.Item(1), Excel.Worksheet)
| 'oBook = oExcel.Workbooks.Add
| 'oSheet = oBook.Worksheets(1)
| 'oSheet.Visible =
| Excel.XlSheetVisibility.xlSheetVisible
| 'oSheet.Activate()
| oSheet.Name = idDisposicion
| oCells = oSheet.Cells
|
| 'Campos para cabeceras
| iCuantas = ds.Tables(0).Rows.Count - 1
| If iCuantas = 0 Then iCuantas = 1
|
| While objLector.Read
| oSheet.Cells(1, i) = objLector.GetValue(0)
| iAuxiliar = objLector.GetValue(1)
| If fFormatoNumero(iAuxiliar) Then
| sLetra = fEquivalenteLetra(i)
| sRango1 = sLetra & 2
|
| sRango2 = sLetra & iCuantas
|
| oCells = oSheet.Range(sRango1, sRango2)
| oCells.EntireColumn.NumberFormat =
| "###,###,##0.00"
| End If
| i = i + 1
| End While
| Else
| sError = "No existen datos."
| Err.Raise(1)
| End If
| For i = 0 To ds.Tables(0).Rows.Count - 1
| For j = 0 To ds.Tables(0).Columns.Count - 1
| If i = 0 Then
| i = 1
| oSheet.Cells(i + 1, j + 1) =
| ds.Tables(0).Rows(i - 1).ItemArray(j)
| i = 0
| Else
| oSheet.Cells(i + 2, j + 1) =
| ds.Tables(0).Rows(i).ItemArray(j)
| End If
| Next
| Next
| Else
| sError = "Error en la generación del layout."
| Err.Raise(1)
| End If
| Else
| sError = "No existe configuración para el layout."
| Err.Raise(1)
| End If
| ' Bitacora
| dsBitacora =
| objAdministracion.fdsBitacora(Session("ClaveUsuario"), "Cesión --
Exportar",
| "E", " Institución: " & CStr(idInstitucion) & " Disposición: " &
| idDisposicion & " Cartera : " & CStr(idCartera), 0)
|
| oSheet.SaveAs(sFile) 'Salva el archivo nuevo en LibrosExcel
 
G

Guest

Thanks for your help.
But I have the same problem with the Open() method.

oBooks.Open(sTemplate)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top