当使用C#生成CSV文件并在Microsoft Excel中打开时,它会显示特殊符号前的字符,例如£
在Notepad ++中,Â的十六进制值为:C2
所以在将£符号写入文件之前,我已尝试过以下内容......
var test = "£200.00";
var replaced = test.Replace("\xC2", " ");
StreamWriter outputFile = File.CreateText("testoutput.csv"); // default UTF-8
outputFile.WriteLine(replaced);
outputFile.Close();
Run Code Online (Sandbox Code Playgroud)
在Excel中打开CSV文件时,我仍然在£符号前面看到"Â"字符(十六进制等效\ xC2\xA3); 它没有任何区别.
我需要使用不同的编码吗?还是我错过了什么?
我正在尝试使用DataTable填充List,我为每个循环检查每一行并将该项添加到列表中.但代码不起作用,我不断收到错误..
System.NullReferenceException:{"对象引用未设置为对象的实例."}
-Data:{System.Collections.ListDictionaryInternal}
-HelpLink:Nothing -Inner Exception:Nothing
-TargetSite:{System.Collections.Generic.List`1 [System.String] getListOfUsers()}
这是我的代码......
Function getListOfUsers() As List(Of String)
'Dim i As Integer = 0
Dim lUserNames As List(Of String) = Nothing
Dim dt As DataTable = getDataTable(db_Config, "SELECT * FROM tblUsers")
If dt.Rows.Count > 0 Then
Try
For Each dRowItem As DataRow In dt.Rows
'i = i + 1
'If IsDBNull(dt.Rows(0)("fldUserName").ToString) = False Then
' lUserNames.Add(dt.Rows(0)("fldUserName").ToString)
'End If
If dRowItem.Item("fldUserName").ToString <> "" Then
lUserNames.Add(dRowItem.Item("fldUserName").ToString)
End If
Next dRowItem
Catch ex As Exception
MsgBox(ex.ToString) …Run Code Online (Sandbox Code Playgroud)