Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have used the function below to create a template for excel 2003(xls) file. I am able to generate the file and view its contents. However when I press my arrow keys , on reaching the final cell on screen the sheet wont scroll, rather the cursor moves to new cell without being visible. I searched on the net and found problems opposite to this. I have used the EPPLUS to generate an xlsx file which doesn't have this problem .Can any body please suggest of an attribute o a way which I could use to implement normal scroll functionality of the excel. If you require any more details please mention in the comments.


C#
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);

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


        sb.AppendFormat(@" </Styles>{0}", Environment.NewLine);
        sb.Append(@"{0}\r\n</Workbook>");
        return sb.ToString();
    }
Posted
Comments
Maciej Los 13-Apr-15 9:01am    
Excel file is not simple text file. I do not advice to use StringBuilder to create Excel template. Is that ASP.NET or windows form application?
Kalla Ganesh 14-Apr-15 0:34am    
Asp.net application
Kalla Ganesh 14-Apr-15 0:36am    
What I mean to say is that the cursor actually moves to a new location, but doesn't stay on screen. It goes out of view, and the page doesn't scroll to adjust this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900