I have WCF Service
that returns data as DataTable
type. I want to insert this data into Excel workbook in the Workbook_Startup
event.
What is the best way to do it?
(VS .NET 3.5 Excel 2010 Workbook Project)
WCF Service code:
public DataTable GetQuarterTargetAchievement()
{
var dt = new DataTable("TargetAchievement");
using (var conn = new SqlConnection(GetConnectionString()))
{
using (var da = new SqlDataAdapter("SELECT fld1, fld2, ... , fldN FROM dbo.ReportTable; ", conn))
{
da.Fill(dt);
}
}
return dt;
}
Client code:
var dt = proxy.GetQuarterTargetAchievement();
Final solution:
Try this example this should be enough to get you started in your using section at the top add this
you may also have to add the Reference at the Project level as well make sure you order the list when you select Reference--> add--> and select the correct version of Microsoft Office Interop assembly based on the installed version you have
probably ver 12 or 14 I am guessing..
There is a open soure library called EPPlus, I found one tutorial on that. It could be helpful for you.
DataTable to Excel
Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))