Solved

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

Posted on 2007-04-09
1
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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