我编写了一个程序,可以创建三个独立的csv文件。一个直接在Excel中打开,另外两个需要导入文本文件 方法和步骤相同(写入CSV的数据除外。)
作品
Dim fso, MyFile 'tests writing from different Lists
fso = CreateObject("scripting.filesystemobject")
MyFile = fso.createtextfile(OutPutfilePath, True)
MyFile.WriteLine("Entry Key Number,Item Number,Part Number,Description,Part Sheet,Parent Level")
For Each ENTRY_ As LDF_Test_1.ENTRY_ARRAY In ENTRY_ENTRY
MyFile.writeline(ENTRY_.ENTRY_KEY & "," & ENTRY_.Entry_ItemNo & "," & ENTRY_.Entry_PartNo & ",""" & ENTRY_.Entry_Descrip & """," & ENTRY_.Entry_LIST_FileName & "," & ENTRY_.Entry_ParentNo)
Next
MyFile.close()
不能工作
Dim fso, MyFile 'tests writing from different Lists
fso = CreateObject("scripting.filesystemobject")
MyFile = fso.createtextfile(OutPutfilePath, True)
MyFile.WriteLine("LDF File Name,LDF Ref,LDF Description,Folder Name,Pic File Name,Picture Title ,Destination Folder,Serial Number,Converted,end")
For Each Pix_ As LDF_Test_1.PIX_ARRAY In PIX_PIX
MyFile.writeline(Pix_.Pix_List_FileName & ",""" & Pix_.Pix_List_Ref & """,""" & Pix_.Pix_List_Descrip & """,""" & path_ & """,""" & Pix_.Pix_FileName & """,""" & Pix_.Pix_Title & """,""" & OutPutfilePath & """,""" & Serial_Num)
Next
MyFile.close()
MsgBox("File Created")
任何想法或想法?
答案 0 :(得分:0)
嵌入式行情是一种痛苦,可能是“不起作用”的根源。 NET提供了一个很好的替代尝试:
MyFile.writeline(String.Format("{0}, {1}, {2}, ...etc",
Pix_.Pix_List_FileName, Pix_.Pix_List_Ref,
Pix_.Pix_List_Descrip, Pix_.Pix_FileName,
etc)
确保您拥有与数据元素相同数量的持有者。
注意:代码看起来更像VBA而不是VB.NET,但这就是你如何标记它。
答案 1 :(得分:0)
尝试使用System.IO
命名空间中的StreamWriter对象:
Using myFile As New IO.StreamWriter(OutPutfilePath)
myFile.WriteLine("LDF File Name,LDF Ref,
LDF Description,Folder Name,
Pic File Name,Picture Title ,Destination Folder,
Serial Number,Converted,end")
For Each ENTRY_ As LDF_Test_1.ENTRY_ARRAY In ENTRY_ENTRY
myFile.WriteLine(String.Format("{0},{1},{2},{3},{4},{5}",
ENTRY_.ENTRY_KEY,ENTRY_.Entry_ItemNo,
ENTRY_.Entry_PartNo, ENTRY_.Entry_Descrip,
ENTRY_.Entry_LIST_FileName, ENTRY_.Entry_ParentNo)
Next
End Using