如何在C#中从数据库表中添加excel表? [英] How to add an excel table from a database table in C#?
问题描述
您好我已创建了一个文件夹。
我想将excel放入此文件夹。如果我在此文件夹中有Class.xlss,我想找到它并将其添加到表中。
如果你在这个文件夹中搜索这个文件夹,我想通过阅读列将它添加到数据库中的相关表中。所以包括了excelde class-branch-quota信息。
excel专栏是:
Class Branch Quata
2 B 20
4 A 30
这个excel 插入Class表。所以
表列是:
Class Branch Quata
2 B 20
4 A
我尝试过:
Hi I've created a folder.
I want to throw excel into this folder.If I have Class.xlss in this folder, I want to find it and add it to the table.
And if you search this folder in this folder, and I want to add it to the relevant table in the database by reading the columns.So excelde class-branch-quota information is included.
excel column is:
Class Branch Quata
2 B 20
4 A 30
this excel insert Class table.So
Table column is:
Class Branch Quata
2 B 20
4 A 30
What I have tried:
namespace InsertTableProject
{
class Program
{
public static void Main(string[] args)
{
// Specify the directory you want to manipulate.
string pathfile = @"C:\MyFolder";
try
{
// Determine whether the directory exists.
if (Directory.Exists(pathfile))
{
Console.WriteLine("That pathfile exists.");
return;
}
// Try to create the directory.
DirectoryInfo di = Directory.CreateDirectory(pathfile);
Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(pathfile));
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
finally { }
}
}
推荐答案
参见使用MS Excel(xls / xlsx)使用MDAC和Oledb [ ^ ]。
这篇关于如何在C#中从数据库表中添加excel表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!