如何将WPF DataGridTextColumn文本限制为最大长度为10个字符.
我不想使用DatagridTemplateColumn,因为它有内存泄漏问题.
该字段也绑定到数据实体模型.
使用带有日文字符双引号字段的流阅读器读取csv文件.它不读日文字符并将其视为unicode字符.我尝试了不同的编码类型,但它不适合我.请与我分享一些想法或解决此问题的其他解决方案.或者有更好的方法来做到这一点.
public DataTable ReadDataFromCSV(string path, char delim)
{
string fulltext;
string[] arrColumnNames;
string[] arrColumnValues;
string[] arrRows;
int i, j, n;
System.Data.DataTable dt = new System.Data.DataTable();
DataRow row;
if (delim.ToString().Length < 1)
{
delim = ',';
}
try
{
//' check that the file exists before opening it
if (File.Exists(path))
{
using (TextReader sr = new StreamReader(path,Encoding.UTF8))
{
fulltext = sr.ReadToEnd();
arrRows = fulltext.Split('\n');
arrColumnNames = arrRows[0].Replace('"', ' ').Trim().Split(delim);
//'add columns to a datatable
for (n = 0; n < arrColumnNames.Length …Run Code Online (Sandbox Code Playgroud) 当对某些 Excel 文件使用 excelDatareader 时,ExcelReaderFactory.CreateOpenXmlReader(stream)返回 null 并且不获取文件流。但对于某些 Excel 文件来说,它运行完美。
有人能给我解释一下原因吗?
static void Main(string[] args)
{
FileStream stream = File.Open(@"C:\Users\nichi-user\Desktop\BLRJCCI.xls", FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();
result.Tables[0].TableName.ToString();
}
Run Code Online (Sandbox Code Playgroud)
