0

when I generate a report using asp.net with c# into xls format it is initially approximately 32 MB. But when i open it using excel and save it as xls format providing different name, the size is reduced to approximately 10 KB, but the data and the formatting isnt lost both the file appear identical in Excel.

why is that so?

How could i initially generate a report of smaller file size?

32MB File Size contains data like

<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>  

10MB file contains some random functions as in

https://gist.github.com/anonymous/f979595cf169575aea3b94d9abc3b525

Thomas
  • 1
  • 1
  • 2
    You appear to be generating HTML that Excel can understand, not a native Excel file. Re-saving it produces a correctly formatted file (xml or binary) that will be significantly smaller (because the binary format is very efficient and the xml format is compressed) – Alex K. Feb 02 '17 at 13:34
  • Thanks Alex, I am using following code to generate the excel sheet, can you give the suggestion to improve the codings https://gist.github.com/anonymous/913e9ee9127b775bd1cd8ac52c59019a – Thomas Feb 02 '17 at 13:52
  • 1
    Creating a proper Excel file is the best way: http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c-sharp – Alex K. Feb 02 '17 at 14:03

1 Answers1

0

You can try to create xlsx files. It should has smaller size. Or if you stuck with coding, you can try to use report generators, like a Crystal or FastReport.Net (it has an exports in xls and xlsx too).

xaml
  • 172
  • 9