POIexcel文件中的部分内容有问题。已修复的记录: /xl/styles.xml 部分的 格式 (样式)

在这里插入图片描述
导出的问题是:
在这里插入图片描述
网上大多是这样这样的处理方式:
在获得 workbook.Write(ms) 生成的 MemoryStream 后,使用了 ms.GetBuffer() 返回文件内容,导致生成的 Excel 文件结尾处有大量的 00(空字节),改为 ms.ToArray() 即可得到正常的文件
我的代码是:

                MemoryStream stream = new MemoryStream();
                workbook.Write(stream);
                byte[] buf = stream.ToArray();
                //保存为Excel文件  
                try
                {
                    using (FileStream fs = new FileStream(saveFileName, FileMode.Create, FileAccess.Write))
                    {
                        fs.Write(buf, 0, buf.Length);
                        fs.Flush();
                        fs.Close();
                        stream.Close();
                        stream.Dispose();
                        fileSaved = true;
                    }
                    MessageBox.Show("数据导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("导出失败!提示:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                } 

我的问题是:
自定义格式错误
在这里插入图片描述

修改正常就OK了。

Utility to identify builtin formats. Now can handle user defined data formats also. The following is a list of the formats as returned by this class.
0, "General"
1, "0"
2, "0.00"
3, "#,##0"
4, "#,##0.00"
5, "($#,##0_);($#,##0)"
6, "($#,##0_);[Red]($#,##0)"
7, "($#,##0.00);($#,##0.00)"
8, "($#,##0.00_);[Red]($#,##0.00)"
9, "0%"
0xa, "0.00%"
0xb, "0.00E+00"
0xc, "# ?/?"
0xd, "# ??/??"
0xe, "m/d/yy"
0xf, "d-mmm-yy"
0x10, "d-mmm"
0x11, "mmm-yy"
0x12, "h:mm AM/PM"
0x13, "h:mm:ss AM/PM"
0x14, "h:mm"
0x15, "h:mm:ss"
0x16, "m/d/yy h:mm"
// 0x17 - 0x24 reserved for international and undocumented 0x25, "(#,##0_);(#,##0)"

0x26, "(#,##0_);[Red](#,##0)"

0x27, "(#,##0.00_);(#,##0.00)"

0x28, "(#,##0.00_);[Red](#,##0.00)"

0x29, "_(*#,##0_);_(*(#,##0);_(* \"-\"_);_(@_)"

0x2a, "_($*#,##0_);_($*(#,##0);_($* \"-\"_);_(@_)"

0x2b, "_(*#,##0.00_);_(*(#,##0.00);_(*\"-\"??_);_(@_)"

0x2c, "_($*#,##0.00_);_($*(#,##0.00);_($*\"-\"??_);_(@_)"

0x2d, "mm:ss"

0x2e, "[h]:mm:ss"

0x2f, "mm:ss.0"

0x30, "##0.0E+0"

0x31, "@" - This is text format.

0x31 "text" - Alias for "@"

参考时局:
https://www.cnblogs.com/cndavy/archive/2012/09/24/2700109.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值