Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How would you add MULTITHREADING to the attached C# code? 4 62
Error on link 14 48
Get Client IP on RDS - VB.NET 15 47
Release Dynamically Allocated Memory in C# 3 26
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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