Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何把数字导出成文本? #23

Closed
pjy612 opened this issue Jan 16, 2020 · 8 comments
Closed

如何把数字导出成文本? #23

pjy612 opened this issue Jan 16, 2020 · 8 comments
Assignees

Comments

@pjy612
Copy link

pjy612 commented Jan 16, 2020

Format 设置为什么 可以让 单元格 在导出后变成文本。
long 的 总变成 科学计数法
网上查了下 设成 @ 也没有用。。。
还是说最新版已经支持?

@xin-lai
Copy link
Collaborator

xin-lai commented Jan 17, 2020

把你的代码贴上来看看

@pjy612
Copy link
Author

pjy612 commented Jan 17, 2020

[ExcelExporter]
        class LongToStr
        {
            [ExporterHeader("Long",format:"@")]
            public long Long { get; set; }
            [ExporterHeader("String")]
            public String Str => Long.ToString();
        }

List<LongToStr> list = new List<LongToStr>();
            for (long i = 9223372036854775797L; i > 9223372036854775787L; i--)
            {
                list.Add(new LongToStr(){Long = i});
            }
            ExcelExporter exporter = new ExcelExporter();
            exporter.Export("test.xlsx", list);

image

我希望能让数字显示成字符串 = =。有什么方法吗?

@xin-lai
Copy link
Collaborator

xin-lai commented Jan 17, 2020

#,##0

@xin-lai
Copy link
Collaborator

xin-lai commented Jan 17, 2020

[ExporterHeader(DisplayName = "长数值", Format = "#,##0")]

@pjy612
Copy link
Author

pjy612 commented Jan 17, 2020

[ExporterHeader(DisplayName = "长数值", Format = "#,##0")]

###0
#0
#
0

我刚都试了,然后 失真了。。。
image

Long String
9223372036854780000 9223372036854775797
9223372036854780000 9223372036854775796
9223372036854780000 9223372036854775795

@pjy612
Copy link
Author

pjy612 commented Jan 17, 2020

如果暂不支持的话 将来能不能在 Attr 里面加个 type 什么的 让字段当字符串 处理

@xin-lai
Copy link
Collaborator

xin-lai commented Jan 17, 2020

等我有空测试一下。
可以考虑。

@xin-lai
Copy link
Collaborator

xin-lai commented Jan 18, 2020

设置为“#”是OK的,但是如果数值过长的话,在写入的时候已经存在数据丢失,因此无论你如何设置格式,都是不对的。哪怕再将其转为文本类型。
基于以上情形,建议如下:

  • 将DTO长数值列设置为string类型
  • 然后使用Select将你的原始List做一个转换再进行导出

后续可以考虑通过特性处理,或者提供数据筛选器。

@xin-lai xin-lai self-assigned this Jan 18, 2020
@xin-lai xin-lai closed this as completed Feb 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants