title: Trouble reading excel file C#
body: <p>I need help. I made a form in C# that send an excel file, which is read and written in a div element after. The problem is the program writes wrong characters. I have tried to encode the output in UTF8, but the program returns something like this: </p>
  
  <p>PK!?z??x [Content_Types].xml ?(???J?0????V?lDd?.?^???19]??$?ds{{O???Â?4?9??~I?o8^?:Y??????K?H?<em>3????9?g   a???@?6?l?]d?EZ(mQT??°v C?A(,B??8f?????,F?~? ??????q?G??????#?2g?Fv???9?RxPo?SRt?]??ZNJ?2o?A?????)?&lt;\????;u$>Tp???p?4???(}??[?s?|}??PK!?U0#?L_rels/.rels ?(????N?0??H?C???nH???LH?!T?$????$@????Jc??????[???iTb/Nú(A?3b{?jx??V?b"gi??aW??l_x???b?????????#b4O??r??0Q?ah??e??=??P-????3{??Ä?C"$?i;?_???!?4jw??K? ?c?xJ????????\s</em>&amp;   A@??M?b????2??yFRx7?"? E?2??&amp;le?V[<em>I0M?????   ?3??[???z!db????????!g??:I??1???*@K/?A??+[WW?fN??Z??o?r??<code>|?jd?hT ???+;%</code>j?????z??p??V?g??Q?&lt;????[k?>???s???4[?.?????Fm????? ???Fg??]??d??????z??P?hz?????s?%d??J??7j9|??l(?K???T-??? dX??YF&amp;8??a??G?c?]???bx{?Y?C|????U??8?B?f?5???|????é?I?B?? ?º??z~???O?OQ?J???K?9? ?@\fU6C?=???C???!?> ? ?yn??? 'U,?8a??oaW)9???????HG?q?)?h??? ?M??2?l??H??A?[?s???1N?*???}O@?b??U|????!8]?{?x?>?????z???S??I&amp;?T%0??SP?V?!????PK!???m?xl/worksheets/sheet2.xml??Mk?0???????liZ??X?1?qv%1??<code>?k??tz?M???z_y??y'~ &amp;????,????????WR$??rI.??-?ujH0!?B?D?T?dZ?:e?A?J??k?46*ut5\?N???Nym?&lt;???5?D?????4????]:?9?u\o?+??cDi?????? u?X?nt??=$'xoMA5e?S?AO5O?D1i&gt;?,+?m?B&gt;????s?,l?X?^???? ?????y??-?R'xB?m+jy??? j?q???MK|z?jzQ?j??d?Mg??1??4???^ullH?A=t?K??,+?m?B&gt;????s?,l?X?^???? ?????y??-?R'xB?m+jy??? j?q???MK|z?jzQ?j??d?Mg??1??4???^ullH?A=t?K???iq???0(4|??h? ????h?????H?+??ejR]q?5"??6D??%????5n?a?B??????V?C?jG??MN?$6?"?U??^?'O?2?? ?h??zy#_??QNK1?@???y?PJ?d?=?????,??A?P  ?C?;?@???¹??????o(}???S?\ ??(?3\UK???%????#8?????Q??w?m????B??%TF?K???z???v'??r"S????&amp;?2???ON+?_?&amp;P\1??????'?Y??3P??\???La?? ?  ?.=zP%=o???(??+H?sH?Ep???m???-sm???</code>8 ???"?yY????/?J^?k?5?v???c?m?t?:F"}?????~\?h?W?Y???xr??pL\?] ??P???Ly?????O</em>???E[? ?-i?W?$?lEL????? ??? ???vp)?pU    G???Rq~?W5s?N???PK!r?VDxl/sharedStrings.xmll??n?0???Q?k??m<em>7HE? p?Y??#??RM???G???q?<code>?5??SN?U?gs????NC????3F??????!??/???@k??V???9???'9?z6?????qZc??H?y??A??4CO???Na?/?x??EuI?@?. L??( ????6I????????+??E6[O    i????f?dk@?lR?????Q?????y????9???H?gO˜o|?q?7*?x?XO?&gt;?U-x]???L@?N7??t??K??&amp;?x?o?????T?</code>????8qG??ka??N?F?B{? ?? ???PK!??H?H? xl/styles.xml??M??0?????#?M?I???d ?RH ?</em>??????i???v??=??k4=zg4r??J?N?X?U???#?r]pU%??>YGUA?V,?gf?c??Cl?Y??1??l????+Bl~d??????RILMElm-??$???H??  +??DR???A?eM?p??ca$??s???R???v7y??&lt;7???MGtY?U?$K?4.?r?Qjh??U?<em>?K??G????NT?g?I?Zh?T?uE%?#6T??>????s??+?'9?????????GCu3</em>? ?????\d????]z?F? ?;0???8?z\i,X?@????N??=h??i\pZiE??????3!v??~?w?D???t?E??M}.&amp;$2?=??x?-?g??????w??????A@?th?p\???Y???????~?Rv?D?J??|????72???v"?W????????Z?b??<code>D??   ??????&gt;eQ??</code>????|? ??z??an??? ???Q??????????|@?[u?1T?@{?IB??U??@??8???:t:?=e??{??<code>l?&amp;i?.F?O??????K??*s?)??????J???|o zd?K????eS???/%????s[x?+??" 1i_?g????????8e2?iFo??6s?6v?Y?O??????2?g_????PK!r?\?8docProps/app.xml ?(????n?0???????@V1?r?I{?d:?H????f?m#?????H??????? Z??S,?tRH???m)7?n?K?dceC?P???3o??UN d?-"?rG?,?B????  ??:?%N?V????;?!???;G?XAu?&lt;??q??kM??:&gt;|?6?C??,??w9a?I|&lt;:Z?E?tkp???d ??^;??Mm?V??^???&gt;??--Zp??@???6??E?pJ???m$?????C???2}?(*????!i?}???#???y???ucg0?pM????+?????1x?0</code><em>P?c?g?n???9?</em>????????l?%8o????;???:?^??s?L?w6n?:??+to?i?fz;)?_?????????PK!?(W??xl/calcChain.xmlt?? ?0????^????|}???m???7"?M _??9)?O??}h???3`h??Z[?]/?????v?0???N %?:7???l???8?A#??uhirw??H??y?</p>
  
  <p>My code behind is the next:</p>
  
  <pre><code>HttpPostedFile file = Request.Files["myFile"];
  
  if (file != null &amp;&amp; file.ContentLength &gt; 0 &amp;&amp; (Path.GetExtension(file.FileName) == ".xlsx" || Path.GetExtension(file.FileName) == ".xls"))
          {
              StreamReader reader = null;
              StringBuilder data = new StringBuilder();
              string value = "";
  
              CultureInfo cultureSp;
              Encoding encodingSp;
              cultureSp = CultureInfo.GetCultureInfo("es-ES");
              encodingSp = Encoding.GetEncoding(cultureSp.TextInfo.ANSICodePage);
  
              using (reader = new StreamReader(file.InputStream))
              {
                  while ((value = reader.ReadLine()) != null)
                  {
                      data.AppendLine(value); 
                  }
              }
              escribirExcel.InnerHtml = encodingSp.GetString(Encoding.Default.GetBytes(data.ToString()));
  
          }
          else
              escribirExcel.InnerHtml = "ERROR";
  
      }        
  </code></pre>
  
  <p>Thanks.</p>