
Convert DataTable XML to CSV Using XSL
Well, the exciting news is....there is no exciting news.
I'd beeter explain and help otherwise you're going to get ticked.
Okay, XML>>XLS is a means by which you reform your XML into HTML.. At least,
that's the normal bent.
So if you're looking for some Hail Marys, you may want to move to the Out
Fathers.
Yet a table by any other name is a table, right?
Here's the code:
Dim ds As New DataTable()
Dim r As DataRow
Dim x As Integer
Dim y As Integer
Dim csv As String
Dim FSO As Object
Dim txtStream As Object
FSO = CreateObject("Scripting.FileSystemObject")
txtStream = FSO.OpenTextFile("C:\temp.csv", 2, True, -2)
dt = Datagrid1.Datasource
r = dt.Tables(0).Rows(0)
For x = 0 To dt.Tables(0).Columns.Count - 2
csv = csv & dt.Tables(0).Columns(x).Caption & ","
Next
csv = csv & dt.Tables(0).Columns(x).Caption
txtStream.Writeline(csv)
csv = ""
For x = 0 To dt.Tables(0).Rows.Count - 1
r = dt.Tables(0).Rows(x)
For y = 0 To dt.Tables(0).Columns.Count - 2
If (r(y)) Is Nothing = True Then
csv = csv & ","
Else
csv = csv & r(y) & ","
End If
Next
If (r(y)) Is Nothing = True Then
csv = csv & ","
Else
csv = csv & r(y)
End If
txtStream.WriteLine(csv)
csv = ""
Next
txtStream.close()
txtStream = Nothing
FSO = Nothing
Thus are the words of todays holly grail.
Sincerely hope this helps. If it doesn't, I get down on my hands and knees
and beg for mercy.
Quote:
> 'Course I do but what's that got to do with it ;-)
> Seriously though, I get paid to do as I'm told, and I've been told certain
> clients want access to the underlying data in CSV format, I don't wanna do
> it but ......
> I could interate the DT and write out the details, but I've after
something
> more exciting!
> Mark
> : Yeah, why?
> :
> : XML to CSX via XLS
> :
> : Do you like hurting yourself?
> :
> : > Being totally new to the whole XSL thing, anyone have any code
snippets
> or
> : > ideas on how I might approach this?
> : >
> : > Thanks!
> : >
> : > Mark
> : >
> : >
> :
> :