DataSet到文本文件 [英] DataSet to Text File

查看:87
本文介绍了DataSet到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种方法可以将一个数组写入excel电子表格,但是在一个巨大的
时间关键运行中它失败了,因为可怕的HRESULT:0x800A03EC错误。当我对数据进行采样但是当它全部试图进入时,
工作得很好。

它被轰炸了。


所以我需要把它写成一个制表符分隔的文件,我确定希望有人今晚醒来。


如何编写我的数据集来制作一个标签分隔的文本文件?

Well I had a way to write an array to an excel spreadsheet but on a huge
time critical run it failed iwth the dreaded HRESULT: 0x800A03EC error. It
worked fine when i sampled the data to go in but when it all tried to go in
it bombed.

So I need to write this to a tab delimited file and I sure hope somebody is
awake tonight.

How do I write my dataset to make a tab delimted text file?


推荐答案

你可以详细说明一下,以便我可以帮助你在excel的东西.. 。

如果你想坚持使用制表符分隔文件,那么你可能需要使用

字符串。获取每个datacell并添加选项卡。重复每个数据集并且不要

忘记在每行之后添加换行符...


" scorpion53061" <它的世界尽头我们知道 it@here.com >写在

消息新闻:OR **************** @ TK2MSFTNGP09.phx.gbl ...
can u elaborate a bit more so that i may help u in excel stuff...
if u want to stick to tab delimited file then u may need to play with
strings. take every datacell and add tab. repeat for each dataset and dont
forget to add a newline after each row...

"scorpion53061" <Its the end of the world as we know it@here.com> wrote in
message news:OR****************@TK2MSFTNGP09.phx.gbl...
我有一种将数组写入excel电子表格的方法,但是在时间紧迫的大运行中它失败了,因为可怕的HRESULT:0x800A03EC错误。
当我对数据进行采样时它工作得很好但是当它全部试图在其中轰炸
时。

所以我需要将它写入制表符分隔文件并且我肯定希望有人
今晚醒来。

如何编写我的数据集来制作制表符分隔的文本文件?
Well I had a way to write an array to an excel spreadsheet but on a huge
time critical run it failed iwth the dreaded HRESULT: 0x800A03EC error. It worked fine when i sampled the data to go in but when it all tried to go in it bombed.

So I need to write this to a tab delimited file and I sure hope somebody is awake tonight.

How do I write my dataset to make a tab delimted text file?



这是我的代码在我需要它时失败了...

http://www.kjmsolutions.com/datasetarray.htm


我现在需要快点,因为我没有时间做它工作。
This is my code that failed me when I needed it...

http://www.kjmsolutions.com/datasetarray.htm

I need something quick now because I dont have time to make it work.


scorpion53061

这是一个非常通用的快速VB.NET 1.1导出例程(太多了

general?):


它基于DataSet,但你应该可以将它采用到

DataReader。


''所需进口

为StreamWriter导入System.IO''

为UnicodeEncoding导入System.Text''

''样本用法

导出(" Customers.csv",DataSet1.Tables( 客户))

导出(" Employees.csv",DataSet1.Tables(" Employees"))

Public Sub Export(ByVal path As String, ByVal table As DataTable)

Dim output As New StreamWriter(path,False,UnicodeEncoding.Default)

Dim delim As String


''写出标题行

delim =""

For each col As DataColumn in table.Columns

output.Write (delim)

output.Write(col.ColumnName)

delim =","

Next

output.WriteLine()


''写出每个数据行

For Each row As DataRow In table.Rows

delim =""

For Each value As Object In row.ItemArray

output.Write(delim)

如果TypeOf值是String然后

output.Write("""" c)''有四个双引号和ac

output.Write(value)


output.Write(""" c)''有四个双引号和ac

Else

output.Write(value)

结束如果

delim =","

Next

output.WriteLine()

下一页


输出。关闭()


结束子


你可以改变(或删除)上面的编码参数以满足您的需要,

我使用Unicode,因为表中包含非ASCII字符。另外当写b / b
时,我不会处理字符串中的双引号。如果你使用StreamWriter作为参数,它会更加灵活(你可以去内存流来支持剪切和粘贴)。我使用

数字类型的默认格式。


您可以通过

更改以下行:


''Public Sub Export(ByVal path As String,ByVal table As DataTable)

Public Sub Export( ByVal path As String,ByVal view as DataView)


''For each col As DataColumn in table.Columns

For each col As DataColumn in view.Table .Columns


''For Each row As DataRow In table.Rows

For Each row As DataRowView在视图中


''For Each value As Object in row.ItemArray

For Each value As Object In row.Row.ItemArray


而不是设置delim变量到,对于逗号分隔,你可以将

设置为ControlChars.Tab以用于制表符分隔。


希望这有助于

Jay


" scorpion53061" <它的世界尽头我们知道 it@here.com >写在

消息新闻:OR **************** @ TK2MSFTNGP09.phx.gbl ...
scorpion53061
Here''s a quick VB.NET 1.1 export routine that is very general (too
general?):

Its based on a DataSet, however you should be able to adopt it to a
DataReader instead.

'' Required imports
Imports System.IO '' for the StreamWriter
Imports System.Text '' for the UnicodeEncoding

'' sample usage
Export("Customers.csv", DataSet1.Tables("Customers"))
Export("Employees.csv", DataSet1.Tables("Employees"))
Public Sub Export(ByVal path As String, ByVal table As DataTable)
Dim output As New StreamWriter(path, False, UnicodeEncoding.Default)
Dim delim As String

'' Write out the header row
delim = ""
For Each col As DataColumn In table.Columns
output.Write(delim)
output.Write(col.ColumnName)
delim = ","
Next
output.WriteLine()

'' write out each data row
For Each row As DataRow In table.Rows
delim = ""
For Each value As Object In row.ItemArray
output.Write(delim)
If TypeOf value Is String Then
output.Write(""""c) '' thats four double quotes and a c
output.Write(value)

output.Write(""""c) '' thats four double quotes and a c
Else
output.Write(value)
End If
delim = ","
Next
output.WriteLine()
Next

output.Close()

End Sub

You can change (or remove) the Encoding parameter above to suit your needs,
I used Unicode as the table had non ASCII characters in it. Also when
writing strings, I don''t deal with double quotes in the string. If you make
the StreamWriter a parameter it will be much more flexible (you could go to
a memory stream to support cut & paste). I use the default formatting for
numeric types.

You can change it to use a DataView (for sorting & filtering for example) by
changing the following lines:

''Public Sub Export(ByVal path As String, ByVal table As DataTable)
Public Sub Export(ByVal path As String, ByVal view As DataView)

''For Each col As DataColumn In table.Columns
For Each col As DataColumn In view.Table.Columns

''For Each row As DataRow In table.Rows
For Each row As DataRowView In view

''For Each value As Object In row.ItemArray
For Each value As Object In row.Row.ItemArray

Instead of setting the delim variable to "," for comma delimited, you can
set it to ControlChars.Tab for tab delimited.

Hope this helps
Jay

"scorpion53061" <Its the end of the world as we know it@here.com> wrote in
message news:OR****************@TK2MSFTNGP09.phx.gbl...
我有一种将数组写入excel电子表格的方法,但是在时间紧迫的大运行中它失败了,因为可怕的HRESULT:0x800A03EC错误。它在我对数据进行采样时工作得很好但是当它全部试图在其中轰炸
时。

所以我需要将它写入制表符分隔文件并且我肯定希望有人
今晚醒来。

如何编写我的数据集来制作制表符分隔的文本文件?
Well I had a way to write an array to an excel spreadsheet but on a huge
time critical run it failed iwth the dreaded HRESULT: 0x800A03EC error. It
worked fine when i sampled the data to go in but when it all tried to go in it bombed.

So I need to write this to a tab delimited file and I sure hope somebody is awake tonight.

How do I write my dataset to make a tab delimted text file?



这篇关于DataSet到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆