Format cell size in . csv files

Asked

Viewed 111 times

1

Gero esse csv

public ActionResult geraExcel()
        {
            List<vwFinancingReportViewModel> lista = new List<vwFinancingReportViewModel>();
            lista = dadosPlanilha();

            StringBuilder sb = new StringBuilder();
            sb.Append("Status;Nro.Pessoal;Nome Completo;Grade;Nro.Solicitação;Data Financiamento;" + 
                "Ano Fabric.;Modelo;Chassi;Valor Bem;Valor Financiado;Status Solicitação;Status Pagamento;" +
                "Valor Parcela;Juros;ReembolsoKM;Reembolso Depreciação;Sequencia;Data Pagamento\r\n");
            foreach(var item in lista)
            {
                sb.Append(item.valuepayment.ToString() + ";" + item.chassi.ToString() + ";" + item.solicitationid.ToString() + "\r\n");

            }
            //sb.Append("Eduardo;11111\r\n");
            //sb.Append("Coutinho;22222\r\n");

            HttpContext.Response.Clear();
            HttpContext.Response.AddHeader("content-disposition", string.Format("attachment;filename=" + DateTime.Now.ToString("yyyyMMdd") + "ReportFinanciamentoRH.csv"));

            HttpContext.Response.ContentType = "application/CSV";
            HttpContext.Response.ContentEncoding = System.Text.Encoding.Default;

            HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            HttpContext.Response.Write(sb.ToString());

            HttpContext.Response.End();

            return null;
        }

I can increase the size of the cell, so that when opening the file via excel, the name (header) of the columns can appear correctly, without the need to enlarge the cell?

  • 4

    a csv file is a file Plain text, Without formatting, it wouldn’t make much sense to format the size of the cell. Maybe if you increase the size of the header text the column increases tb, but again, it doesn’t make sense, because a csv file is not for reading, but for importing

  • I get it, @Ricardopunctual, but a lot of people use it to export spreadsheets and so on. I tried making a spreadsheet and I’m not getting it, so I switched to csv, just to buy time.

  • Yes, as export file, importing it in Excel will be able to format normally. Tried to add spaces in column name in header?

  • Yeah, I have big names, like Full Name and yet it comes in the default excel size. But I don’t see this as a serious problem. Anyway, obgd by tip.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.