Sometimes we may require to generate Excel file from our reports,read from excel files to import data etc. This can be achieved using Office Interop (Office Automation) assemblies, but Office Automation in Web servers,got some issues;(More details: http://support.microsoft.com/kb/257757). The alternative is using OleDb provider. You may need to add one more attribute to connection string to connect to the Excel file. And connection string will be
stringconnectionString = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=C:/Sample.xls; Extended Properties=Excel 8.0;"
Please note the “Extended Properties” attribute. This attribute helps us to query the excel file.
Exporting Data from Data Table to Excel File.
stringconnectionString = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=C:/Sample.xls; Extended Properties=Excel 8.0;"
<br /><br />1.实现原理引用原文【Import / export data in MS Excel using C#】<br />Sometimes we may require to generate Excel file from our reports,read from excel files to import data etc. This can be achieved using Office Interop (Office Automation) assemblies, but