Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试通过xml在excel中设置页边距_Xml_Excel_Formatting_Xml Namespaces - Fatal编程技术网

尝试通过xml在excel中设置页边距

尝试通过xml在excel中设置页边距,xml,excel,formatting,xml-namespaces,Xml,Excel,Formatting,Xml Namespaces,我“继承”了一些将数据下载到excel电子表格的代码。格式化html的表也在生成excel数据 我正在尝试设置工作表的页边距。下面的代码并不能真正做到这一点。我认为xml数据被忽略了 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns:x="urn:schemas

我“继承”了一些将数据下载到excel电子表格的代码。格式化html的表也在生成excel数据

我正在尝试设置工作表的页边距。下面的代码并不能真正做到这一点。我认为xml数据被忽略了

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns:x="urn:schemas-microsoft-com:office:excel">

<head id="Head1" runat="server">
    <title></title>
<style>
  @page 
    {
        mso-page-orientation:portrait;
    }
</style>

    <xml> 
         <x:ExcelWorkbook> 
          <x:ExcelWorksheets> 
           <x:ExcelWorksheet> 
                <x:Name>HoursReport</x:Name> 
                <x:WorksheetOptions>
                <x:Selected/>
                <x:FreezePanes/>
                <x:FrozenNoSplit/>
                <!--- Bottom row number of top pane. --->
                <x:SplitHorizontal>4</x:SplitHorizontal>
                <x:TopRowBottomPane>4</x:TopRowBottomPane>

                  <x:PageSetup>
                    <x:Header x:Margin="0.25"/>
                    <x:Footer x:Margin="0.25"/>
                    <x:PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
                   </x:PageSetup>

                 <x:FitToPage/> 
                 <x:Print> 
                  <x:FitHeight>99</x:FitHeight>
                  <x:ValidPrinterInfo/> 
                  <x:Scale>100</x:Scale> 
                  <HorizontalResolution>600</HorizontalResolution> 
                  <VerticalResolution>600</VerticalResolution> 
                 </x:Print> 
                 <x:Selected/> 
                    <x:ActivePane>2</x:ActivePane>
                 <x:ProtectContents>False</x:ProtectContents> 
                 <x:ProtectObjects>False</x:ProtectObjects> 
                 <x:ProtectScenarios>False</x:ProtectScenarios>
                </x:WorksheetOptions> 
           </x:ExcelWorksheet> 
          </x:ExcelWorksheets> 
          <x:ProtectStructure>False</x:ProtectStructure> 
          <x:ProtectWindows>False</x:ProtectWindows> 
         </x:ExcelWorkbook> 
         <x:ExcelName> 
          <x:Name>Print_Titles</x:Name> 
          <x:SheetIndex>1</x:SheetIndex>
          <x:Formula>='HoursReport'!$1:$4</x:Formula>
         </x:ExcelName> 
</xml>
</head>

@页面
{
mso页面方向:纵向;
}
小时报告
4.
4.
99
100
600
600
2.
假的
假的
假的
假的
假的
打印标题
1.
='HoursReport'$1:$4
我对这里的一切都不熟悉-asp.net、c#、xml、excel…:)我已经使用了其他excel命令-拆分和冻结窗格等。但是页面边距似乎没有任何作用

有人能帮我改邪归正吗

谢谢

也许吧

<x:pageMargins x:left="0.7" x:right="0.7" x:top="0.75" x:bottom="0.75" x:header="0.3" x:footer="0.3" />


作为
元素中的子元素,而不是
元素中的子元素

尝试完成相同的任务,而PageMargins标记似乎不起作用,因此,使用CSS起作用

<style type="text/css">
<!--

@page {
margin:.0in .0in .0in .0in;
mso-header-margin:.0in;
mso-footer-margin:.0in;
mso-page-orientation:portrait;
}

@print {
margin:.0in .0in .0in .0in;
mso-header-margin:.0in;
mso-footer-margin:.0in;
mso-page-orientation:portrait;
}

-->
</style>



页面设置选项位于
工作表选项
标记的内部。我把我的放在工作表开头的标签后面。它就像一个符咒。

你好,马克-谢谢你的回复。我将页边距的位置更改为Excel工作表。还是不走运。下载的文件删除了对页边距的任何引用,当我实际添加它并在excel中重新打开时,会出现错误。
<ss:Worksheet>
  <x:WorksheetOptions>
    <x:PageSetup>
      <x:PageMargins x:Bottom="1.5" x:Left=".25" x:Right=".25" x:Top="1.5" />
    </x:PageSetup>
  </x:WorksheetOptions>
</ss:Worksheet>