Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:50:19+00:00 2026-05-29T21:50:19+00:00

I have WCF Service that returns data as DataTable type. I want to insert

  • 0

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();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:50:20+00:00Added an answer on May 29, 2026 at 9:50 pm

    Try this example this should be enough to get you started
    in your using section at the top add this

    using Microsoft.Office.Interop.Excel; 
    using System.Runtime.InteropServices;
    

    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..

    private static void Excel_FromDataTable(DataTable dt)
    {
        // Create an Excel object and add workbook...
        Excel.ApplicationClass excel = new Excel.ApplicationClass();
        Excel.Workbook workbook = excel.Application.Workbooks.Add(true); // true for object template???
    
        // Add column headings...
        int iCol = 0;
        foreach (DataColumn c in dt.Columns)
        {
            iCol++;
            excel.Cells[1, iCol] = c.ColumnName;
        }
        // for each row of data...
        int iRow = 0;
        foreach (DataRow r in dt.Rows)
        {
            iRow++;
    
            // add each row's cell data...
            iCol = 0;
            foreach (DataColumn c in dt.Columns)
            {
                iCol++;
                excel.Cells[iRow + 1, iCol] = r[c.ColumnName];
            }
        }
    
        // Global missing reference for objects we are not defining...
        object missing = System.Reflection.Missing.Value;
    
        // If wanting to Save the workbook...
        workbook.SaveAs("MyExcelWorkBook.xls",
        Excel.XlFileFormat.xlXMLSpreadsheet, missing, missing,
        false, false, Excel.XlSaveAsAccessMode.xlNoChange,
        missing, missing, missing, missing, missing);
    
        // If wanting to make Excel visible and activate the worksheet...
        excel.Visible = true;
        Excel.Worksheet worksheet = (Excel.Worksheet)excel.ActiveSheet;
        ((Excel._Worksheet)worksheet).Activate();
    
        // If wanting excel to shutdown...
        ((Excel._Application)excel).Quit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF web service that returns JSON data back to an app
I have a WCF service that returns a lot of data. So much so
I have a WCF service that does some document conversions and returns the document
I have a WCF service that uses ODP.NET to read data from an Oracle
I created a WCF service, that returns some data and also allow to post
Can an Ajax-enabled WCF Service pass back a DataTable as a Sys.Data.DataTable? Like this
I am trying to create a WCF Data Service that returns objects that look
I have created a WCF service which returns IEnumerable<CyberResourceProvisioningAction> . The CyberResourceProvisioningAction type has
I’m writing a WCF service that returns data in JSON format to clients. I
I'm having a strange problem with my WCF service that returns data in JSON

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.