读取Excel文件并将数据导入sql [英] Read Excel file and import data to sql
本文介绍了读取Excel文件并将数据导入sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我添加了一个用于导入Excel文件的openfile对话框。我需要验证输入文件,例如它是否已指定列和至少一行数据。
是否可以在将文件保存到服务器之前进行验证?
如何读取excel文件的内容并导出到datatable或dataset。
Hi
I had added a openfile dialog for Importing Excel Files. I need to validate the input file like whether it has specified columns and atleast one row of data.
Is it possible to validate before saving the file to server ?
How to read the contents of excel file and export to datatable or dataset.
private void ImportButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = false;
openFileDialog.Filter = "Excel Files(*.xlsx)|*.xlsx";
if (openFileDialog.ShowDialog() == true)
{
this.FileTextBox.Text = openFileDialog.File.Name;
this.FileTextBox.IsReadOnly = true;
FileStream myStream = openFileDialog.File.OpenRead();
}
}
推荐答案
请参阅此示例代码项目
文章:使用C#使用Excel [ ^ ]。
正如 Maciej 已经提出的那样,您也可以使用ADO.NET
来达到同样的目的(例如,参见此页面 从C#读取Excel [ ^ ])。
See, for instance thisCode Project
article: "Working with Excel Using C#"[^].
As already proposed by Maciej, you could alternatively useADO.NET
for the same purpose (see, for instance this page "Reading Excel From C#"[^]).
这篇关于读取Excel文件并将数据导入sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文