protected void btnGenerarExcel_Click(object sender, EventArgs e) { int intIdInforme; int intGrupo = 0; int idUsuario = 2698; // Usuario Bancor int idCliente = 3490; // Cliente Bancor EncabezadoApp Encabezado = new EncabezadoApp(); UsuarioAutenticado Usuario = (UsuarioAutenticado)Session["UsuarioAutenticado"]; if (dgExportar.Items.Count > 0) { intGrupo = Encabezado.crearGrupoCambioEstado(Usuario.IdUsuario, 15); } int idRef; ReferenciasApp Referencia = new ReferenciasApp(); DateTime ahora = DateTime.Now; Usuario nUsuario = new Usuario(); nUsuario.Cargar(idUsuario); Referencia.Descripcion = nUsuario.Apellido + ", " + nUsuario.Nombre + " " + ahora.Day + "/" + ahora.Month; Referencia.Estado = 1; Referencia.Observaciones = ""; Referencia.Path = ""; Referencia.isFile = 0; //Referencia.IdUsuario = Usuario.IdUsuario; Referencia.UsuarioCliente = ""; Referencia.IdCliente = idCliente; idRef = Referencia.Crear(); Response.Write("<script>menu = " + menuTab.SelectedItem.Value + ";</script>"); /* * Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass(); * ExcelApp.Application.Workbooks.Add(Type.Missing); * ExcelApp.Columns.ColumnWidth = 30; * * for (int i = 0; i < dgExportar.Rows.Count; i++) * { * DataGridViewRow row = ReportDataGridView.Rows[i]; * for (int j = 0; j < row.Cells.Count; j++) * { * ExcelApp.Cells[i + 1, j + 1] = row.Cells[j].ToString(); * } * } */ libro = ApExcel.Workbooks.Add(opc); ApExcel.Visible = true; libro = ApExcel.Workbooks.Add(opc); Microsoft.Office.Interop.Excel.Worksheet hoja1 = new Microsoft.Office.Interop.Excel.Worksheet(); hoja1 = (Microsoft.Office.Interop.Excel.Worksheet)libro.Sheets.Add(opc, opc, opc, opc); hoja1.Activate(); //hoja1.Cells[1,1] = 100; int ac = 1; System.Web.UI.WebControls.CheckBox chkPersona; hoja1.Cells[1, 1] = "Apellido y nombre"; hoja1.Cells[1, 2] = "Documento"; hoja1.Cells[1, 3] = "Tipo de vivienda"; hoja1.Cells[1, 4] = "Destino del inmueble"; hoja1.Cells[1, 5] = "Estado de conservacion"; hoja1.Cells[1, 6] = "Habita/vive en caracter de "; hoja1.Cells[1, 7] = "Resultado"; hoja1.Cells[1, 8] = "Observaciones"; hoja1.Range["a1:h1"].Font.Bold = true; //hoja1.Range["a1:h1"].colorIndex = 15; foreach (DataGridItem myItem in dgExportar.Items) { chkPersona = ((System.Web.UI.WebControls.CheckBox)dgExportar.Items[myItem.DataSetIndex].FindControl("chkSUrgente")); //chkPersona = (System.Web.UI.WebControls.CheckBox)dgExportar.FindControl("chkSUrgente"); if (chkPersona.Checked) { //ac = myItem.ItemIndex + 2; ac += 1; hoja1.Cells[ac, 1] = myItem.Cells[4].Text; hoja1.Cells.Columns.ColumnWidth = 25; hoja1.Cells[ac, 2] = myItem.Cells[5].Text; hoja1.Cells.Columns.ColumnWidth = 11; hoja1.Cells[ac, 3] = myItem.Cells[6].Text; hoja1.Cells.Columns.ColumnWidth = 15; hoja1.Cells[ac, 4] = myItem.Cells[7].Text; hoja1.Cells.Columns.ColumnWidth = 20; hoja1.Cells[ac, 5] = myItem.Cells[8].Text; hoja1.Cells.Columns.ColumnWidth = 20; hoja1.Cells[ac, 6] = myItem.Cells[9].Text; hoja1.Cells.Columns.ColumnWidth = 16; hoja1.Cells[ac, 7] = myItem.Cells[10].Text; hoja1.Cells.Columns.ColumnWidth = 10; hoja1.Cells[ac, 8] = myItem.Cells[11].Text.Replace(" ", ""); //hoja1.Cells.Columns.ColumnWidth = 80; Encabezado.Entregado = 1; Encabezado.CambiarEntregado(int.Parse(myItem.Cells[1].Text)); Encabezado.crearCambiosEstadoInformes(intGrupo, int.Parse(myItem.Cells[1].Text), 3); } } /* * for (int i = 0; i < dgExportar.Items.Count; i++) * { * DataGridRow row = ReportDataGridView.Rows[i]; * for (int j = 0; j < row.Cells.Count; j++) * { * ExcelApp.Cells[i + 1, j + 1] = row.Cells[j].ToString(); * } * } */ DateTime fechaActual = DateTime.Now; string fechaArchivo = fechaActual.Year.ToString() + fechaActual.Month.ToString() + fechaActual.Day.ToString(); //hoja1.SaveAs("D:\\Sitios\\TyG\trunk\\FrontEnd\\Intranet\\res\\bancor\\bancor_" + fechaArchivo); hoja1.SaveAs("F:\\Sitios\\Res\\bancor\\bancor_" + fechaArchivo); hoja1 = null; libro.Close(false); libro = null; ApExcel.Quit(); ApExcel = null; //WebClient webClient = new WebClient(); string urlDw = "http://www.tiempoygestion.com.ar:81/Res/bancor/"; string fileDw = "bancor_" + fechaArchivo + ".xls"; lblDescargar.Visible = true; hlDescargar.Visible = true; lblDescargar.Text = "Descargar planilla "; hlDescargar.Text = fileDw; hlDescargar.NavigateUrl = urlDw + fileDw; //webClient.DownloadFile(urlDw + fileDw, fileDw); //System.IO.FileInfo toDownload =new System.IO.FileInfo(urlDw + fileDw); //Response.AddHeader("Content-Disposition", "attachment; filename=" + fileDw); //Response.AddHeader("Content-Length", toDownload.Length.ToString()); //Response.ContentType = "application/octet-stream"; //Response.WriteFile(urlDw + fileDw); //Response.End(); /* * //FUNCA * Response.Clear(); * Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); * Response.Charset = ""; * //Response.Cache.SetCacheability(HttpCacheability.NoCache); * Response.ContentType = "application/vnd.xls"; * System.IO.StringWriter stringWrite = new System.IO.StringWriter(); * System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); * dgExportar.RenderControl(htmlWrite); * Response.Write(stringWrite.ToString()); * Response.End(); */ }