create new excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yogarajan
    New Member
    • Apr 2007
    • 115

    create new excel

    hi All

    how can i create new excel sheet through asp.net (with c#)

    i have create report in aspx (with c#) and i store data in excel sheet also so user can select view report through web page or excel sheet

    this is my query

    any one know abt create excel

    pls guide me

    i need sample program

    Thanks
    Yogarajan.G
  • agarwalsunitadhn
    New Member
    • Jan 2008
    • 82

    #2
    Originally posted by yogarajan
    hi All

    how can i create new excel sheet through asp.net (with c#)

    i have create report in aspx (with c#) and i store data in excel sheet also so user can select view report through web page or excel sheet

    this is my query

    any one know abt create excel

    pls guide me

    i need sample program

    Thanks
    Yogarajan.G

    That mean u want to export ur created report to Ms-Excel

    Comment

    • yogarajan
      New Member
      • Apr 2007
      • 115

      #3
      Hi Agarwal

      yes. i want create my report to xls format also

      Thanks
      Yogarajan.G

      Originally posted by agarwalsunitadh n
      That mean u want to export ur created report to Ms-Excel

      Comment

      • Brad Orders
        New Member
        • Feb 2008
        • 21

        #4
        Hi Yogarajan

        There are a number of ways you can do this, ranging from simple to painful. If you are just using a Datagrid, then one simple and quick way to display it in Excel is just change the content type like this:

        Code:
        Response.ContentType = "application/vnd.ms-excel"
        However, you will need to make sure that the HTML in the page is clean and really simple. I would suggest making your navigation, banners, etc invisible, so only a simple table layout is opened in Excel.

        Hope this helps

        Comment

        • agarwalsunitadhn
          New Member
          • Jan 2008
          • 82

          #5
          Originally posted by yogarajan
          Hi Agarwal

          yes. i want create my report to xls format also

          Thanks
          Yogarajan.G
          At First you place your report within a panel
          then use the following code:

          Response.Clear( );

          Response.AddHea der("content-disposition", "attachment;fil ename=ReportNam e.xls");

          Response.Conten tType = "applicatio n/vnd.ms-excel";

          Response.Charse t = "";

          this.EnableView State = false;

          System.IO.Strin gWriter tw=new System.IO.Strin gWriter();

          HtmlTextWriter hw = new HtmlTextWriter( tw);

          PanelName.Rende rControl(hw);

          Response.Write( tw.ToString());

          Response.End();

          Try this one.It solve ur problem upto a large extent

          Comment

          • yogarajan
            New Member
            • Apr 2007
            • 115

            #6
            Hi Agarwal

            i have little bit confussion. where i can insert your code

            /////////////my code start here
            Code:
            Excel.ApplicationClass objExl = new Excel.ApplicationClass();
                        string excelfilepath = Server.MapPath(".") + "/ExcelReport/sampleReport123.xls";
                       
                        Excel.Workbook ExlWrBk = objExl.Workbooks.Open(excelfilepath, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "", false, false, 0, true, 1, 0);
            
                        Excel.Sheets ExlShts = ExlWrBk.Worksheets;
            
                        Excel.Worksheet objWrSht = (Excel.Worksheet)ExlShts.get_Item("sampleReport");
            
                        Excel.Range ExlRng = (Excel.Range)objWrSht.get_Range("A1", "A1");
            
            
                        SqlCommand cmd = new SqlCommand("select * from customermaster", db_con);
            
                        //SqlDataReader dr = null;
            
                        SqlDataReader dr5 = cmd.ExecuteReader();
            
                        DataSet ds = new DataSet();
                        
                        int Row = 2;
            
            
                        while (dr5.Read())
                        {
            
                            objWrSht.Cells[Row, 1] = "1";
            
                            objWrSht.Cells[Row, 2] = dr5["cusname"];//ds.Tables[0].Columns["cusName"];
            
                            objWrSht.Cells[Row, 3] = dr5["cusCompany"];
            
                            objWrSht.Cells[Row, 4] = dr5["cusindustry"];
            
                            objWrSht.Cells[Row, 5] = dr5["cusdesig"];
            
                            objWrSht.Cells[Row, 6] = dr5["cusaddress1"];
            
                            objWrSht.Cells[Row, 7] = dr5["cusaddress2"];
            
                            objWrSht.Cells[Row, 8] = dr5["cuscity"];
            
                            objWrSht.Cells[Row, 9] = dr5["cuspincode"];
            
                            objWrSht.Cells[Row, 10] = dr5["cusmobileno"];
            
                            objWrSht.Cells[Row, 11] = dr5["cusLandLineNo"];
            
                            objWrSht.Cells[Row, 12] = dr5["cusEmail"];
            
                            objWrSht.Cells[Row, 13] = dr5["cusintereston"];
            
                            objWrSht.Cells[Row, 14] = dr5["cusinterestlevel"];
            
                            objWrSht.Cells[Row, 15] = dr5["cusdatelastmet"];
            
                            objWrSht.Cells[Row, 16] = dr5["cusnextmeetingdate"];
            
                            objWrSht.Cells[Row, 17] = dr5["cusFollowupstatus"];
            
            
                            Row = Row + 1;
            
                        }
                        objExl.Visible = true;
            //////////////////////my code end here

            pls reply as soon as possible

            Thanks
            Yogarajan.G

            Originally posted by agarwalsunitadh n
            At First you place your report within a panel
            then use the following code:

            Response.Clear( );

            Response.AddHea der("content-disposition", "attachment;fil ename=ReportNam e.xls");

            Response.Conten tType = "applicatio n/vnd.ms-excel";

            Response.Charse t = "";

            this.EnableView State = false;

            System.IO.Strin gWriter tw=new System.IO.Strin gWriter();

            HtmlTextWriter hw = new HtmlTextWriter( tw);

            PanelName.Rende rControl(hw);

            Response.Write( tw.ToString());

            Response.End();

            Try this one.It solve ur problem upto a large extent

            Comment

            • Rajeshshewale
              New Member
              • Aug 2007
              • 8

              #7
              I have written code here for read write Excel sheet:

              [Link Removed]

              Comment

              • MMcCarthy
                Recognized Expert MVP
                • Aug 2006
                • 14387

                #8
                @ Rajeshshewale

                If you wish to submit code please submit it in the thread and not using a link.

                ADMIN

                Comment

                • yogarajan
                  New Member
                  • Apr 2007
                  • 115

                  #9
                  Hi

                  thanks for your reply

                  pls send the code

                  Thanks
                  Yogarajan.G

                  Originally posted by Rajeshshewale
                  I have written code here for read write Excel sheet:

                  [Link Removed]

                  Comment

                  Working...