zoukankan      html  css  js  c++  java
  • VBA读excel写xml

    VBA

    ◆写文件
    Dim sFile As Object, fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")

    sFile.WriteLine (String(8, " ") & "<Request>")

    sFile.Close
    Set sFile = Nothing
    Set fso = Nothing

    ◆选择文件夹
    With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show = -1 Then
    folder = .SelectedItems(1)

    End If
    End With
    MsgBox folder & "/TaskInfo.xml"


    ◆循环/IF
    Do While Cells(rowIndex, 2).Value <> ""
    For compCol = 8 To 17 Step 1

    If idStr < 10 Then
    sFile.WriteLine (String(12, " ") & "<Complete id=""0" & idStr & """ />")
    Else
    sFile.WriteLine (String(12, " ") & "<Complete id=""" & idStr & """ />")
    End If

    Next compCol

    Loop


    ◆完整


    Sub CreateFile()

    Dim sFile As Object, fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")

    folder = "D:"

    With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show = -1 Then
    folder = .SelectedItems(1)

    End If
    End With
    MsgBox folder & "/TaskInfo.xml"

    Set sFile = fso.CreateTextFile(folder & "/TaskInfo.xml", True)

    sFile.WriteLine ("<?xml version=""1.0"" encoding=""UTF-8""?>")
    sFile.WriteLine ("<Tasks>")

    rowIndex = 4

    Do While Cells(rowIndex, 2).Value <> ""
    ' タスクID
    taskId = Cells(rowIndex, 2).Value

    ' 家電対象
    obj = Cells(rowIndex, 4).Value

    sFile.WriteLine (String(4, " ") & "<Task id=""" & taskId & """ obj=""" & obj & """>")

    sFile.WriteLine (String(8, " ") & "<Request>")


    For compCol = 8 To 17 Step 1
    ' 補完ID
    compId = Cells(rowIndex, compCol).Value

    If compId <> "" Then

    idStr = compCol - 7
    If idStr < 10 Then
    sFile.WriteLine (String(12, " ") & "<Complete id=""0" & idStr & """ />")
    Else
    sFile.WriteLine (String(12, " ") & "<Complete id=""" & idStr & """ />")
    End If

    End If

    Next compCol


    sFile.WriteLine (String(8, " ") & "</Request>")

    ' URL
    URL = Cells(rowIndex, 5).Value

    ' Path
    Path = Cells(rowIndex, 6).Value

    ' Method
    method = Cells(rowIndex, 7).Value

    sFile.WriteLine (String(8, " ") & "<Api url=""" & URL & """ path=""" & Path & """ method=""" & method & """ >")

    sFile.WriteLine (String(12, " ") & "<Input>")

    ' 入力定義
    inputText = Cells(rowIndex, 18).Value

    sFile.WriteLine (inputText)

    sFile.WriteLine (String(12, " ") & "</Input>")

    sFile.WriteLine (String(8, " ") & "</Api>")

    sFile.WriteLine (String(8, " ") & "<Response>")

    ' 出力応答文種別
    outputStatus = Cells(rowIndex, 19).Value

    sFile.WriteLine (outputStatus)

    sFile.WriteLine (String(8, " ") & "</Response>")

    sFile.WriteLine (String(4, " ") & "</Task>")

    sFile.WriteLine

    rowIndex = rowIndex + 1

    Loop


    sFile.WriteLine ("</Tasks>")
    sFile.Close
    Set sFile = Nothing
    Set fso = Nothing
    End Sub


    Sub DeleteFile()

    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.DeleteFile ("D:/TestFile.txt")
    End Sub

  • 相关阅读:
    spring -项目功能介绍
    【HQL】分页查询 、对象导航查询、外置命名查询、连接查询、查询过滤器、统计查询
    【HQL】属性查询、条件查询
    【HQL】hibernate查询语言hql
    Hibernate- 表联系
    struts 配置过程 -一个计算器程序
    【DRP】-JSTL核心库 c:out标签
    .NET 使用sock5做代理(不是搭建服务端)
    重磅新闻!昨日阿里云发布首款云电脑“无影”,到底如何呢?
    C#如何实现获取电脑硬件相关的配置信息呢?
  • 原文地址:https://www.cnblogs.com/xuemanjiangnan/p/8378744.html
Copyright © 2011-2022 走看看