我的问题是关于sql server bcp实用程序:
如何使用bcp工具将数据从sql server导出到扩展名为xls、xlsx和xlsb的excel工作表中,因为我可以导出为.csv文件和.txt文件扩展名,但用excel在使用bcp导出后无法打开。
任何工人周围的出口到excel工作表将有很大帮助。
提前感谢您的帮助
发布于 2016-02-04 17:16:16
首先,BCP不支持xls或xlsx格式。BCP仅支持xml、txt、csv;
如果你必须从excel中导入数据,你可以使用.net或java或PHP语言来创建具有相同excel的数据表。然后使用该datatable在Sql中创建相应的表
如果您正在使用sql和C#,那么这可能会对您有所帮助。
string con =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\temp\test.xls;" +
@"Extended Properties='Excel 8.0;HDR=Yes;'";
using(OleDbConnection connection = new OleDbConnection(con))
{
connection.Open();
OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);
using(OleDbDataReader dr = command.ExecuteReader())
{
while(dr.Read())
{
var row1Col0 = dr[0];
Console.WriteLine(row1Col0);
}
}
}或
private void GetExcel()
{
string fullPathToExcel = "<Path to Excel file>"; //ie C:\Temp\YourExcel.xls
string connString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=yes'", fullPathToExcel);
DataTable dt = Function_Library.DatabaseFunctions.GetDataTable("SELECT * from [SheetName$]", connString);
}https://stackoverflow.com/questions/35196106
复制相似问题