public static object GetSelectComprobante(int jtStartIndex, int jtPageSize, string jtSorting, String[] dataFrm) { int indexPage; int totalRow; if (jtStartIndex != 0) { indexPage = jtStartIndex / jtPageSize; } else { indexPage = jtStartIndex; } eComprobanteVC ec = frmConsultaComprobante.SetParametros(dataFrm); bComprobanteVC bc = new bComprobanteVC(); List<eComprobanteVC> list = bc.GetSelectComprobante(ec, indexPage, jtPageSize, jtSorting.Substring(1), out totalRow,"FORM"); return new { Result = "OK", Records = list, TotalRecordCount = totalRow }; }
private void exportarDataExecl(eComprobanteVC o) { int total; bComprobanteVC bc = new bComprobanteVC(); DataTable dt = bc.GetSelectComprobanteExport(o,0, 1000000, "NRO_COMPROBANTE ASC", out total); String filename = "COMPROBANTE " + ddl_tipcom_c.SelectedItem.Text + " " + String.Format("{0:dd/MM/yyyy}", System.DateTime.Today) + ".xls"; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename)); Response.Clear(); var output = new MemoryStream(); var writer = new StreamWriter(output); HSSFWorkbook xssfworkbook = new HSSFWorkbook(); ISheet sheet = xssfworkbook.CreateSheet("COMPROBANTE"); IFont titleFont = xssfworkbook.CreateFont(); titleFont.FontName = "Calibri"; titleFont.Boldweight = (short)FontBoldWeight.Bold; titleFont.Color = (IndexedColors.Black.Index); titleFont.FontHeightInPoints = 11; ICellStyle styleCabecera = xssfworkbook.CreateCellStyle(); styleCabecera.Alignment = HorizontalAlignment.Center; styleCabecera.VerticalAlignment = VerticalAlignment.Center; styleCabecera.SetFont(titleFont); styleCabecera.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; styleCabecera.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; styleCabecera.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; styleCabecera.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; for (int cl1 = 0; cl1 < 11; cl1++) { sheet.SetColumnWidth(cl1, 150 * 25); } for (int cl = 11; cl <= 21; cl++) { sheet.SetColumnWidth(cl, 300 * 25); } IRow dataHeader = sheet.CreateRow(0); ICell dataCellH; for (int h = 0; h < dt.Columns.Count; h++) { dataCellH = dataHeader.CreateCell(h); dataCellH.SetCellValue(dt.Columns[h].ToString()); dataCellH.CellStyle = styleCabecera; dataCellH.CellStyle.WrapText = true; } for (int r = 0; r < dt.Rows.Count; r++) { IRow dataBody = sheet.CreateRow(1 + r); for (int c = 0; c < dt.Columns.Count; c++) { dataBody.CreateCell(c, CellType.String).SetCellValue(dt.Rows[r][c].ToString()); } } xssfworkbook.Write(output); writer.Flush(); dt.Rows.Clear(); dt.Columns.Clear(); dt.Clear(); Response.BinaryWrite(output.GetBuffer()); Response.End(); }