excel
-
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
-
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
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 )
-
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
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
-
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 )