i have 'inherited' some code that downloads data to an excel spreadsheet. The same tables formatting the html are generating the excel开发者_Python百科 data.
i am trying to set the page-margins for the worksheet. the following code doesn't really do it. i think the xml data is ignored.
<!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>
i am new to everything here - asp.net, c#, xml, excel...:) i've gotten the other excel commands to work - splitting and freezing panes etc. but the page-margins don't seem to do anything.
anyone out there that can straighten me out?
Thanks!
was trying to accomplish the same thing and the PageMargins tag doesn't seem to work, what did work was using 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>
<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>
Your page setup options go inside of the WorksheetOptions
tag. I placed mine right after the beginning Worksheet
tag. It works like a charm.
Perhaps
<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" />
as a child element within the <x:ExcelWorksheet>
element rather than in the <x:PageSetup>
element
精彩评论