Quantcast
Channel: Forum SIG - Systèmes d'Information Géographique et Géomatique
Viewing all articles
Browse latest Browse all 8030

[ArcGIS 9.x] Export table to text (.CSV)

$
0
0
Bonjour à tous,



je cherche un code en VBA ArcGIS qui permet l'exportation de ma table illustrée dans mon Grid, vers un fichier text
voila le code que j'ai utilisé pour l'exporter autant que fichier EXCEl
dans j'ai ajouté les références suivant:

'Reference Microsoft ActiveX Data Objects Library
'Reference Microsoft Excel Object Library

et voila le code pour exporter vers excel:
Code:

Private Sub cmd_Excel_Click()    Set pMouseCursor = New MouseCursor
    pMouseCursor.SetCursor 2
 
    Dim ExcelSheet As Object
    Set ExcelSheet = CreateObject("Excel.Sheet")
   
    Dim NewSheet As Object
   
    Dim ColIndexNIRE As Integer
    Grid1.Row = 0
    For i = 0 To Grid1.Cols - 1
        Grid1.Col = i
        If Grid1.Text = "N_IRE" Then
            ColIndexNIRE = i
        End If
    Next i
   
    Grid1.Row = 0
   
    Dim Index As Boolean
    ExcelSheet.Application.Cells(1, 6).value = "Nom du bassin:Zone d'action du bassin SEBOU"
    ExcelSheet.Application.Cells(2, 6).value = "Qualité des eaux de surface"
    ExcelSheet.Application.Cells(3, 1).value = "N°_IRE :" & lbx_N°IRE
    ExcelSheet.Application.Cells(4, 1).value = "Période d'échantillonnage:entre les années hydrologiques 1994 et 2009  "
    For i = 0 To Grid1.Rows - 1
        For j = 0 To Grid1.Cols - 1
            Grid1.Row = i
            Grid1.Col = j
            If ColIndexNIRE = j Then
                ExcelSheet.Application.Cells(i + 6, j + 1).value = Grid1.Text
            ElseIf ColIndexNIRE > j Or ColIndexNIRE < j Then
                ExcelSheet.Application.Cells(i + 6, j + 1).value = Grid1.Text
            End If
            ExcelSheet.Application.Cells(i + 6, j + 1).HorizontalAlignment = xlCenter
           
            If Grid1.CellBackColor = 0 Then
                ExcelSheet.Application.Cells(i + 6, j + 1).Interior.color = vbWhite
            Else
                ExcelSheet.Application.Cells(i + 6, j + 1).Interior.color = Grid1.CellBackColor
            End If
            ExcelSheet.Application.Cells.Font.Bold = True
        Next j
    Next i
 
    'Définitiondu nom du fichier Excel
    Dim NomFichier As String
    CommonDialog.FileName = ""
    CommonDialog.Filter = "Excel|*.xls"
    CommonDialog.ShowSave
    NomFichier = CommonDialog.FileName
    If NomFichier = "" Then
        Exit Sub
    ElseIf NomFichier <> "" Then
        ExcelSheet.SaveAs (NomFichier)
        ExcelSheet.Close
        Set ExcelSheet = Nothing
        'Application Excel
        Dim appExcel As Excel.Application
        'Classeur Excel
        Dim wbExcel As Excel.Workbook
        'Ouverture de l'application
        Set appExcel = CreateObject("Excel.Application")
        'Ouverture d'un fichier Excel
        Set wbExcel = appExcel.Workbooks.Open(NomFichier)
        appExcel.Visible = True
    End If
 
End Sub



merci d'avoir m'indiquer la solution

Viewing all articles
Browse latest Browse all 8030

Trending Articles