Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Inside

Importar dados em MDB

Recommended Posts

Caros amigos,

 

preciso de mais uma ajuda de você. A mais de 1 mês tenho tentando achar um código que pegue os dados de MBD e gere uma planilha Excel. Estou utilizando o componente Softartisans.ExcelWriter. Mas mesmo no site deles não consigo achar nada que resolva, é tudo muito complicado. Vários códigos que estão no site deles nao funcionam quandos e coloca em pratica, com certeza está faltando alguma coisa.

 

Achei esse código que faz o que preciso mas nao consigo descobrir como pegar só os campos que eu quero pois esse código pega todos e ainda mostra o nome do campo em cima dos dados.

 

O que eu preciso é pegar só alguns campos e jogar em determinados locais da planilha que quero gerar.

 

Alguém tem um código mais fácil ou sem componente?

 

 

<%@ Language=VBScript %>
<!-- METADATA TYPE="TypeLib" UUID="{7BCD2133-64A0-4770-843C-090637114583}" -->
<%
'http://www.ambientalclean.com.br/painel/ex.asp?n_ordem=3015

    '--- Declarations
    Dim strDBFilePath
    Dim strConnString
    Dim oConn, oRS
    Dim oXLW, oWS, oRange, oStyleRange, oCells
    Dim oNumStyle, oTextStyle, oCurStyle, oDateStyle, oFontStyle, oHeadingStyle
    Dim intNumRows, intNumCols
    Dim intFirstRow, intFirstCol
    
    Const adOpenStatic = 3

dim n_ordem

n_ordem = request.queryString("n_ordem")

    strDBFilePath = Server.MapPath(Application("vroot") & "../../dados/ocorrencias.mdb")
    
    strConnString = "Driver={Microsoft Access Driver (*.mdb)};" & _ 
                    "Dbq=" & strDBFilePath
                   
    
    '--- Create spreadsheet
    Set oXLW = Server.CreateObject("Softartisans.ExcelWriter")
    Set oWS = oXLW.Worksheets(1)

    '--- Create the formats to be applied later
    Set oFontStyle = oXLW.CreateFont
    If oXLW.Version = 0 Then oFontStyle.Name = "Tahoma"
    oFontStyle.Size = 10
            
    Set oNumStyle = oXLW.CreateStyle
    oNumStyle.Font = oFontStyle
    oNumStyle.HorizontalAlignment = sahaRight

    Set oDateStyle = oXLW.CreateStyle
    oDateStyle.Font = oFontStyle
    oDateStyle.Number = 14 ' m/d/y

    Set oTextStyle = oXLW.CreateStyle
    oTextStyle.Font = oFontStyle
    oTextStyle.HorizontalAlignment = sahaLeft

    Set oCurStyle = oXLW.CreateStyle
    oCurStyle.Font = oFontStyle
    oCurStyle.Number = 8 ' ($#,##0.00_);[red]($#,##0.00)

    Set oHeadingStyle = oXLW.CreateStyle
    oHeadingStyle.Font = oFontStyle
    oHeadingStyle.Font.Bold = True
    oHeadingStyle.Font.Size = 12



    '--- Instantiate an ADO Connection object
    Set oConn = Server.CreateObject("ADODB.Connection")
    '--- Open the database connection
    oConn.Open strConnString
    
    Set oRS = Server.CreateObject("ADODB.RecordSet")
    oRS.Open "SELECT * FROM ocorrencias WHERE n_ordem = " & n_ordem & "", oConn, adOpenStatic
    oRS.MoveFirst

    '--- Get information about the recordset
    intNumRows = oRS.RecordCount
    intNumCols = oRS.Fields.Count
    
    '--- Add Title row
    oWS.Cells("B1").Value = "Ambiental Clean Database"
    oWS.Cells("B1").Style = oHeadingStyle
    oWS.Cells("B1").Format.Font.Size = 14
    oWS.Cells("B1").Format.Font.Bold = True
    oWS.Cells("B1").Format.HorizontalAlignment = sahaCenterAcross

    oWS.Cells("B2").Value = "Orders Query"
    oWS.Cells("B2").Style = oHeadingStyle


    '--- Import the data using CopyFromRecordset
    '--- Set first row and columns, leave room for the headers
    intFirstRow = 3
    intFirstCol = 1

    oWS.Cells.CopyFromRecordset oRS, True, intFirstRow, intFirstCol

    '--- Open the spreadsheet in the browser
    oXLW.Save "database.xls", saOpenInPlace

    '--- Clean up
    oRS.Close
    oConn.Close
    Set oRS = Nothing
    Set oConn = Nothing
    Set oXLW = Nothing
    Response.End
%>

 

Obrigadole pela ajuda e atenção de todos.

Compartilhar este post


Link para o post
Compartilhar em outros sites

ja tentou o XLA2.XLASheet2 e procure no laboratorio de script, existem varios modelos

tente usar a propriedade .Name

Compartilhar este post


Link para o post
Compartilhar em outros sites

Caro xanburzum

 

Isso é um componente? Porque na Locaweb não tem, não posso usar este.

 

Alguma outra solução?

 

Obrigado pela atenção.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.