如何输出excel文件的每一行读取单个文件?

我怎样才能输出一个文件的Excel数据的每一行? 现在它输出正确数量的文件,但增加了数据行,所以文件1是正确的,文件2具有行1和行2等

Dim smNum As Integer = 0 If rowct > 0 Then For rr As Integer = 10 To rowct For cc As Integer = 1 To colct val = CType(r.Cells(rr, cc), Excel.Range).Value If val = "" Then Exit For str.Append(ht((cc - 1).ToString)).Append(",") str.Append(val) 'assigning the sample managaer num in column 1 If cc = 1 Then smNum = val file_name = selectedFile.Substring(13, 16) & "_" & smNum & "_" & todays_date & file_count & ".csv" full_path = save_file_path & file_name MessageBox.Show("Sample Manager Number: " & val & full_path) End If If cc < colct Then str.Append(",") End If My.Computer.FileSystem.WriteAllText(full_path, str.ToString, False) lstFileOut.Items.Add(file_name) Next 'str.AppendLine() Next End If 

在每一行之前使用StringBuilder.Clear 。

  For rr As Integer = 10 To rowct str.Clear() For cc As Integer = 1 To colct 

我还build议每行一次调用My.Computer.FileSystem.WriteAllText,因为您正在写入每个列上的文件。