我正在尝试读取其中包含多行单元格的 CSV 文件。
这是 CSV 的样子:
第 1 行,“详细信息”列有多行。
当我尝试使用ReadLine()
方法阅读它时:
private void buttonBrowse_Click(object sender, EventArgs e)
{
openFileDialog.Filter = "Excel Worksheets|*.csv";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
String filePathAndName = openFileDialog.FileName;
StreamReader reader = new StreamReader(filePathAndName);
String line = reader.ReadLine();
Console.WriteLine(line);
do
{
line = reader.ReadLine();
Console.WriteLine(line);
} while (line != null);
}
}
Run Code Online (Sandbox Code Playgroud)
它将具有多行的单元格拆分为行数:
[1]"Time of Day","Process Name","PID","Operation","Path","Result","Detail","Image Path"
[2]"22:52:24.2905182","notepad.exe","4828","Process Start","","SUCCESS","Parent PID: 2484, Command line: ""C:\Windows\system32\notepad.exe"" , Current directory: C:\Users\User\, Environment:
[3]; =::=::\
[4]; ALLUSERSPROFILE=C:\ProgramData
[5]; APPDATA=C:\Users\User\AppData\Roaming
[6]; asl.log=Destination=file
[7]; CommonProgramFiles=C:\Program Files\Common Files
...
"22:52:24.2905201","notepad.exe","4828","Thread Create","","SUCCESS","Thread ID: 8008","C:\Windows\system32\notepad.exe"
"22:52:24.2915842","notepad.exe","4828","Load Image","C:\Windows\System32\notepad.exe","SUCCESS","Image Base: 0x6f0000, Image Size: 0x30000","C:\Windows\system32\notepad.exe"
Run Code Online (Sandbox Code Playgroud)
在上面的日志中,第 2-7 行应该是一行。
我想阅读它,就像 powershell 在这里使用import-csv
函数做得很好一样:
您可以使用以下命令(示例)轻松地按行和列从特定单元格中提取数据:
$csvContent[0] |select -expand Detail
Run Code Online (Sandbox Code Playgroud)
例子:
归档时间: |
|
查看次数: |
5754 次 |
最近记录: |