Page Setup
In Microsoft Excel, you can set the layout properties of a printed worksheet by
selecting Page Setup... from the File menu:

If you set page setup properties in Microsoft Excel and open the spreadsheet with
ExcelWriter, the page setup settings will be preserved. Alternatively, use ExcelWriter's
PageSetup object to set layout properties
in script.
ExcelWriter's PageSetup object represents the layout properties of a printed
worksheet. To create a PageSetup object with ExcelWriter, use,
Set PageSetup = Worksheet.PageSetup
Note: Since this object is tightly related to client's printer
setup, for those computers without a printer setup, changes
to this object have no effect.
Example

<%@ Language=VBScript %>
<% Option Explicit %>
<!-- METADATA TYPE="TypeLib" UUID="{7BCD2133-64A0-4770-843C-090637114583}" -->
<%
Dim xlw, ws, commentstyle, ScriptName
Dim NumRows, NumCols, NumSheets
Dim RowCount, ColCount, SheetCount
Dim SRowX, SColY, SSheetZ
NumRows = 40
NumCols = 40
NumSheets = 1
RowCount = NumRows + 1
ColCount = NumCols + 1
SheetCount = NumSheets
SRowX = 3
SColY = 1
SSheetZ = 1
Set xlw = Server.CreateObject("Softartisans.Excelwriter")
Set ws = xlw.worksheets(1)
'--- Set a comment style
Set commentstyle = xlw.CreateStyle
commentstyle.Font.Name = "Arial"
commentstyle.Font.Bold = True
commentstyle.VerticalAlignment = savaCenter
commentstyle.HorizontalAlignment = sahaCenter
'--- Include a comment explaining where to
'--- view the page setup settings
ws.cells.mergecells 1,1,1,15
ws.cells.rowheight(1) = 20
ws.cells("A1").style = commentstyle
ws.cells("A1").value = "PageSetup.asp assigned layout settings for " &_
"printing this spreadsheet. To see the layout " &_
"settings, open File/Page Setup..." &_
"and File/Print Preview."
'--- Set layout properties for the printed
'--- worksheet.
ws.PageSetup.CenterFooter = "centerfooter"
ws.PageSetup.CenterHeader = "centerheader"
ws.PageSetup.CenterVertically = True
ws.PageSetup.CenterHorizontally = True
ws.PageSetup.LeftFooter = "leftfooter"
ws.PageSetup.RightFooter = "rightfooter"
ws.PageSetup.LeftHeader = "leftheader"
ws.PageSetup.RightHeader = "rightheader"
ws.PageSetup.Orientation = 1
ws.PageSetup.PaperSize = saxlPaperA4
ws.PageSetup.FirstPageNumber = 2
ws.PageSetup.Zoom = 50
Ws.PageSetup.FitToPagesTall = 2
Ws.PageSetup.FitToPagesWide = 3
'--- Set title columns and rows that will be repeated on each page
'--- of a printed worksheet. SetPrintTitleColumns and
'--- SetPrintTitleRows set two Areas of the Range returned
'--- by PageSetup.GetPrintTitles.
Ws.PageSetup.SetPrintTitleRows 4, 1
Ws.PageSetup.SetPrintTitleColumns 4, 1
'--- Define theworksheets print area. PrintArea is a Range
'--- that is read by the PageSetup object when determining the
'--- portion of the page that should be printed.
Ws.PageSetup.PrintArea = Ws.Cells.Range(20, 20, 10, 10)
Do While SRowX < RowCount
Do While SColY < ColCount
xlw.Worksheets(1).Cells(SRowX, SColY).Value = "PageSetup"
SColY = SColY + 1
Loop
SColY = 1
SRowX = SRowX + 1
Loop
'--- Save the spreadsheet.
xlw.Save "PageSetup.xls", saOpenInPlace
'--- Error handling.
ScriptName = Request.ServerVariables("Script_Name")
If Err.number <> 0 Then
Response.Status = "500 Internal Server Error"
Response.Write "Error : '" & Err.description & "'</P>"
Else
Response.End
End IF
set xlw = nothing
%>

Copyright 2005 © SoftArtisans, Inc. All Rights Reserved.
|