Solved

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

Posted on 2007-04-09
1
256 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

12 Experts available now in Live!

Get 1:1 Help Now