locked
Excel export RRS feed

  • Question

  • Anyone know how to export to excel a datagrid in a web application?In desktop with office integration pack i can do that without a problem but when i pass to web application doesn´t work...
    • Edited by AndreAlves Monday, July 15, 2013 2:42 PM
    Monday, July 15, 2013 2:41 PM

Answers

  • Hi

    Go through the below post this will help you to solve your problem

    How to export data to CSV using Microsoft Lightswitch Web Application

    Please do follow that post....then realise that it is a copy of the post that I referred to before and that the "solution" that it provides is the solution in my post! Just as a way of explination, in my post I refer to a site that asks to be paid for help....wonder what site that is.

    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Marked as answer by AndreAlves Wednesday, July 24, 2013 12:39 PM
    Tuesday, July 16, 2013 1:22 PM

All replies

  • Hello

    Have you searched this site at all? Follow this link (Removing ControlAvailiable) where I am doing a similar thing to what you require. It creates a CSV file rather than an XLS(X) but it does everything else you have asked.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Proposed as answer by Otis Ranger Monday, July 15, 2013 3:50 PM
    Monday, July 15, 2013 3:50 PM
  • Hi

    Go through the below post this will help you to solve your problem

    How to export data to CSV using Microsoft Lightswitch Web Application

    Regards


    Rashmi Ranjan Panigrahi
    www.lightswitchspecial.com

    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”.
    This will help other users to find their answer quickly.

    Tuesday, July 16, 2013 1:07 PM
  • Hi

    Go through the below post this will help you to solve your problem

    How to export data to CSV using Microsoft Lightswitch Web Application

    Please do follow that post....then realise that it is a copy of the post that I referred to before and that the "solution" that it provides is the solution in my post! Just as a way of explination, in my post I refer to a site that asks to be paid for help....wonder what site that is.

    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Marked as answer by AndreAlves Wednesday, July 24, 2013 12:39 PM
    Tuesday, July 16, 2013 1:22 PM
  • Hi Andre, Otis,

    Stretching back more than a decade we have served-up data in IE versions with the correct mime-type for Excel. That probably still works and gives a nice effect.

    You can definitely serve data up from the server and from the client side you will have to try.

    If I had the time I would do it, but I don't this week, so if either of you have the time then perhaps we can enhance the existing solution and put this one to bed... :)

    Refer to MSDN example like this here


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Tuesday, July 16, 2013 2:40 PM
  • Tuesday, July 16, 2013 3:13 PM
  • @ Dave.  I would love to see a solution like the one you describe!

    For a client solution that works well, see my response to this thread.  This was formulated based on several different forums and blog posts.  The advantage is that it allows for custom search queries used on the screen to be exported without paging and with all navigation properties, and shows the property display name as the header.  It does not rely on disabling paging on the client, which in my experience can cause errors.  My csv parser needs some help tho :)


    • Edited by Hessc Tuesday, July 16, 2013 3:20 PM edit
    Tuesday, July 16, 2013 3:19 PM
  • partialvoid Excel_Execute()        {

                // Write your code here.List<string> excel = newList<string>();             excel.Add("Entidade");             excel.Add("Data Inicial");             excel.Add("Data final");             excel.Add("Concursos para titulos notariais");             excel.Add("Observações");              Entidade_Tipoes.Refresh();             OfficeIntegration.Excel.Export(Entidade_Tipoes, excel);         }but when i click it said: object variable or with block variable not set

    Tuesday, July 23, 2013 2:04 PM
  • I need to export in web application not in desktop application.
    Tuesday, July 23, 2013 2:10 PM
  • @AndreAlves

    I am more than confused now. You said earlier that the CSV solution that I proposed works and now you just have to format the CSV. Why are you following up by trying to use the OfficeIntegration within a webapp?
    The whole reason for me doing the CSV export was because you couldnt do the Excel Export.

    @Dave

    Yes, back in the day when everyone had access to Notepad and you could create very simple HTML docs you could set the charset so that Excel 97-2000 would see it. In exactly the same way that Excel can open and manipulate a CSV File. I seriously doubt that anyone will be providing a way to create a web based export of data to Excel for free and quickly.

    As always, Im happy to be proved wrong.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Tuesday, July 23, 2013 2:34 PM
  • Ok, now i understand the problem, office integration only work in desktop application.

    Now the only problem i have is when i export to csv the info is coded, i think the problem is the accents...

    Tuesday, July 23, 2013 4:26 PM
  • @AndreAlves

    If you can explain your problem a little better and maybe show us an example we may be able to help you solve your issue.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Wednesday, July 24, 2013 5:49 AM
  • @Otis

    The mime-type trick still works today. Nothing much changed except the version of office that you are likely using. I just tried it.


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Wednesday, July 24, 2013 7:58 AM
  • Wednesday, July 24, 2013 10:42 AM
  • @AndreAlves

    Not the best explination in the world but try this:-

    Where you are creating the new StreamWriter connection add the encoding option after it like below...

                        if (dialog.ShowDialog() == true)
                        {
                            using (StreamWriter stream = new StreamWriter(dialog.OpenFile(), System.Text.Encoding.UTF8))
                            {
                                stream.Write(csv);
                                stream.Close();
                            }
                        }
    

    Not tested but should work

    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Wednesday, July 24, 2013 11:08 AM
  • Yes problem solved!!!

    Thanks a lot!!

    Wednesday, July 24, 2013 12:27 PM
  • Yes problem solved!!!

    Brilliant. Happy to help. Can you please mark the question as answered so it can help others?


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Wednesday, July 24, 2013 12:34 PM
  • Can you please explain your Code more iam doing the same but Iam exporting to a desktop application :(

       partial void ExportToExcel_Execute()
            {
                // Write your code here.
                List <String> Excel = new List<string>
                Excel.Add("Hotel_Number");
                OfficeIntegration.Excel.Export(??what should I put here???,Excel);
            }

    Thanks,

    Zayed

    Tuesday, August 19, 2014 10:52 AM
  • Hello Zayed

    I dont understand what you are asking. This question is about an Excel Export in a Web appilcation and NOT a desktop application. A simple Google search will give you the answers you are looking for. Or you could go to http://officeintegration.codeplex.com/ and look at the downloads or documents section


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Thursday, August 21, 2014 8:28 AM
  • Hi Otis,

    I am really searching for 3 days now, and I cannot find a good example for the function Export in Officeintergration (C#).

    I guess the code is the same for Desktop application and for web application regarding the export function. I just have a problem regarding this part:

    partial void ExportToExcel_Execute()
           
    {
               
    // Write your code here. 
               
    OfficeIntegration.Excel.Export(??what should I put here???);
           
    }

    ---- > I want to export the whole screen (in an excel table), can you help me in this?

    Thanks,

    Zayed

    Thursday, August 21, 2014 8:34 AM
  • There is no code for the Web application as the office integration pack doesnt work with it, hence my answer! I am also unsure why you are searching as http://officeintegration.codeplex.com/ covers what you need on the Export side. It seems like you just want to copy and paste code without understanding what you are doing.

    What should go in your ""??what should I put here???" is your dataset. if your dataset was called DataSetName then you would enter This.DataSetName. For all the other overloads (i.e. file name, location and column names) you need to look at the documentation


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Thursday, August 21, 2014 8:45 AM
  • Thanks for your really polite answer (you just want to copy and paste code without understanding what you are doing).


    Thursday, August 21, 2014 8:53 AM
  • Thank you. It came about from the fact that you hadnt read any of the other replies that were on this question and the fact that a single search would give you what you had spent "3 days" searching for.

    The documentation here maybe a little confusing for the first time programmer but as it states at the top of the page you can download the example applications that are extensively commented and will walk you through what you need. Sometimes doing is the best way to learn


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Thursday, August 21, 2014 9:01 AM
  • I sow the documentation before. and this is not C# and my project is in C#. I wouldn't ask here if I didn't do a good search about this topic.
    Thursday, August 21, 2014 9:07 AM
  • Then all you need is something like this.

    It can take VB.Net code and convert it to C# just as it has below

    List<string> names as New List<string>
    names.Add("Name")
    names.Add("Address")
    names.Add("City")
    Export(this.Applicants, names) 
    


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Thursday, August 21, 2014 9:19 AM
  • Thanks for the website, its a great tool.

    But this is the code that I want to convert :

    Private Sub ExportToExcel_Execute()
     Dim ExcelFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Customers.xlsx"
    
        If File.Exists(ExcelFile) Then
            Dim fields As New List(Of String) From
                {"CompanyName", "ContactName", "ContactTitle", "Phone"}
    
            OfficeIntegration.Excel.Export(Me.Customers, ExcelFile, "Sheet1", "A1", fields)
        End If
    End Sub
    Office Integration Pack Extension for LightSwitch

    Thursday, August 21, 2014 9:36 AM
  • I did it:

     partial void New_Excel_Export_Execute()
            {
             
                 // Write your code here. 
                // OfficeIntegration.Excel.Export(this.BalanceGreaterZero);   --- Export all screen
                List<string> columns = new List<string>();
        
                columns.Add("Costomer_No_");
                columns.Add("Hotel_Name");
                columns.Add("Post_Code");
                columns.Add("Hotel_City");
                columns.Add("Country");
                columns.Add("Hotel_Status");
                columns.Add("Contract_Status_Code");
                columns.Add("Chain_Code");
                columns.Add("Brand_Name");
                columns.Add("Brand_Code");
                columns.Add("Brand_Name");
                columns.Add("Electronic_Payment_Method");
                columns.Add("Reason_Code1");
                columns.Add("Inkasso");
                columns.Add("Balance__LCY_");
                OfficeIntegration.Excel.Export(this.BalanceGreaterZero, columns);
    
             } 

    • Proposed as answer by Consultant_606 Friday, August 22, 2014 10:29 AM
    Friday, August 22, 2014 10:29 AM