Solved

Create excel file through asp.net webservice............

Posted on 2007-04-09
1
257 Views
Last Modified: 2013-11-26
Hi,

I need to generate an xl file through web service.

Basically,  
I have a dataset populated data from database and need to create a xl file on server.  All this has to be done in a web service, and I will use smtp to send this file to an email address as an attachment.

I would like to know that which library I should reference in my asp.net webservice project.  

Any code samples using xl object to create files are appreciated.

Thank You.
cm
0
Comment
Question by:chandukb
1 Comment
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 125 total points
ID: 18922991
Excel.Application ea = new Excel.ApplicationClass();

Excel.Workbook wb = ea.Workbooks.Open(template, 0, true, 5, "", "", true,
Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

string currentSheet = "Daily Data";

Excel.Sheets eSheets = wb.Worksheets;
Excel.Worksheet eWs = (Excel.Worksheet)eSheets.get_Item(currentSheet);
                 
ea.Visible = true;
                 
DataTable table = ds.Tables[0];
                 
int ColumnIndex=0;
foreach(DataColumn col in table.Columns)
{
      ColumnIndex++;
      eWs.Cells[1,ColumnIndex]=col.ColumnName;
}

int count = table.Rows.Count;

int rowIndex=0;
foreach(DataRow row in table.Rows)
{
      rowIndex++;

      Console.WriteLine(count + " out of " + rowIndex);
      ColumnIndex=0;
      foreach(DataColumn col in table.Columns)
      {
            ColumnIndex++;
            eWs.Cells[rowIndex+1,ColumnIndex] = row[col.ColumnName];
      }
}

Excel.Worksheet worksheet = (Excel.Worksheet)ea.ActiveSheet;
worksheet.Activate();
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 160
How to deploy to IIS 7 on 2008R2 server with DUO 2-step login? 2 36
Class object 2 27
C#.NET and microsoft certification. 3 34
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now