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

原文地址:https://www.cnblogs.com/xuemanjiangnan/p/8378744.html

时间: 2024-10-20 09:06:10

VBA读excel写xml的相关文章

dom4j 简单实例,通过java代码读,写xml文件

项目会用到下面两个jar包 package com.xml.writer; import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileReader;import java.io.InputStreamReader;imp

DOM解析xml实现读、写、增、删、改

qt提供了三种方式解析xml,不过如果想实现对xml文件进行增.删.改等操作,还是DOM方式最方便. 项目配置 pro文件里面添加QT+=xml include <QtXml>,也可以include <QDomDocument> pro文件: [plain] view plain copy print? QT       += core xml QT       -= gui TARGET = xmltest CONFIG   += console CONFIG   -= app_

JAVA读、写EXCEL文件

采用jxl.jar包,网上下载,百度一下到出都是.希望可以帮助到大家. 接下来直接贴代码: <span style="font-size:18px;">public List getValue(String fileName){ String str=ExcelOparations.readExcel(fileName).trim(); String[] str4n= str.split("\n"); List list1 = new ArrayList

02_Android写xml文件和读xml文件

?? 新建Android项目 编写AndroidManifest.xml,使本Android项目具有单元测试功能和写外设的权限. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.itheima28.xmldemo" a

遍历元组写excel,读excel文件

pip install xlrd xlwt 写excel #coding=utf-8 import xlwt workbook = xlwt.Workbook(encoding='utf-8') booksheet = workbook.add_sheet('Sheet 1',cell_overwrite_ok=True) workbook.add_sheet('Sheet 2') DATA = (('学号', '姓名', '年龄', '性别', '成绩'), (1001, 'AAAA', 23

TXLSReadWriteII读和写Excel

unit OpExcell; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, XLSReadWriteII2, QFileCtrls, OleCtrls, DB, ADODB, CellFormats2, XLSFonts2, BIFFRecsII2, Rows2; type TStringArray = array of array of str

【转】python3 对excel读、写、修改的操作

一.对excel的写操作实例: 将一个列表的数据写入excel, 第一行是标题,下面行数具体的数据 1 import xlwt 2 #只能写不能读 3 stus = [['姓名', '年龄', '性别', '分数'], 4 ['mary', 20, '女', 89.9], 5 ['mary', 20, '女', 89.9], 6 ['mary', 20, '女', 89.9], 7 ['mary', 20, '女', 89.9] 8 ] 9 book = xlwt.Workbook()#新建一个

TestLink学习七:TestLink测试用例Excel转换XML工具

最近在整理测试用例,所以想找一个合适的工具来完成对测试需求.测试用例的管理.对比了一翻,发现开源工具中扩展比较好的还属TestLink,而且还可以与JIRA进行对接,这样就引起了我更大的兴趣.加上之前本来就接触过此工具,只是源于各种原因没能深入去研究来着,这次也就是决心于此!于是就找来了Testlink的最新版1.9.3,将其搭建在Ubuntu Server上,很快我们就可以正常方访问了.不过说实话,Testlink界面确实很难看,不过毕竟它不是商业工具,而且可以自己去扩展并定制开发,这就是最大

[Android L]SEAndroid开放设备文件结点权限(读或写)方法(涵盖常用操作:sys/xxx、proc/xxx、SystemProperties)

温馨提示 建议你先了解一下上一篇博文([Android L]SEAndroid增强Androd安全性背景概要及带来的影响)所讲的内容,先对SEAndroid窥个全貌,然后再继续本节内容. 1 现象描述 基于Android L版本源码环境进行开发时,根据项目需求,APP层需要操作sys/xxx 或 proc/xxx下面的文件结点,但是会报出以下权限异常,无法直接操作这些结点 LedLightFileUtil( 4671): java.io.FileNotFoundException: /sys/c