我正在尝试编写一个将csv转换为xml的程序。 我的xml在放入数据之前将csv中的第一行保存为标签.i将粘贴我的代码和输出以更好地理解。这是我的代码。
Imports System.IO
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Module Module1
Sub Main()
Dim source As String() = File.ReadAllLines("c:\Data\csvtoxmlTEST.CSV")
Dim firstRow As Boolean = True
Dim cust As XElement =
<events>
<%= From strs In source
Let fields = Split(strs, ",")
Select
<event EventIdentity=<%= fields(0) %>>
<name><%= fields(1) %></name>
<summary><%= fields(2) %></summary>
<description><%= fields(3) %></description>
<local-start-date-time><%= fields(4) %></local-start-date-time>
<local-end-date-time><%= fields(5) %></local-end-date-time>
<status><%= fields(11) %></status>
<locations>
<location>
<name><%= fields(6) %></name>
<location>
<name><%= fields(7) %></name>
<location>
<name><%= fields(8) %></name>
</location>
</location>
</location>
</locations>
<categories>
<category>
<name><%= fields(9) %></name>
</category>
</categories>
<custom-data><%= fields(10) %></custom-data>
</event>
%>
</events>
cust.Save("c:\Data\csvtoxmlTEST.xml")
End Sub
End Module
我的输出显示以下内容:
<?xml version="1.0" encoding="utf-8"?>
<events>
<event EventIdentity="EventIdentity">
<name>EventName</name>
<summary>EventSummary</summary>
<description>EventDescription</description>
<local-start-date-time>EventStart</local-start-date-time>
<local-end-date-time>EventEnd</local-end-date-time>
<status>status</status>
<locations>
<location>
<name>Location1_Name</name>
<location>
<name>Location2_Building</name>
<location>
<name>Location3_Room</name>
</location>
</location>
</location>
</locations>
<categories>
<category>
<name>Category</name>
</category>
</categories>
<custom-data>Department</custom-data>
</event>
<event EventIdentity="17057">
<name>ACCT</name>
<summary> Financial Acct</summary>
<description>ACCT 23071 Financial Acct</description>
<local-start-date-time>1/28/2019 10:00AM</local-start-date-time>
<local-end-date-time>1/28/2019 10:50AM</local-end-date-time>
<status>A</status>
<locations>
<location>
<name>TestClass</name>
<location>
<name>West</name>
<location>
<name>room - 24</name>
</location>
</location>
</location>
</locations>
<categories>
<category>
<name>Academic Course</name>
</category>
</categories>
<custom-data>School of Business Administration</custom-data>
</event>
</events>
我希望它保存我的xml并以<event EventIdentity="17057">
而不是<event EventIdentity="EventIdentity">
开头。
最后这是程序读取的我的测试csv文件: EventIdentity,EventName,EventSummary,EventDescription,EventStart,EventEnd,Location1_Name,Location2_Building,Location3_Room,类别,部门,状态 17057,ACCT,Financial Acct,ACCT 23071 Financial Acct,1/28/2019 10:00 AM,1/28/2019 10:50 AM,TestClass,West,room-24,Academic Course,工商管理学院,A
答案 0 :(得分:1)
您要library(zoo)
z <- read.zoo(e, FUN = as.yearmon, aggregate = function(x) tail(x, 1))
as.ts(z)
第一行。 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2016 1300 NA 1300 NA NA NA 1300 NA 1300 1300
2017 NA 1300 NA NA NA NA 1300 NA NA NA NA NA
2018 NA NA NA 1375 NA 1375 NA NA NA NA NA NA
2019 NA 1405 1405
是一个字符串数组-迭代时只需跳过第一项:
Skip