本文介绍了如何使用窗口应用程序将excel文档的数据导入数据库表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 任何人请帮助我如何使用winform将数据从excel文档导入到数据库中的表格中。Any one please help me how i import data from excel document to a table present in data base using winform.????推荐答案 public void parsefunction(string filepath) { Microsoft.Office.Interop.Excel.Application Exlapp; Microsoft.Office.Interop.Excel.Workbook Exlwkbk; Microsoft.Office.Interop.Excel.Worksheet Exlwksht; Microsoft.Office.Interop.Excel.Range ExlRng; Exlapp = new Microsoft.Office.Interop.Excel.ApplicationClass(); //opening Excel file Exlwkbk = Exlapp.Workbooks.Open(@filepath,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing); Exlwksht = (Microsoft.Office.Interop.Excel.Worksheet)Exlwkbk.Sheets.get_Item(1); ExlRng = Exlwksht.UsedRange; ExlRng = Exlwksht.get_Range("A2","L2");//this is starting and ending index in Excel column.. string a3;//declare some variables string b3; string c3; string d3; string e3; string f3; string g3; string h3; string i3; string j3; string k3; a3 = Exlwksht.get_Range("A3",Type.Missing).Value.ToString();//assign Index values to those variables you may also go for both the things(declaring and assigning) together. b3 = Exlwksht.get_Range("B3",Type.Missing).Value.ToString(); c3= Exlwksht.get_Range("C3",Type.Missing).Value.ToString(); d3 = Exlwksht.get_Range("D3",Type.Missing).Value.ToString(); e3 = Exlwksht.get_Range("E3",Type.Missing).Value.ToString(); f3 = Exlwksht.get_Range("F3",Type.Missing).Value.ToString(); g3 = Exlwksht.get_Range("G3",Type.Missing).Value.ToString(); h3 = Exlwksht.get_Range("H3",Type.Missing).Value.ToString(); i3 = Exlwksht.get_Range("I3",Type.Missing).Value.ToString(); j3 = Exlwksht.get_Range("J3",Type.Missing).Value.ToString(); k3 = Exlwksht.get_Range("K3",Type.Missing).Value.ToString(); SqlHelper.ExecuteNonQuery(ConfigurationManager.AppSettings["connstring"], "insertetartdata",a3,b3, c3, d3, e3,f3,g3,h3,i3,j3,k3 //now insert data into sql server using a sprocedure.. //look I am using a different function(which i have not shown here) here for reading the path of Excel file''s location,you may go for a hardcoded location i.e specify the path here itself on the page..Hope this may help you .. 这篇关于如何使用窗口应用程序将excel文档的数据导入数据库表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 11:00