Click here to Skip to main content
15,922,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have data with specified range from excel file(sales.xlsx) by using Excel service in sharepoint 2010.I have to convert this excel service data to datatable without looping in c#.
please refer http://stackoverflow.com/questions/18888870/how-to-convert-excel-service-data-with-ranges-to-datatable-from-share-point-2010"
How do I do this?
Posted

Your can use ACE provider in a procedure, and call the procedure :

How to export data from SQL to excel along with headers and table attributes[^]
http://www.excel-sql-server.com/excel-import-to-sql-server-using-distributed-queries.htm[^]

please be noted
select * into newtable from lasttable

is a good way for what you want.
 
Share this answer
 
Comments
Member 10112611 20-Sep-13 7:40am    
I did the same in asp.net and c#..I can give the code if can help u..
Member 10112611 20-Sep-13 7:42am    
go thru the below code..
private DataTable CopyExceltoDatatable(string path, string filename)
    {
        string sheetname="";
        DataTable dtexcel = new DataTable();
        string excelConnString = "Provider=Microsoft.ACE.OLEDB.12.0;OLE DB Services=-4;Data Source=" + path +"\\"+filename + ";Excel 12.0;HDR=Yes;IMEX=1";
        using (OleDbConnection excelConnection = new OleDbConnection(excelConnString))
        {
            excelConnection.Open();
            //Create OleDbCommand to fetch data from Excel 
             DataTable Sheets = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
             DataRow schemaRow = Sheets.Rows[0];
             sheetname = schemaRow["TABLE_NAME"].ToString();
                if (!sheetname.EndsWith("_"))
                {
                    string query = "SELECT  * FROM [" + sheetname + "]";
                    OleDbDataAdapter daexcel = new OleDbDataAdapter(query, excelConnection);
                    daexcel.Fill(dtexcel);
                }
                return dtexcel;
        }
    }
 
Share this answer
 
Comments
Member 10112611 20-Sep-13 8:01am    
this copies only data assuming that first line is Header (because HDR=YES given)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900