excel问题中的数字格式 [英] Number format in excel issue

查看:87
本文介绍了excel问题中的数字格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想将列表转换为excel并将其返回给浏览器。我已经完成了这个过程。但问题是excel中有一列默认收缩。我有一个信用卡号列,我把它作为一个字符串,仍然缩小。 (列中16位数)。



请告诉我如何解决这个问题。



我尝试了什么:



Hi All,

I want to convert a list to excel and return that to the browser. I have finished the process. But the issue is that there is a column in the excel that shrink by default. I have a credit card number column, i have taken that as a string, still that shrinks. (16 digit in the column).

Kindly let me know how can i solve this one.

What I have tried:

var reducedList = FinReportClassList.Select(e => new { e.ConfNo, e.FIleNo, e.Guest, e.CardNo, e.VCAStatus, e.Txn, e.Post, e.Supplier, e.State, e.Country, e.OrgAmount, e.orgcuuactual, e.BillAmount, e.BillCurrency, e.UserName }).ToList();
                         Response.ClearContent();
                         Response.AddHeader("content-disposition", "attachment;filename=VCA-Transactions.xls");
                         Response.AddHeader("Content-Type", "application/vnd.ms-excel");
                         WriteTsv(reducedList, Response.Output);
                         Response.End();


         public void WriteTsv<t>(IEnumerable<t> data, TextWriter output)
         {
             PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));


             foreach (PropertyDescriptor prop in props)
             {                 
                 if(prop.DisplayName=="ConfNo")
                 {
                     output.Write("Confirmation No"); // header
                     output.Write("\t");  
                 }
                 if (prop.DisplayName == "FIleNo")
                 {
                     output.Write("FIle No"); // header
                     output.Write("\t");  
                 }
                 if (prop.DisplayName == "Guest")
                 {
                     output.Write("Guest Name"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "CardNo")
                 {
                     output.Write("Card No"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "VCAStatus")
                 {
                     output.Write("Card Status"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "Txn")
                 {
                     output.Write("Txn Date"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "Post")
                 {
                     output.Write("Post Date"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "Supplier")
                 {
                     output.Write("Supplier Name"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "State")
                 {
                     output.Write("Supplier State"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "Country")
                 {
                     output.Write("Supplier Country"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "OrgAmount")
                 {
                     output.Write("Swipped Amount"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "orgcuuactual")
                 {
                     output.Write("Swipped Currency"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "BillAmount")
                 {
                     output.Write("Bill Amount"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "BillCurrency")
                 {
                     output.Write("Bill Currency"); // header
                     output.Write("\t");
                 }
                 if (prop.DisplayName == "UserName")
                 {
                     output.Write("Agent"); // header
                     output.Write("\t");
                 }  
             }
             output.WriteLine();
             foreach (T item in data)
             {
                 foreach (PropertyDescriptor prop in props)
                 {
                     output.Write(prop.Converter.ConvertToString(
                          prop.GetValue(item)));
                     output.Write("\t");
                 }
                 output.WriteLine();
             }
         }

推荐答案

您的代码似乎以CSV格式写入文件,而不是excel。

所以你不能控制列宽并且有默认宽度,而不是收缩。



为了控制excel之类的东西,比如格式化,你必须使用像xlsx或xml这样的excel格式。找到符合您需求的库。
your code seems to write the file in CSV format which is not excel.
So you can't control column width and have default width, not a shrink.

In order to control excel things like formatting, you must use an excel format like xlsx or xml. Find the library that will fit your needs.


这篇关于excel问题中的数字格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆