Friday, February 24, 2012

Export to Excel - Fit to one page property?

It is possible to set scaling property "fit to ... page(s) wide" = 1 (menu "File" ->"Page Setup") , when I export report to Excel from Reporting Services 2005?

Thank you

Fit to Page is not currently supported in the Excel renderer.

-Chris

|||

If you go to:

menu>reoprt> report properties

click on the layout tab and change the size to what ever you need probably bigger, that should do it.

-Rohit

|||
I use the following code to format Excel on Export from my .net page
everything works except the line "sb.Append"<x:FitToPage>true</x:FitToPage>".

I've tried "yes", "1", "true", none worked.

I read at a couple sites that FitToPage is not supported in Excel.

Response.Write(AddExcelStyling())

Private Function AddExcelStyling() As String

Dim sb As New StringBuilder()

sb.Append("<html xmlns:o='urn:schemas-microsoft-com:office:office'" & Chr(10) & "" + "xmlns:x='urn:schemas-microsoft-com:office:excel'" & Chr(10) & "" + "xmlns='http://www.w3.org/TR/REC-html40'>" & Chr(10) & "" + "<head>" & Chr(10) & "")
sb.Append("<style>" & Chr(10) & "")

sb.Append("@.page")
sb.Append("{margin:.25in .5in .25in .5in;" & Chr(10) & "")

sb.Append("mso-header-margin:.5in;" & Chr(10) & "")

sb.Append("mso-footer-margin:.5in;" & Chr(10) & "")
sb.Append("{size:11in 8.5in; " & Chr(10) & "")
sb.Append("mso-page-orientation:landscape;}" & Chr(10) & "")
sb.Append("</style>" & Chr(10) & "")

sb.Append("<!--[if gte mso 9]><xml>" & Chr(10) & "")
sb.Append("<x:ExcelWorkbook>" & Chr(10) & "")

sb.Append("<x:ExcelWorksheets>" & Chr(10) & "")
sb.Append("<x:ExcelWorksheet>" & Chr(10) & "")

sb.Append("<x:Name> </x:Name>" & Chr(10) & "")
sb.Append("<x:WorksheetOptions>" & Chr(10) & "")

sb.Append("<x:Print>" & Chr(10) & "")
sb.Append("<x:ValidPrinterInfo/>" & Chr(10) & "")
sb.Append("<x:FitToPage>true</x:FitToPage>" & Chr(10) & "")

sb.Append("<x:PaperSizeIndex>9</x:PaperSizeIndex>" & Chr(10) & "")
sb.Append("<x:HorizontalResolution>600</x:HorizontalResolution" & Chr(10) & "")

sb.Append("<x:VerticalResolution>600</x:VerticalResolution" & Chr(10) & "")
sb.Append("</x:Print>" & Chr(10) & "")

sb.Append("<x:Selected/>" & Chr(10) & "")
sb.Append("<x:DoNotDisplayGridlines/>" & Chr(10) & "")

sb.Append("<x:ProtectContents>False</x:ProtectContents>" & Chr(10) & "")
sb.Append("<x:ProtectObjects>False</x:ProtectObjects>" & Chr(10) & "")

sb.Append("<x:ProtectScenarios>False</x:ProtectScenarios>" & Chr(10) & "")
sb.Append("</x:WorksheetOptions>" & Chr(10) & "")

sb.Append("</x:ExcelWorksheet>" & Chr(10) & "")
sb.Append("</x:ExcelWorksheets>" & Chr(10) & "")

sb.Append("<x:WindowHeight>12780</x:WindowHeight>" & Chr(10) & "")
sb.Append("<x:WindowWidth>10035</x:WindowWidth>" & Chr(10) & "")

sb.Append("<x:WindowTopX>0</x:WindowTopX>" & Chr(10) & "")
sb.Append("<x:WindowTopY>15</x:WindowTopY>" & Chr(10) & "")

sb.Append("<x:ProtectStructure>False</x:ProtectStructure>" & Chr(10) & "")
sb.Append("<x:ProtectWindows>False</x:ProtectWindows>" & Chr(10) & "")

sb.Append("</x:ExcelWorkbook>" & Chr(10) & "")
sb.Append("</xml><![endif]-->" & Chr(10) & "")

sb.Append("</head>" & Chr(10) & "")
sb.Append("<body>" & Chr(10) & "")

Return sb.ToString()
End Function

No comments:

Post a Comment