网页抓取小数问题

时间:2020-05-13 23:50:12

标签: excel vba number-formatting decimalformat

im尝试使用vba从网站导入数据到excel,数据导入正常。但是我对数字格式有疑问。网站上的数字显示为206.000,但导入数据时我的工作表仅显示206。我尝试了一切...在Windows的控制面板中更改十进制格式,并在excel的高级选项中更改格式,并始终显示206而不是206.000。如何将数据作为文本导入并防止更改数字以使其与本地格式匹配?

这是我的代码:

    Sub scrap()

On Error Resume Next
    Dim ieObj As InternetExplorer
    Dim htmlEle As IHTMLElement
    Dim i As Integer

Dim LastRowData As Long
Dim LastRowFondos As Long
LastRowFondos = Sheets("Config").Cells(Rows.Count, "A").End(xlUp).Row

For j = 2 To LastRowFondos
    LastRowData = Sheets("CarterasFI").Cells(Rows.Count, "A").End(xlUp).Row - 1

    i = 1 + LastRowData

    Set ieObj = New InternetExplorer
    ieObj.Visible = False
    ieObj.Navigate "http://www.cmfchile.cl/institucional/inc/inf_financiera/ifrs_xml/ifrs_cartera_nac.php?rut=" & Sheets("Config").Range("B" & j) & "&periodo=201912"

    Application.Wait Now + TimeValue("00:00:05")

    For Each htmlEle In ieObj.Document.getElementsByTagName("table")(0).getElementsByTagName("tr")
        With Sheets("CarterasFI")
        'Nemo
            .Range("A" & i).Value = htmlEle.Children(1).textContent
        'Tipo Inst:
            .Range("B" & i).Value = htmlEle.Children(4).textContent
            .Range("C" & i).Value = htmlEle.Children(7).textContent
            .Range("D" & i).Value = htmlEle.Children(9).textContent
            .Range("E" & i).Value = htmlEle.Children(10).textContent
            .Range("F" & i).Value = htmlEle.Children(5).textContent
            .Range("E" & i).Value = Sheets("Config").Range("C" & j)

        End With

        i = i + 1

    Next htmlEle
Next j


End Sub

0 个答案:

没有答案