简体   繁体   English

使用VBA Excel Macro读取XML并自定义生成的表

[英]Read XML using VBA Excel Macro and customize the generated table

I am new to Excel VBA. 我是Excel VBA的新手。 My problem is that I have an XML file and I need to show its contents in a tabular format in Excel. 我的问题是我有一个XML文件,需要在Excel中以表格格式显示其内容。

I have written a sample VBA code as follows: 我编写了一个示例VBA代码,如下所示:

Dim testFile As Workbook

Set testFile = Workbooks.OpenXML(
Filename:="D:\sample.xml",LoadOption:=XlXmlLoadOption.xlXmlLoadImportToList)

It generates the contents in a tabular format in Excel, but there are a lot of empty cells and some garbage data (data relevant in XML but not needed here). 它在Excel中以表格格式生成内容,但是有很多空单元格和一些垃圾数据(XML中相关的数据,但此处不需要)。 I need to delete the empty cells (both in rows and columns) and also remove some unwanted columns. 我需要删除空单元格(行和列),还删除一些不需要的列。

Can someone please suggest some approach on how to proceed in this? 有人可以建议一些方法进行此操作吗?

Depending on how comfortable with VBA you are, you could parse the file yourself. 根据您对VBA的满意程度,可以自己解析文件。 A reference to "Microsoft XML" ( msxml#.dll ) and a look at this question should be all you need to get you on your way! 对“ Microsoft XML”( msxml#.dll )的引用和对此问题的了解应该是您所需要的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM