Create an Excel doc from HTML: page-orientation

Discussion in 'Software' started by pwillener, Apr 25, 2012.

  1. pwillener

    pwillener MajorGeek

    I am creating an Excel document from a browser based application; the output is basically a large table, which is then saved as an XLS document.

    The page-orientation should be landscape, but I seem to be unable to achieve that, whatever I try.

    The header section contains the following
    Code:
    @page
    	{mso-header-data:"&Cmy header";
    	mso-footer-data:"Page &P of &N";
    	margin:.31in 0in .31in 0in;
    	mso-header-margin:0in;
    	mso-footer-margin:0in;
    	mso-page-orientation:landscape;}
    
    Interestingly everything else works: header, footer, margins. But the page-orientation is always portrait.

    Searching all over the Internet I found that 'mso-page-orientation:landscape' is the way to do it, but it simply doesn't - I always have to change it manually.

    Any ideas?

    (Excel version: 2003)
     
  2. pwillener

    pwillener MajorGeek

    P.S. there is even something additional under WorksheetOptions
    Code:
         <x:PageSetup> 
          <x:Layout x:Orientation="Landscape"/> 
         </x:PageSetup> 
    
     
  3. pwillener

    pwillener MajorGeek

    Found this topic http://forums.iis.net/t/1156329.aspx, where part addresses the same problem. They found that removing the <x:pageSetup> section resolved the problem.

    Unfortunately it did not for me...
     
  4. pwillener

    pwillener MajorGeek

    I finally found the solution for my problem by creating a new Excel doc with landscape page-orientation, then save it in HTML format.

    Next I compared the <xml> and <style> sections line by line with my generated document. The biggest difference was the distribution of the <xml> and <style> sections.

    In my generated document:
    Code:
    <!--[if gte mso 9]><xml>
     <o:DocumentProperties>
    ...
    </xml><![endif]-->
    <!--[if gte mso 9]><xml>
     <x:ExcelWorkbook>
    ...
    </xml><![endif]-->
    <style>
    <!--table
    	{mso-displayed-decimal-separator:"\.";
    	mso-displayed-thousand-separator:"\,";}
    @page
    	{mso-header-data:"&Cmy header";
    	mso-footer-data:"Page &P of &N";
    	margin:.31in 0in .31in 0in;
    	mso-header-margin:0in;
    	mso-footer-margin:0in;
    	mso-page-orientation:landscape;}
    ...
    -->
    </style>
    
    In the document created with Excel:
    Code:
    <!--[if gte mso 9]><xml>
     <o:DocumentProperties>
    ...
    </xml><![endif]-->
    <style>
    <!--table
    	{mso-displayed-decimal-separator:"\.";
    	mso-displayed-thousand-separator:"\,";}
    @page
    	{mso-header-data:"&Cmy header";
    	mso-footer-data:"Page &P of &N";
    	margin:.31in 0in .31in 0in;
    	mso-header-margin:0in;
    	mso-footer-margin:0in;
    	mso-page-orientation:landscape;}
    ...
    -->
    </style>
    <!--[if gte mso 9]><xml>
     <x:ExcelWorkbook>
    ...
    </xml><![endif]-->
    
    Changing the sequence to <xml> : <style> : <xml> fixed my problem, and the generated document now opens with landscape preset.
     
  5. kimber2x

    kimber2x Private E-2

    Hey, can you post your whole script for this, i've tried to copy paste the codes, none of them worked for me.
    thanks in advance.
     
  6. pwillener

    pwillener MajorGeek

    Gladly, here it is. Note that the .xl23 ~ .xl39 sections are my table column formatting. I extracted these from a manually formatted Excel doc, saved as a HTML doc.

    If you continue to have problems, please post some details.
    Code:
    <html xmlns:v="urn:schemas-microsoft-com:vml"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns="http://www.w3.org/TR/REC-html40">
    <head>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
    <meta name=ProgId content=Excel.Sheet>
    <meta name=Generator content="Microsoft Excel 11">
    <!--[if gte mso 9]><xml>
     <o:DocumentProperties>
      <o:Author>Pat Willener</o:Author>
      <o:Company>Good Day Books</o:Company>
     </o:DocumentProperties>
     <o:OfficeDocumentSettings>
      <o:RelyOnVML/>
      <o:AllowPNG/>
     </o:OfficeDocumentSettings>
    </xml><![endif]-->
    <style>
    <!--table
    	{mso-displayed-decimal-separator:"\.";
    	mso-displayed-thousand-separator:"\,";}
    @page
    	{mso-header-data:"&CInventory";
    	mso-footer-data:"Page &P of &N";
    	margin:.31in 0in .31in 0in;
    	mso-header-margin:0in;
    	mso-footer-margin:0in;
    	mso-page-orientation:landscape;}
    tr
    	{mso-height-source:auto;}
    col
    	{mso-width-source:auto;}
    br
    	{mso-data-placement:same-cell;}
    .style0
    	{mso-number-format:General;
    	text-align:general;
    	vertical-align:bottom;
    	white-space:nowrap;
    	mso-rotate:0;
    	mso-background-source:auto;
    	mso-pattern:auto;
    	color:windowtext;
    	font-size:10.0pt;
    	font-weight:400;
    	font-style:normal;
    	text-decoration:none;
    	font-family:Arial;
    	mso-generic-font-family:auto;
    	mso-font-charset:128;
    	border:none;
    	mso-protection:locked visible;
    	mso-style-name:Normal;
    	mso-style-id:0;}
    td
    	{mso-style-parent:style0;
    	padding-top:1px;
    	padding-right:1px;
    	padding-left:1px;
    	mso-ignore:padding;
    	color:windowtext;
    	font-size:10.0pt;
    	font-weight:400;
    	font-style:normal;
    	text-decoration:none;
    	font-family:Arial;
    	mso-generic-font-family:auto;
    	mso-font-charset:128;
    	mso-number-format:General;
    	text-align:general;
    	vertical-align:bottom;
    	border:none;
    	mso-background-source:auto;
    	mso-pattern:auto;
    	mso-protection:locked visible;
    	white-space:nowrap;
    	mso-rotate:0;
            overflow:hidden;}
    .xl23
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"0;-0;;@";
    	text-align:center;
    	vertical-align:top;}
    .xl24
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"\@";
    	vertical-align:top;}
    .xl25
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"\@";
    	text-align:left;
    	vertical-align:top;}
    .xl26
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"\#\,\#\#0";
    	text-align:right;
    	vertical-align:top;}
    .xl27
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"\0022x\0022\;\0022x\0022\;\0022\0022";
    	text-align:center;
    	vertical-align:top;}
    .xl28
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	font-weight:700;
    	mso-number-format:"\@";
    	border-top:.5pt solid black;
    	border-right:none;
    	border-bottom:none;
    	border-left:.5pt solid black;}
    .xl29
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	font-weight:700;
    	mso-number-format:"\@";
    	border-top:.5pt solid black;
    	border-right:none;
    	border-bottom:none;
    	border-left:none;}
    .xl30
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	font-weight:700;
    	mso-number-format:"\@";
    	border-top:.5pt solid black;
    	border-right:.5pt solid black;
    	border-bottom:none;
    	border-left:none;}
    .xl31
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:0;
    	text-align:right;
    	vertical-align:top;
    	border-top:none;
    	border-right:none;
    	border-bottom:none;
    	border-left:.5pt solid black;}
    .xl32
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"\@";
    	vertical-align:top;
    	border-top:none;
    	border-right:.5pt solid black;
    	border-bottom:none;
    	border-left:none;}
    .xl33
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:0;
    	text-align:right;
    	vertical-align:top;
    	border-top:none;
    	border-right:none;
    	border-bottom:.5pt solid black;
    	border-left:.5pt solid black;}
    .xl34
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"\@";
    	vertical-align:top;
    	border-top:none;
    	border-right:none;
    	border-bottom:.5pt solid black;
    	border-left:none;}
    .xl35
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"\@";
    	text-align:left;
    	vertical-align:top;
    	border-top:none;
    	border-right:none;
    	border-bottom:.5pt solid black;
    	border-left:none;}
    .xl36
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"\#\,\#\#0";
    	text-align:right;
    	vertical-align:top;
    	border-top:none;
    	border-right:none;
    	border-bottom:.5pt solid black;
    	border-left:none;}
    .xl37
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"0\;\\-0\;\;\@";
    	text-align:center;
    	vertical-align:top;
    	border-top:none;
    	border-right:none;
    	border-bottom:.5pt solid black;
    	border-left:none;}
    .xl38
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:"\@";
    	vertical-align:top;
    	border-top:none;
    	border-right:.5pt solid black;
    	border-bottom:.5pt solid black;
    	border-left:none;}
    .xl39
    	{mso-style-parent:style0;
    	font-size:8.0pt;
    	mso-number-format:0;
    	text-align:center;
    	vertical-align:top;}
    -->
    </style>
    <!--[if gte mso 9]><xml>
     <x:ExcelWorkbook>
      <x:ExcelWorksheets>
       <x:ExcelWorksheet>
        <x:Name>Inventory</x:Name>
        <x:WorksheetOptions>
         <x:Print>
          <x:ValidPrinterInfo/>
          <x:PaperSizeIndex>9</x:PaperSizeIndex>
          <x:HorizontalResolution>600</x:HorizontalResolution>
          <x:VerticalResolution>600</x:VerticalResolution>
         </x:Print>
         <x:Selected/>
         <x:Panes>
          <x:Pane>
           <x:Number>1</x:Number>
           <x:ActiveRow>1</x:ActiveRow>
          </x:Pane>
         </x:Panes>
         <x:ProtectContents>False</x:ProtectContents>
         <x:ProtectObjects>False</x:ProtectObjects>
         <x:ProtectScenarios>False</x:ProtectScenarios>
        </x:WorksheetOptions>
       </x:ExcelWorksheet>
      </x:ExcelWorksheets>
      <x:WindowHeight>8835</x:WindowHeight>
      <x:WindowWidth>15180</x:WindowWidth>
      <x:WindowTopX>120</x:WindowTopX>
      <x:WindowTopY>105</x:WindowTopY>
      <x:ProtectStructure>False</x:ProtectStructure>
      <x:ProtectWindows>False</x:ProtectWindows>
     </x:ExcelWorkbook>
    </xml><![endif]-->
    
    <title>Inventory</title>
    </head>
    <body lang=en-US>
    <div class=Section1>
    <table cellpadding=0 cellspacing=0 border=1 style='border-collapse:collapse;table-layout:fixed'>
    
    <!-- here are my table rows -->
    
    </table>
    </div>
    </body>
    </html>
    
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds