Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 系统生成的xls报告大于修改后的报告_C#_Asp.net_Excel_Xls - Fatal编程技术网

C# 系统生成的xls报告大于修改后的报告

C# 系统生成的xls报告大于修改后的报告,c#,asp.net,excel,xls,C#,Asp.net,Excel,Xls,当我使用asp.net和c#生成xls格式的报告时,最初大约是32MB。但当我使用excel打开它并将其保存为提供不同名称的xls格式时,大小会减小到大约10 KB,但数据和格式并没有丢失。这两个文件在excel中看起来完全相同 为什么会这样 我最初如何生成文件大小较小的报告 32MB文件大小包含以下数据 <tr height="20" style='height:15.00pt;'> <td class="xl66" height="20" style='height

当我使用asp.net和c#生成xls格式的报告时,最初大约是32MB。但当我使用excel打开它并将其保存为提供不同名称的xls格式时,大小会减小到大约10 KB,但数据和格式并没有丢失。这两个文件在excel中看起来完全相同

为什么会这样

我最初如何生成文件大小较小的报告

32MB文件大小包含以下数据

<tr height="20" style='height:15.00pt;'>
    <td class="xl66" height="20" style='height:15.00pt;' x:str>PR</td>
    <td class="xl72" x:str>00923</td>
    <td class="xl66" align="right" x:num>2016</td>
    <td class="xl66" align="right" x:num>25</td>
    <td class="xl66" align="right" x:num>89</td>
    <td class="xl66" align="right" x:num>89</td>
    <td class="xl66" align="right" x:num>45</td>
    <td class="xl66" align="right" x:num>52</td>
    <td class="xl66" align="right" x:num>2316</td>
    <td class="xl73" align="right" x:num="0.87">87%</td>
    <td class="xl73" align="right" x:num="1.e-002">1%</td>
    <td class="xl73" align="right" x:num="4.0000000000000001e-002">4%</td>
    <td class="xl73" align="right" x:num="4.0000000000000001e-002">4%</td>
    <td class="xl73" align="right" x:num="2.e-002">2%</td>
    <td class="xl73" align="right" x:num="2.e-002">2%</td>
    <td class="xl73" align="right" x:num="0.92000000000000004">92%</td>
</tr>  

公共关系
00923
2016
25
89
89
45
52
2316
87%
1%
4%
4%
2%
2%
92%
10MB文件包含一些随机函数,如中所示


您可以尝试创建xlsx文件。它应该有更小的尺寸。
或者,如果您坚持使用编码,您可以尝试使用报表生成器,如Crystal或FastReport.Net(它也有xls和xlsx格式的导出)。

您似乎正在生成Excel可以理解的HTML,而不是本机Excel文件。重新保存它会生成一个格式正确的文件(xml或二进制),该文件将显著更小(因为二进制格式非常有效,xml格式是压缩的)。谢谢Alex,我正在使用以下代码生成excel工作表,您能给出改进编码的建议吗创建一个适当的excel文件是最好的方法: