Click here to Skip to main content
11,581,353 members (57,426 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 22-Jan-13 0:50am
Edited 23-Jan-13 5:07am
v4

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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! Smile | :)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 260
1 Sergey Alexandrovich Kryukov 155
2 virusstorm 114
3 Frankie-C 105
4 RyanDev 84
0 OriginalGriff 1,183
1 Sergey Alexandrovich Kryukov 825
2 Abhinav S 597
3 F-ES Sitecore 500
4 Suvendu Shekhar Giri 433


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100