[英]How can I create schema.ini file? I need to export my .csv file to datagridview
I want to export a CSV file to a datagridview. 我想将CSV文件导出到datagridview。 I need to create the file
schema.ini
. 我需要创建文件
schema.ini
。 But I don't know, how can I create it? 但我不知道,我怎么能创造它呢?
There is my code: 有我的代码:
public DataTable exceldenAl(string excelFile)
{
try
{
string fileName = Path.GetFileName(excelFile);
string pathOnly = Path.GetDirectoryName(excelFile);
string cmd = "Select * From [" + fileName + "$]";
string cnstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathOnly + "\\;Extended Properties=\"Text;HDR=Yes;FORMAT=Delimited\"";
OleDbConnection ocn = new OleDbConnection(cnstr);
ocn.Open();
OleDbCommand command = new OleDbCommand(cmd,ocn);
OleDbDataAdapter adap = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
dt.Locale = CultureInfo.CurrentCulture;
adap.Fill(dt);
return dt;
}
finally {
}
}
private void btnExcelReader_Click(object sender, EventArgs e)
{
string dosya;
string cevap;
openFileDialog1.ShowDialog();
dosya = openFileDialog1.FileName.ToString();
ClsExcelReader er = new ClsExcelReader();
cevap = er.exceldenAl(dosya).ToString();
dataGridView1.DataSource = cevap;
//listViewExcelOku.DataBindings =
}
}
Open up notepad and create a file similar to this: 打开记事本并创建一个类似于此的文件:
[YourCSVFileName.csv]
ColNameHeader=True
Format=CSVDelimited
DateTimeFormat=dd-MMM-yyyy
Col1=A DateTime
Col2=B Text Width 100
Col3=C Text Width 100
Col4=D Long
Col5=E Double
Modify the above file to fit your specific data schema. 修改上述文件以适合您的特定数据模式。 Save it as SCHEMA.ini in the same directory where your *.CSV file is located.
将其作为SCHEMA.ini保存在* .CSV文件所在的同一目录中。
Read this link ( Importing CSV File Into Database ), it is a good example to get you up and understanding how the Schema.ini works 阅读此链接( 将CSV文件导入数据库 ),这是一个很好的例子,让您了解Schema.ini的工作原理
I wrote these Excel formulas to generate the content of this file if you can get hold of the Excel sheet with column headers. 如果您可以获取带有列标题的Excel工作表,我编写了这些Excel公式来生成此文件的内容。 It's pretty basic.
这很基础。 Add and remove features as desired.
根据需要添加和删除功能。 It assumes all text with delimiters.
它假设所有文本都带有分隔符。 Then insert the following formula (including all your options) in A2:
然后在A2中插入以下公式(包括所有选项):
="[no headers.csv]
"&"ColNameHeader=false
"&"MaxScanRows=0
"&"Format=Delimited(;)
Col"&COLUMN()&"="&A1&" text
"
And the following formula in B2. B2中的以下公式。
=A2&"Col"&COLUMN()&"="&B1&" text
"
Then drag to the right to get your basic schema.ini (rightmost cell). 然后向右拖动以获取基本schema.ini(最右边的单元格)。 You can adjust options in the excel cell below the column name.
您可以调整列名称下方的Excel单元格中的选项。 Each column has it's own definition.
每列都有自己的定义。 I got closing and opening quotes in the result when copied to text file.
复制到文本文件时,我在结果中关闭并打开引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.