Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. excel

excel

Scheduled Pinned Locked Moved ASP.NET
help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    niki_nilu
    wrote on last edited by
    #1

    hi i want on butttonclick event all data transfer in excel and save it. in my code when i click on btnSaveToExcel button that time one dialogbox open wheh ask you want to save file in .exe . if yes click then file saved on desktop or whtever path.but when you want to open it that time excel open but there one popupbox comming which have message unable to read file. pls help me. this is my code protected void btnSaveToExcel_Click(object sender, EventArgs e) { objVarInit.sqlDS.Reset(); objVarInit.sqlDT.Reset(); objClsDllSql.sqlCon = objReadIniFile.funReadIniSql(); objClsDllSql.sqlCon.Open(); objVarInit.sqlDA = new SqlDataAdapter("select * from tUser", objClsDllSql.sqlCon); //objVarInit.sqlDT = new DataTable(); objVarInit.sqlDA.Fill(objVarInit.sqlDT); objClsDllSql.sqlCon.Close(); Response.Clear(); Response.ContentType = "application/vnd.ms-excel"; string sep = ""; foreach (DataColumn dc in objVarInit.sqlDT.Columns) { Response.Write(sep + dc.ColumnName); sep = "\t"; } Response.Write("\n"); int i; foreach (DataRow dr in objVarInit.sqlDT.Rows) { sep = ""; for (i = 0; i < objVarInit.sqlDT.Columns.Count; i++) { Response.Write(sep + dr[i].ToString()); sep = "\t"; } Response.Write("\n"); } }

    Gayatri

    C P 2 Replies Last reply
    0
    • N niki_nilu

      hi i want on butttonclick event all data transfer in excel and save it. in my code when i click on btnSaveToExcel button that time one dialogbox open wheh ask you want to save file in .exe . if yes click then file saved on desktop or whtever path.but when you want to open it that time excel open but there one popupbox comming which have message unable to read file. pls help me. this is my code protected void btnSaveToExcel_Click(object sender, EventArgs e) { objVarInit.sqlDS.Reset(); objVarInit.sqlDT.Reset(); objClsDllSql.sqlCon = objReadIniFile.funReadIniSql(); objClsDllSql.sqlCon.Open(); objVarInit.sqlDA = new SqlDataAdapter("select * from tUser", objClsDllSql.sqlCon); //objVarInit.sqlDT = new DataTable(); objVarInit.sqlDA.Fill(objVarInit.sqlDT); objClsDllSql.sqlCon.Close(); Response.Clear(); Response.ContentType = "application/vnd.ms-excel"; string sep = ""; foreach (DataColumn dc in objVarInit.sqlDT.Columns) { Response.Write(sep + dc.ColumnName); sep = "\t"; } Response.Write("\n"); int i; foreach (DataRow dr in objVarInit.sqlDT.Rows) { sep = ""; for (i = 0; i < objVarInit.sqlDT.Columns.Count; i++) { Response.Write(sep + dr[i].ToString()); sep = "\t"; } Response.Write("\n"); } }

      Gayatri

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Where is the file coming from ? Is the file created on the server and then sent to the client ? Does the file exist as you expect ? Are you sure it will exist on the server, not the client, when this is deployed ?

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      N 1 Reply Last reply
      0
      • N niki_nilu

        hi i want on butttonclick event all data transfer in excel and save it. in my code when i click on btnSaveToExcel button that time one dialogbox open wheh ask you want to save file in .exe . if yes click then file saved on desktop or whtever path.but when you want to open it that time excel open but there one popupbox comming which have message unable to read file. pls help me. this is my code protected void btnSaveToExcel_Click(object sender, EventArgs e) { objVarInit.sqlDS.Reset(); objVarInit.sqlDT.Reset(); objClsDllSql.sqlCon = objReadIniFile.funReadIniSql(); objClsDllSql.sqlCon.Open(); objVarInit.sqlDA = new SqlDataAdapter("select * from tUser", objClsDllSql.sqlCon); //objVarInit.sqlDT = new DataTable(); objVarInit.sqlDA.Fill(objVarInit.sqlDT); objClsDllSql.sqlCon.Close(); Response.Clear(); Response.ContentType = "application/vnd.ms-excel"; string sep = ""; foreach (DataColumn dc in objVarInit.sqlDT.Columns) { Response.Write(sep + dc.ColumnName); sep = "\t"; } Response.Write("\n"); int i; foreach (DataRow dr in objVarInit.sqlDT.Rows) { sep = ""; for (i = 0; i < objVarInit.sqlDT.Columns.Count; i++) { Response.Write(sep + dr[i].ToString()); sep = "\t"; } Response.Write("\n"); } }

        Gayatri

        P Offline
        P Offline
        Prateek G
        wrote on last edited by
        #3

        I can think of two ways to put your data into excel file... 1.) Use com object.Add reference to microsoft office and use namespace microsoft.office.interop.excel; then create ur workbook, worksheet and put all the data one by one in a forloop. Export To Excel[^] Export to excel.[^] 2.) Another and very interesting way of doing it use xsl transformation.wot u need to do is just get xml from dataset and then apply xsl on the same and create ur excel sheet.Lemme knw if u r interested...

        modified on Monday, December 10, 2007 5:24:30 AM

        1 Reply Last reply
        0
        • C Christian Graus

          Where is the file coming from ? Is the file created on the server and then sent to the client ? Does the file exist as you expect ? Are you sure it will exist on the server, not the client, when this is deployed ?

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          N Offline
          N Offline
          niki_nilu
          wrote on last edited by
          #4

          hi i want code for -- i am using farpoint spreadshhet control. and my database is in sql. i want to save data in excel on button click. and iam using asp.net 2.0 with c#.

          Gayatri

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups