title: Export to Excel fails on some machines
body: <p>We are developing a Web application and some of our query results need to be Exported to Excel. We are using the following C# code to Export : </p>
  
  <pre><code>System.Web.HttpContext ctx = System.Web.HttpContext.Current;
  CurrentPackingListModel.Voyage.ShipmentDataContext = ShipmentDataContext;
  ctx.Response.Clear();
  string filename = "ApprovalForm.xls";
  ctx.Response.AddHeader("content-disposition", "attachment;filename=" + filename);
  ctx.Response.ContentType = "application/vnd.ms-excel";
  ctx.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
  ctx.Response.Charset = "UTF-8";
  return View("../Packing/_ExportApprovalForm", CurrentPackingListModel);
  </code></pre>
  
  <p>The partial View I am returning to result is as follows : </p>
  
  <pre><code>&lt;body id="body" onload="window.print();"&gt;
      &lt;table&gt;
          &lt;tbody&gt;
              &lt;tr&gt;
                  &lt;td class="table-header" colspan="8"&gt;
                      &lt;div style="width: 100%"&gt;
                          &lt;div class="lleft"&gt;
                              @* &lt;img id="imgLogo" src="~/Images/myLogo.png" /&gt;*@
                          &lt;/div&gt;
                          &lt;div class="baslik"&gt;Approval Packing List Form&lt;/div&gt;
                          &lt;div style="float: right;"&gt;@DateTime.Now.ToString("MM.dd.yyyy")&lt;/div&gt;
                      &lt;/div&gt;
  
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan="6"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="line-header"&gt;@Html.DisplayNameFor(x =&gt; x.ID)&lt;/td&gt;
                  &lt;td&gt;: @Html.HiddenFor(x =&gt; x.ID)@Html.DisplayFor(x =&gt; x.ID)&lt;/td&gt;
  
                  &lt;td class="line-header" style="width: 165px;"&gt;@Html.DisplayNameFor(x =&gt; x.Voyage.StartDate)&lt;/td&gt;
                  &lt;td&gt;: @Html.DisplayFor(x =&gt; x.Voyage.StartDate)&lt;/td&gt;
  
                  &lt;td class="line-header"&gt;@Html.DisplayNameFor(x =&gt; x.Voyage.VesselID)&lt;/td&gt;
                  &lt;td&gt;: @Html.DisplayFor(x =&gt; x.Voyage.VesselText)
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="line-header"&gt;@Html.DisplayNameFor(x =&gt; x.Voyage.Id)&lt;/td&gt;
                  &lt;td&gt;: @Html.DisplayFor(x =&gt; x.Voyage.Id)&lt;/td&gt;
  
                  &lt;td class="line-header" style="width: 165px;"&gt;@Html.DisplayNameFor(x =&gt; x.Voyage.EndDate)&lt;/td&gt;
                  &lt;td&gt;: @Html.DisplayFor(x =&gt; x.Voyage.EndDate)&lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;tr&gt;
                  &lt;td colspan="6"&gt;
                      &lt;hr /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
  
          &lt;/tbody&gt;
  
      &lt;/table&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td class="line-header" style="width: 160px;"&gt;Approve Personel&lt;/td&gt;
              &lt;td style="border: solid 1px; width: 180px;"&gt;&lt;/td&gt;
              &lt;td class="line-header"&gt;Discharge Port&lt;/td&gt;
              &lt;td style="border: solid 1px; width: 180px;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="line-header"&gt;Approve Date&lt;/td&gt;
              &lt;td style="border: solid 1px;"&gt;&lt;/td&gt;
              &lt;td class="line-header"&gt;Terminal&lt;/td&gt;
              &lt;td style="border: solid 1px;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="line-header"&gt;Signiture&lt;/td&gt;
              &lt;td style="border: solid 1px;"&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  
      @if (Request.QueryString["type"] == "HRC" &amp;&amp; Model.HrcListPrint != null)
      {
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td colspan="10" style="height: 20px;"&gt;
                      &lt;hr /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td style="text-align: center; width: 210mm; font-weight: bold;" colspan="11"&gt;HRC LIST
                  &lt;/td&gt;
              &lt;/tr&gt;
  
          &lt;/table&gt;
          &lt;table class="display dataTable no-footer"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Customer Name&lt;/th&gt;
                      &lt;th&gt;Customer PO No&lt;/th&gt;
                      &lt;th&gt;Ord. ITem No&lt;/th&gt;
                      &lt;th&gt;CM No&lt;/th&gt;
                      &lt;th&gt;Product&lt;/th&gt;
                      &lt;th&gt;Size (T x W inch)&lt;/th&gt;
                      &lt;th&gt;Thickness Tolerance&lt;/th&gt;
                      &lt;th&gt;Qty (tons)&lt;/th&gt;
                      &lt;th&gt;Coil Weight (Lbs)&lt;/th&gt;
                      &lt;th&gt;Destination Port&lt;/th&gt;
                      &lt;th&gt;Barcode&lt;/th&gt;
                      &lt;th&gt;Heat No&lt;/th&gt;
                      &lt;th&gt;Status&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  @foreach (MedTrade.Apollo.Shared.Models.Shipment.PackingListDetailModel item in Model.HrcListPrint)
                  {
                      &lt;tr&gt;
                          &lt;td&gt;@item.CustomerName&lt;/td&gt;
                          &lt;td&gt;@item.CustomerPurchaseOrderNumber&lt;/td&gt;
                          &lt;td&gt;@String.Format("'{0}'", item.OrderItemText)&lt;/td&gt;
                          &lt;td&gt;@item.CMNO&lt;/td&gt;
                          &lt;td&gt;@item.ProductStandartName&lt;/td&gt;
                          &lt;td&gt;@item.ProductProperty&lt;/td&gt;
                          &lt;td&gt;@item.ThicknessToleranceType&lt;/td&gt;
                          &lt;td&gt;@((item.Quantity / 1000).ToString("N3"))&lt;/td&gt;
                          &lt;td&gt;@item.CoilWeight.ToString("N0")&lt;/td&gt;
                          &lt;td&gt;@item.DischargePortTanim&lt;/td&gt;
                          &lt;td&gt;@item.BarcodeNo&lt;/td&gt;
                          &lt;td&gt;@item.HeatNo&lt;/td&gt;
                          &lt;td&gt;@item.StatusText&lt;/td&gt;
                      &lt;/tr&gt;    
                  }
  
              &lt;/tbody&gt;
          &lt;/table&gt;
      }
  
      @if (Request.QueryString["type"] == "Rebar" &amp;&amp; Model.RebarListPrint != null)
      {
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td colspan="10" style="height: 20px;"&gt;
                      &lt;hr /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td style="text-align: center; width: 210mm; font-weight: bold;" colspan="10"&gt;REBAR LIST
                  &lt;/td&gt;
              &lt;/tr&gt;
  
          &lt;/table&gt;
  
          &lt;table class="display dataTable no-footer"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Customer Name&lt;/th&gt;
                      &lt;th&gt;Customer PO No&lt;/th&gt;
                      &lt;th&gt;Ord. ITem No&lt;/th&gt;
                      &lt;th&gt;CM No&lt;/th&gt;
                      &lt;th&gt;Product&lt;/th&gt;
                      &lt;th&gt;Size (D x L inch)&lt;/th&gt;
                      @if (Model.SearchCriteria.ViewType == ViewType.Group)
                      {
                          &lt;th&gt;Qty (tons) / # of bundles&lt;/th&gt;
                      }
                      else
                      {
                          &lt;th&gt;Quantity (Tons)&lt;/th&gt;
                      }
                      &lt;th&gt;Bundle Weight (Lbs)&lt;/th&gt;
                      &lt;th&gt;Destination Port&lt;/th&gt;
                      @if (Model.SearchCriteria.ViewType == ViewType.Detail)
                      {
                          &lt;th&gt;Barcode&lt;/th&gt;
                      }
                      &lt;th&gt;Heat No&lt;/th&gt;
                      &lt;th&gt;Status&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  @foreach (MedTrade.Apollo.Shared.Models.Shipment.PackingListDetailModel item in Model.RebarListPrint)
                  {
                      &lt;tr&gt;
                          &lt;td&gt;@item.CustomerName&lt;/td&gt;
                          &lt;td&gt;@item.CustomerPurchaseOrderNumber&lt;/td&gt;
                          &lt;td&gt;@String.Format("'{0}'", item.OrderItemText)&lt;/td&gt;
                          &lt;td&gt;@item.CMNO&lt;/td&gt;
                          &lt;td&gt;@item.ProductStandartName&lt;/td&gt;
                          &lt;td&gt;@item.ProductProperty&lt;/td&gt;
                          @if (Model.SearchCriteria.ViewType == ViewType.Group)
                          {
                              &lt;td&gt;@((item.Quantity / 1000).ToString("N3")) / @item.Count&lt;/td&gt;
                          }
                          else
                          {
                              &lt;td&gt;@((item.Quantity / 1000).ToString("N3"))&lt;/td&gt;
                          }
                          &lt;td&gt;@item.BundleWeight.ToString("N0")&lt;/td&gt;
                          &lt;td&gt;@item.DischargePortTanim&lt;/td&gt;
                          @if (Model.SearchCriteria.ViewType == ViewType.Detail)
                          {
                              &lt;td&gt;@item.BarcodeNo&lt;/td&gt;
                          }
                          &lt;td&gt;@item.HeatNo&lt;/td&gt;
                          &lt;td&gt;@item.StatusText&lt;/td&gt;
                      &lt;/tr&gt;    
                  }
  
              &lt;/tbody&gt;
          &lt;/table&gt;        
      }
  
  &lt;/body&gt;
  </code></pre>
  
  <p>But export to Excel works on some machines, but not others. This started to happen only recently.</p>
  
  <p>Is there a possible solution to fix this without re-writing the whole Exporting functionality?</p>