以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 将数据表导出为txt文本 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=170014) |
-- 作者:cnsjroom -- 发布时间:2021/7/9 11:41:00 -- 将数据表导出为txt文本 将数据表导出为txt文本 狐表代码: Dim cmd As new S QLCommand cmd.Connectio nName = "kj222" cmd.Comma ndText = "LINK" cmd.StoredPr ocedure = True \'表示CommandText内容不是标准的SQL语句,而是存储过程名 cmd.Parameters.Add("@MKCODE ","10010") cmd.Parameters.Add("@ADDRESS ","D:\\persionLoaction\\Data") cmd.Parameters.Add("@flag ","1") Dim dt As DataTable = cmd.ExecuteReader 怎么没有将指定的文件保存到指定的目录下呢? 存储过程语句: [此贴子已经被作者于2021/7/9 11:42:28编辑过]
|
-- 作者:有点蓝 -- 发布时间:2021/7/9 12:05:00 -- 表格导出txt参考 Dim s As String For Each dc As DataCol In DataTables("表A").DataCols s = s & vbtab & dc.Name Next s = s.TrimStart(vbtab) FileSys.WriteAllText("D:\\问题\\表A.txt",s & vbcrlf,False) For Each dr As DataRow In DataTables("表A").DataRows s = "" For Each dc As DataCol In DataTables("表A").DataCols If s > "" Then s = s & vbtab If dr.IsNull(dc.Name) = False Then s = s & dr(dc.Name) End If Next FileSys.WriteAllText("D:\\问题\\表A.txt",s & vbcrlf ,True) Next |
-- 作者:cnsjroom -- 发布时间:2021/7/9 14:51:00 -- 回复:(有点蓝)表格导出txt参考Dim s As StringFor ... 再麻烦老师一下 如果只导出指定的第一列 第二列 第三列的值怎么操作呢? |
-- 作者:有点蓝 -- 发布时间:2021/7/9 14:54:00 -- Dim Cols1() As String = {"来源列一","来源列二","来源列三"} For Each dc As DataCol In DataTables("表A").DataCols 改为遍历上面数组
|
-- 作者:cnsjroom -- 发布时间:2021/7/9 15:15:00 -- 回复:(有点蓝)Dim Cols1() As String&nb... 当前代码如下: 生成的效果不大理想 麻烦老师继续指导下 谢谢! Dim Cols1() As String = {"vc_Code","vc_Name","AreaID"} Dim s As String s=Date.now() & vbcrlf For i As Integer = 0 To Cols1.Length -1 s = s & vbtab s = s & Cols1(i) Next s = s.TrimStart(vbtab) FileSys.WriteAllText("D:\\问题\\表A.txt",s & vbcrlf,False) For Each dr As DataRow In DataTables("m_Localizer").DataRows s = "" For i As Integer = 0 To Cols1.Length -1 If s > "" Then s = s & vbtab If dr.IsNull(Cols1(i)) = False Then s = s & dr(Cols1(i)) & "," End If Next s = s.TrimStart(vbtab) FileSys.WriteAllText("D:\\问题\\表A.txt", s & vbcrlf , True, Encoding.Default) Next 生成文本如下: 效果不理想: 想实现如下效果: |
-- 作者:有点蓝 -- 发布时间:2021/7/9 15:25:00 -- 去掉逗号,不要画蛇添足。 如果要使用逗号分隔,把代码里的vbtab改为逗号
|