Exemplo n.º 1
0
        public static void ExportToCsv(DataTable dtReport, string delimiter, bool hearder, HtmlStreamAdapter streamAdp)
        {
            if (hearder)
            {
                StringBuilder stHeader = new StringBuilder();
                foreach (DataColumn col in dtReport.Columns)
                {

                    string columnName = col.ToString();
                    stHeader.Append(delimiter);
                    stHeader.Append(columnName);

                }

                string headerLine = stHeader.ToString().Substring(1);
                streamAdp.WriteLine(headerLine);
            }

            foreach (DataRow r in dtReport.Rows)
            {

                StringBuilder stRow = new StringBuilder();
                foreach (DataColumn col in dtReport.Columns)
                {
                    //appExcel.Cells[i, j] = r[j - 1].ToString();
                    stRow.Append(delimiter);
                    stRow.Append(r[col.ColumnName].ToString().Replace(delimiter, " ").Replace("\n", " "));
                }

                string strRow = stRow.ToString().Substring(1);
                streamAdp.WriteLine(strRow);

            }
        }
Exemplo n.º 2
0
        protected void btnGenerarReporte_Click(object sender, EventArgs e)
        {
            if (this.IsValid)
            {

                try
                {
                    DateTime fechaDesde = DateTime.MinValue;
                    DateTime fechaHasta = DateTime.MaxValue;

                    if(this.txtFechaDesde.Text.Trim()!=string.Empty)
                        DateTime.TryParse(this.txtFechaDesde.Text.Trim(), out fechaDesde);

                    if(this.txtFechaHasta.Text.Trim()!=string.Empty)
                        DateTime.TryParse(this.txtFechaHasta.Text.Trim(), out fechaHasta);

                    DataTable dtReporte = ReporteCasos.GetReporteCasos(fechaDesde, fechaHasta);

                    if (dtReporte.Rows.Count > 0)
                    {
                        this.ClearControls();
                        HtmlStreamAdapter h = new HtmlStreamAdapter(GetFileName(fechaDesde, fechaHasta), this.Response);
                        ReporteCasos.ExportToCsv(dtReporte, this.getDelimiter(), true, h);
                        Response.End();
                    }else
                    {
                        this.lblOutMsg.Text = MSG_NON_RECORDS;
                    }

                }
                catch (System.Exception ex)
                {
                    this.cmvRerport.IsValid = false;
                }
            }
        }