Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

The below code which was working good for excel export but i need sheet wise set print preview and pages as landscape set.

any one please help me on this...


public static string getWorkbookTemplate()
{
  StringBuilder 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=""Times New Roman"" x:Family=""Swiss"" ss:Size=""10"" 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"">{0}", Environment.NewLine);
    sb.AppendFormat(@" <Alignment ss:Horizontal=""Left"" ss:Vertical=""Top"" ss:ReadingOrder=""LeftToRight""/>{0}", Environment.NewLine);
    sb.AppendFormat(@" <Borders>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Border ss:Position=""Bottom"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Border ss:Position=""Left"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Border ss:Position=""Right"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Border ss:Position=""Top"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    sb.AppendFormat(@" </Borders>{0}", Environment.NewLine);
    sb.AppendFormat(@" <Font x:CharSet=""1"" ss:Size=""10"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    sb.AppendFormat(@" <Interior ss:Color=""#D8D8D8"" ss:Pattern=""Solid""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <page ss:PageOrientation=""landscape"" />{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=""s22"">{0}", Environment.NewLine);
    sb.AppendFormat(@" <Borders>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Border ss:Position=""Bottom"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Border ss:Position=""Left"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Border ss:Position=""Right"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    sb.AppendFormat(@"   <Border ss:Position=""Top"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine);
    sb.AppendFormat(@" </Borders>{0}", Environment.NewLine);
    sb.AppendFormat(@"    <page ss:PageOrientation=""landscape"" />{0}", Environment.NewLine);
    sb.AppendFormat(@" </Style>{0}", Environment.NewLine);
    sb.AppendFormat(@" </Styles>{0}", Environment.NewLine);
    sb.AppendFormat(@" <WorksheetOptions>{0}", Environment.NewLine);
    sb.AppendFormat(@" <FitToPage/>{0}", Environment.NewLine);
    sb.AppendFormat(@" <Print x:FitWidth=""1"" x:FitHeight=""1000"" x:ValidPrinterInfo=""""/>{0}", Environment.NewLine);
    sb.AppendFormat(@" </WorksheetOptions>{0}", Environment.NewLine);

    sb.Append(@"{0}\r\n</Workbook>");
    return sb.ToString();
}
Posted
Updated 23-Jan-13 5:07am
v4

1 solution

Hi friends,

the below code works for complete that page print setting and landscape.

sw.Write("\r\n\r\n<worksheetoptions xmlns="\"urn:schemas-microsoft-com:office:excel\""><pagesetup><layout x:orientation="\"Landscape\"/" xmlns:x="#unknown"><pagemargins x:bottom="\"0.5\"" x:left="\"0.5\"" x:right="\"0.5\"" x:top="\"0.5\"/"></pagemargins></layout></pagesetup><fittopage /><print x:fitwidth="\"1\"" x:fitheight="\"1000\"" xmlns:x="#unknown" /></worksheetoptions>");


Thanks to all! :)
 
Share this answer
 

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