Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8044569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:16:18+00:00 2026-06-05T05:16:18+00:00

Well, this certainly might have not been asked before. I have a method that

  • 0

Well, this certainly might have not been asked before.

I have a method that returns me an IQueryable, the client requirement is one specific example we should export that to excel without showing the results in a gridview.

Any idea?

string strSql = BuildQuery();
            try
            {
                var list = RequestBaseBL.GetRequestByCustomQuery(strSql, DdlRequestType.SelectedValue).ToList();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:16:20+00:00Added an answer on June 5, 2026 at 5:16 am

    to export in excel have a look here:

    http://epplus.codeplex.com/releases/view/42439

    then you can create your own class to generate excel export for IEnumerable

    here some hint (these are part of more large object so only hints, nothing compiling surely) at the possible from one of my projects:

     public interface IExcelReporting : IServiceObject
        {
            ColumnsExcel Columns { get; }
    
            void SetDatasource(IEnumerable datasource);
            void SetHeaderLabelMerge(int columnMerge);
            void AddHeader(string label, string value);
            Byte[] ExportToExcel(string title, string author, DateTime date);
        }
    

    an example of implementation :

      public Byte[] ExportToExcel(string title, string author, DateTime date)
        {
            ExcelPackage package = new ExcelPackage();
    
            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(title);
    
    if (_Columns != null)
                {
    
                    Dictionary<int, Func<object, string>> internalMappingGetter = new Dictionary<int, Func<object, string>>();
    
                    //create the Header of the body
                    foreach (ColumnExcel entity in _Columns)
                    {
                        worksheet.Cells[RowIndex, ColumnIndex].Value = entity.HeaderName;
                        worksheet.Cells[RowIndex, ColumnIndex].Style.WrapText = true;
                        BorderCell(worksheet.Cells[RowIndex, ColumnIndex]);
                        worksheet.Column(ColumnIndex).Width = entity.Width;
                        ColumnIndex++;
                    }
    
                    RowIndex++;
    
                    if (_DataSource != null)
                    {
                        foreach (Object o in _DataSource)
                        {
                            ColumnIndex = 1;
                            foreach (ColumnExcel column in _Columns)
                            {
                                column.Apply(worksheet.Cells[RowIndex, ColumnIndex], o);
                                worksheet.Column(ColumnIndex).BestFit = true;
                                worksheet.Cells[RowIndex, ColumnIndex].Style.WrapText = true;
                                //BorderCell(worksheet.Cells[RowIndex, ColumnIndex]);
                                ColumnIndex++;
                            }
                            RowIndex++;
                        }
                    }
    

    and the column class:

    public class ColumnsExcel : IEnumerable
        {
            List<ColumnExcel> _Columns;
    
            public ColumnsExcel()
            {
                _Columns = new List<ColumnExcel>();
            }
    
    
            public void AddInt(Func<object,int> getValue, string headerName, int width, string format)
            {
                ColumnExcel entity = new ColumnExcelInt(headerName, width, format, getValue);
                _Columns.Add(entity);
            }
    
            public void AddString(Func<object, string> getValue, string headerName, int width )
            {
                ColumnExcel entity = new ColumnExcelstring(headerName, width, getValue);
                _Columns.Add(entity);
            }
    
            public void AddDateTime(Func<object, DateTime?> getValue, string headerName, int width, string format)
            {
                ColumnExcel entity = new ColumnExcelDateTime(headerName, width, format, getValue);
                _Columns.Add(entity);
            }
    
            public void AddDecimal(Func<object, decimal> getValue, string headerName, int width, string format)
            {
                ColumnExcel entity = new ColumnExcelDecimal(headerName, width, format, getValue);
                _Columns.Add(entity);
            }
    
            public IEnumerator GetEnumerator()
            {
                return _Columns.GetEnumerator();
            }
        }
    

    and its use :

     //prepare the Ienumerable<MyObject>
     var interventi = GetInterventoSchedeConsuntivi()
    
     //prepare the report
     IExcelReporting report = ReportingFactory.GetInstance();
     report.SetDatasource(interventi);
     report.AddHeader("Lotto:", lotto);
    
     report.Columns.AddString((object v) => ((InterventoSchedeConsuntiviView)v).Lotto, "Lotto", 20);
    
    using (System.IO.Stream s = File.Create(filepath))
                        {
                            byte[] csv = report.ExportToExcel(("titleFile", string.Empty, Servizi.DataOra.Now);
                            s.Write(csv, 0, csv.Length);
                        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class extends NamedParameterJdbcDaoSupport. well this superclass has a final setDataSource method
I'm trying to do this: $('li').eq(newCurrent).addClass('current'); I've tried index() as well but I'm certainly
Well this is my first experience with lambda, and I know I might be
I hope I can explain this well enough so that you can understand the
I have been working on a project where I have a Worker class that
I have asked this question earlier today but I didn't provide enough information and
I've been creating this pretty large web application for sometime and have been updating
I have an interesting situation that my usually clever mind hasn't been able to
I have a particular function (well, set of functions) that I want to start
(Well,this is the first time i ask questions here and English isn't my first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.