Inquiridor
exportar 2 Gridview para excel

Pergunta
-
boa tarde pessoal ,gostaria de exportar 2 gridview para excel um do lado do outro na mesma planilkhaconsegui exportar os dois mas esta saindo um a baixo do outro assim .alguem pode me ajudar
RELATÓRIO DE SEPARAÇÃO DE LINHA POR USUÁRIO USUÁRIO QTDE ALISON 51 ALISSA 118 ALMENI 74 ALTAMIR 155 ANANDA 80 B00MWS 15 BARBOSA 59 BIANCA 110 USUÁRIO QTDE B00CHC 67 B00ERR 263 B00LXM 150 B00MAG 79 B00MWS 91 B00SBH 109 B00SLR 12 BARBARA 214 BRUNA 158 CASSIANO 156 CSILVA 228 FMANGA 237 GUI 141 JBEL 131 JULIO 206 LVEECK 7 MPOLI 206 ODAIR 190 SIDNEI 3 VERITIANA 160 VSANTOS 161 ZORAIA 236 gostaria que ficasse assim
USUÁRIO QTDE ALISON 51 ALISSA 118 ALMENI 74 ALTAMIR 155 ANANDA 80 B00MWS 15 BARBOSA 59 BIANCA 110 DANIELE 205 GABRIELA 81 GENZ 184 GIOVANI 123 GUILHERME 27 HERNANI 73 JULIO 4 KELLI 122 LSOUZA 4 LUIS 126 LVEECK 3 MANICA 88 MARCIA 21 MARCOS 136 MBITEN 67 MRODRIGUES 34 PATRICIA 112 PIROLI 47 RAQUEL 127 RMANOEL 69 ROSA 158 ROSALINA 176 TAMARA 163 USUÁRIO QTDE B00CHC 67 B00ERR 263 B00LXM 150 B00MAG 79 B00MWS 91 B00SBH 109 B00SLR 12 BARBARA 214 BRUNA 158 CASSIANO segue meu Code:
public void Exporta_VariosGrids(string header, string nomeArquivo,int ori)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=RelatorioLinha.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
if (header != string.Empty)
hw.WriteLine(header);
//aplica estilo a celula individual
for (int k = 0; k < grdRelatorioSep.HeaderRow.Cells.Count; k++)
{
grdRelatorioSep.HeaderRow.Cells[k].Style.Add("background-color", "#CCC");
}
Table tb1 = new Table();
Table tb = new Table();
TableRow tr1 = new TableRow();
TableRow tr2 = new TableRow();
TableCell cell1 = new TableCell();
TableCell cell2 = new TableCell();
cell1.Controls.Add(grdRelatorioSep);
cell2.Controls.Add(grdRelatorioConf);
if (ori == 2) //horizontal
{
tr1.Cells.Add(cell1);
tr2.Cells.Add(cell2);
cell1.RenderControl(hw);
cell2.RenderControl(hw);
}
tb.Rows.Add(tr2);
//style to format numbers to string
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}- Movido C. Augusto Proiete [MVP]Moderator quinta-feira, 19 de abril de 2012 22:46 Movido para o forum apropriado (De:.NET Development - Geral)
Todas as Respostas
-
-
cara minha query já faço union ela vem pronto com datatable 3 colunas situação-usuario-qtdeitemfiz assim e consigo exportar mas não fica assim como na minha pagina aspx.
pagina aspx fica assim :
Análise de Separação Análise de Conferência USUÁRIO QTDE ALMENI 26 ALTAMIR 1 ANANDA 78 B00MWS 5 DANIELE 17 GENZ 97 GUILHERME 22 LEONAN 2 MANICA 20 MBITEN 69 PIROLI 34 RMANOEL 1 SUELEN 1 TAMARA 5 USUÁRIO QTDE ALINE 59 B00CHC 70 B00ERR 76 B00LXM 21 B00MAG 62 B00MWS 49 B00SBH 61 B00SLR 41 BARBARA 20 BRUNA 38 CASSIANO 30 FMANGA 97 GUI 11 JBEL 97 JULIO 97 MPOLI 70 ODAIR 29 VERITIANA 37 VSANTOS 67 ZORAIA 100 Total:378 Total:1132 no excel fica assim:
USUARIO QTDEITEM USUARIO QTDEITEM ALINE 39 ALISSA 2 ALMENI 26 ALTAMIR 1 ANANDA 78 B00MWS 5 BIANCA 5 DANIELE 32 GENZ 97 GUILHERME 22 KELLI 8 LEONAN 2 MANICA 20 MBITEN 69 PIROLI 34 RMANOEL 1 ROSA 8 SUELEN 9 TAMARA 5 ALINE 59 B00CHC 70 B00ERR 76 B00LXM 21 B00MAG 62 B00MWS 49 B00SBH 61 B00SLR 41 BARBARA 46 BRUNA 38 CASSIANO 30 FMANGA 97 GUI 11 JBEL 108 JULIO 97 MPOLI 78 ODAIR 46 VERITIANA 41 VSANTOS 67 ZORAIA 100 alguem tem alguma ideia de como posso deixar uma do lado da outro como na pagina
segue meu Code Behind.
public static void ExportToExcel(DateTime dtaini, DateTime dtafim, GridView dr, GridView dr1)
{
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
HttpContext context = HttpContext.Current;
DataTable dt = RelatorioData.GetInstance().LinhaUsuario(dtaini, dtafim);
decimal vtotalsep = 0;
decimal vtotalconf = 0;
string xcol = ";";
context.Response.Clear();
context.Response.ContentType = "text/csv"; ///"application/vnd.ms-excel";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=Relatorio.csv");
context.Response.Charset = "";
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
///colunas
context.Response.Write(dt.Columns[1] + ";" + dt.Columns[2]);
context.Response.Write(xcol + xcol + dt.Columns[1] + xcol + dt.Columns[2]);
context.Response.Write(Environment.NewLine);
foreach (DataRow row in dt.Rows)
{
if (row["SITUACAO"].ToString() != "CONFERIDAS")
{
vtotalsep += +Convert.ToInt32(row["QTDEITEM"]);
context.Response.Write(row["USUARIO"].ToString() + ";" + row["QTDEITEM"].ToString());
context.Response.Write(Environment.NewLine);
}
}
foreach (DataRow xrow in dt.Rows)
{
if (xrow["SITUACAO"].ToString() != "SEPARADAS")
{
vtotalconf += +Convert.ToInt32(xrow["QTDEITEM"]);
context.Response.Write(xcol + xcol + xcol + xrow["USUARIO"].ToString() + xcol + xrow["QTDEITEM"].ToString());
context.Response.Write(Environment.NewLine);
}
}
context.Response.End();
}tentei tambem passar os dois Gridviw que populo como parametro e percorrer um por vez e exportar mas mesma coisa .o problema é como posso contorlar as linhas e colunas com objeto HttpContext.
-
Amigo, como está sua questão ? foi resolvida ? Se sim nos conte como você fez.
Obrigado.
Olavo Oliveira Neto
http://olavooneto.wordpress.com
Twitter @Olavooneto
Facebook Olavo Neto
Linkedin Olavo Neto
Se for útil marque como resposta e faça um Developer feliz :) -