c# - Dataset output to Excel Problem -
i using following code output data number of tables in database excel document:
protected void btnexcelexport_click(object sender, eventargs e) { string strquery = "select s.story, s.storycategoryid, convert(varchar(10), s.creationdate, 103) creationdate, m.companyrole, af.name story s inner join projectiterationmember pm on pm.projectiterationmemberid = s.projectiterationmemberid inner join iterations on i.projectiterationid = pm.projectiterationid inner join member m on m.memberid = pm.memberid inner join projectstoryfactors psf on psf.storyid = s.storyid inner join agilefactors af on af.agilefactorid = psf.agilefactorid i.projectid = '" + proj_id + "'"; sqlcommand cmd = new sqlcommand(strquery); datatable dt = getdata(cmd); gridview gridview1 = new gridview(); gridview1.allowpaging = false; gridview1.datasource = dt; gridview1.databind(); response.clear(); response.buffer = true; response.addheader("content-disposition","attachment;filename=retrocloud" + datetime.now.ticks + ".xls"); response.charset = ""; response.contenttype = "application/vnd.ms-excel"; stringwriter sw = new stringwriter(); htmltextwriter hw = new htmltextwriter(sw); (int = 0; < gridview1.rows.count; i++) { gridview1.rows[i].attributes.add("class", "textmode"); } gridview1.rendercontrol(hw); string style = @"<style> .textmode { mso-number-format:\@; } </style>"; response.write(style); response.output.write(sw.tostring()); response.flush(); response.end();
the output follows:
story | storycategoryid | creationdate | companyrole | name negative iii | 1 | 21/02/2011 | business analyst | project duration negative iii | 1 | 21/02/2011 | business analyst | team size negative iii | 1 | 21/02/2011 | business analyst | process negative ccc | 1 | 22/02/2011 | admin | workspace layout negative ccc | 1 | 22/02/2011 | admin | organisational , reporting structure negative ccc | 1 | 22/02/2011 | admin | process
what 2 things. sample code appreciated - wreching head! many help!
1) storycategoryid, if 1 retrieved - display 'negative' , if 0 retrieved - display 'positive' instead.
2) have output in following format:
story | story type | creation date | company role | tag 1 | tag 2 | tag 3
negative iii | 1 | 21/02/2011 | business analyst | project duration | team size | process negative ccc | 1 | 22/02/2011 | admin | workspace layout | organisational | process
well, maybe not best solution, might want:
select story , case storycategoryid when 1 'negative' when 0 'positive' else cast(storycategoryid varchar(10)) storycategoryid , creationdate , companyrole , max(case when z.minname = af2.name af2.name else '' end) tag1 , max(case when z.minname <> af2.name , z.maxname <> af2.name af2.name else '' end) tag2 , max(case when z.maxname = af2.name af2.name else '' end) tag3 ( select s.story , s.storycategoryid , convert(varchar(10), s.creationdate, 103) creationdate , m.companyrole , af.agilefactorid , min(af.name) minname , max(af.name) maxname story s inner join projectiterationmember pm on pm.projectiterationmemberid = s.projectiterationmemberid inner join iterations on i.projectiterationid = pm.projectiterationid inner join member m on m.memberid = pm.memberid inner join projectstoryfactors psf on psf.storyid = s.storyid inner join agilefactors af on af.agilefactorid = psf.agilefactorid i.projectid = '" + proj_id + "'"; group s.story, s.storycategoryid, convert(varchar(10), s.creationdate, 103), m.companyrole, af.agilefactorid ) z inner join agilefactors af2 on af2.agilefactorid = z.agilefactorid group story, storycategoryid, createdate, companyrole
Comments
Post a Comment