?
Solved

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

Posted on 2007-04-09
1
Medium Priority
?
274 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 375 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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