我使用了一个函数来生成xls。但是生成的 xls sheet 没有带方向键的滚动功能

I have used a function to generate xls. But the generated xls sheet doesn't have scroll functionality with arrow keys

您好,我使用以下函数生成了一个 excel 工作簿模板,稍后我用它来生成一个 excel xls 文件并将其写入 response(asp.net).

private static string getWorkbookTemplate()
{
    var sb = new StringBuilder(818);
    sb.AppendFormat(@"<?xml version=""1.0""?>{0}", Environment.NewLine);
    sb.AppendFormat(@"<?mso-application progid=""Excel.Sheet""?>{0}", Environment.NewLine);
    sb.AppendFormat(@"<Workbook xmlns=""urn:schemas-microsoft-com:office:spreadsheet""{0}", Environment.NewLine);
    sb.AppendFormat(@" xmlns:o=""urn:schemas-microsoft-com:office:office""{0}", Environment.NewLine);
    sb.AppendFormat(@" xmlns:x=""urn:schemas-microsoft-com:office:excel""{0}", Environment.NewLine);
    sb.AppendFormat(@" xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet""{0}", Environment.NewLine);
    sb.AppendFormat(@" xmlns:html=""http://www.w3.org/TR/REC-html40"">{0}", Environment.NewLine);
    sb.AppendFormat(@" <Styles>{0}", Environment.NewLine);
    sb.AppendFormat(@"  <Style ss:ID=""Default"" ss:Name=""Normal"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Alignment ss:Vertical=""Bottom""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Borders/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Interior/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <NumberFormat/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Protection/>{0}", Environment.NewLine);
    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
    sb.AppendFormat(@"  <Style ss:ID=""s62"" ss:Name=""Header"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#FFFFFF""{0}", Environment.NewLine);
    sb.AppendFormat(@"    ss:Bold=""1""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Interior ss:Color=""#5A0B0E""  ss:Pattern=""Solid""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
    sb.AppendFormat(@"  <Style ss:ID=""s63"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <NumberFormat ss:Format=""Short Date""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
    sb.AppendFormat(@"  <Style ss:ID=""s64"" ss:Name=""RowArea"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#FFFFFF""{0}", Environment.NewLine);
    sb.AppendFormat(@"    ss:Bold=""1""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Interior ss:Color=""#723B3E""  ss:Pattern=""Solid""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
    sb.AppendFormat(@"  <Style ss:ID=""s65"" ss:Name=""SummarySection"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    //sb.AppendFormat(@"    ss:Bold=""0""/>{0}", Environment.NewLine);//
    sb.AppendFormat(@"   <Interior ss:Color=""#FFE5E6""  ss:Pattern=""Solid""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
    sb.AppendFormat(@"  <Style ss:ID=""s66"" ss:Name=""TotalRow"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11""{0}", Environment.NewLine);
    sb.AppendFormat(@"    ss:Bold=""1""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Interior ss:Color=""#FFE5E6""  ss:Pattern=""Solid""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
    sb.AppendFormat(@"  <Style ss:ID=""s67"" ss:Name=""PosValues"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#008000""/>{0}", Environment.NewLine);
    // sb.AppendFormat(@"    ss:Bold=""1""/>{0}", Environment.NewLine);//
    sb.AppendFormat(@"   <Interior ss:Color=""#FFE5E6""  ss:Pattern=""Solid""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
    sb.AppendFormat(@"  <Style ss:ID=""s68"" ss:Name=""NegValues"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#A31515""/>{0}", Environment.NewLine);
    //  sb.AppendFormat(@"    ss:Bold=""1""/>{0}", Environment.NewLine);//
    sb.AppendFormat(@"   <Interior ss:Color=""#FFE5E6""  ss:Pattern=""Solid""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);

    //New Style Defined Ganesh
    sb.AppendFormat(@"  <Style ss:ID=""s69"" ss:Name=""TotalRowSummarySection"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#000000"" ss:Bold=""1""/>{0}", Environment.NewLine);
    //sb.AppendFormat(@"    />{0}", Environment.NewLine);//
    sb.AppendFormat(@"   <Interior ss:Color=""#FFE5E6""  ss:Pattern=""Solid""/>{0}", Environment.NewLine);


    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
    sb.AppendFormat(@"  <Style ss:ID=""s70"" ss:Name=""BoldPosValues"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#008000"" ss:Bold=""1""/>{0}", Environment.NewLine);
    //sb.AppendFormat(@"    />{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Interior ss:Color=""#FFE5E6""  ss:Pattern=""Solid""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);

    sb.AppendFormat(@"  <Style ss:ID=""s71"" ss:Name=""BoldNegValues"">{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#A31515"" ss:Bold=""1""/>{0}", Environment.NewLine);
    //sb.AppendFormat(@"    />{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Interior ss:Color=""#FFE5E6""  ss:Pattern=""Solid""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
    //New Style Ends

    sb.AppendFormat(@" </Styles>{0}", Environment.NewLine);
    sb.Append(@"{0}\r\n</Workbook>");
    return sb.ToString();
}

我能够成功生成文件,并且能够在 excel 中打开文件。但是当我使用箭头键浏览单元格时,sheet 仍然停滞不前。即它不会滚动,当我使用鼠标并按下滚动条上的滚动按钮时它会起作用。光标不断移动到新的单元格,我可以在 excel 2007 中看到除了公式栏之外的位置。但是页面不滚动。我使用 EPPlus 创建了另一个没有这个问题的 excel 文件。任何人都可以建议是否可以控制 excel spreadsheet 模式中的滚动。

我发现这个文件实际上存储为电子表格 ML (xml) 文件。这就是我遇到这个问题的原因。如果我将它保存为 2003 xls,那么我就可以使用箭头键进行滚动。而且我还在堆栈溢出上找到了一个答案,建议为了实现这一点,我需要将它发送到可以访问 excel 并且可以生成所需的 excel 文件的服务。我尝试为此使用 WCF,但下载速度非常慢,令人无法接受。所以我用了这个技巧。