von moritz » Mo, 04.06.2007 18:59
Die folgenden Makros werden Dir weiterhelfen. Ermittelt werden die erste und letzte benutzte Zelle.
REM ***** BASIC *****
Sub Main
oDoc = ThisComponent
oSheet = oDoc.getSheets().getByIndex( 0 )
oLastCell = GetLastUsedCell( oSheet )
Print "Last cell is ", oLastCell.getRangeAddress().EndColumn, oLastCell.getRangeAddress().EndRow
oFirstCell = GetFirstUsedCell( oSheet )
Print "First cell is ", oFirstCell.getRangeAddress().EndColumn, oFirstCell.getRangeAddress().EndRow
End Sub
Function GetLastUsedCell( oSheet As com.sun.star.sheet.Spreadsheet ) As com.sun.star.sheet.SheetCell
' The Spreadsheet interface XSpreadsheet has method createCursor(),
' which returns a SheetCellCursor.
oCellCursor = oSheet.createCursor()
' The SheetCellCursor has interface XUsedAreaCursor, which has method gotoEndOfUsedArea().
oCellCursor.gotoEndOfUsedArea( False )
' The SheetCellCursor includes service SheetCellRange which has interface XCellRangeAddressable
' which has method getRangeAddress(), which returns a struct com.sun.star.table.CellRangeAddress.
tCellRangeAddress = oCellCursor.getRangeAddress()
' Get the last used cell on the spreadsheet.
oCell = oSheet.getCellByPosition( tCellRangeAddress.EndColumn, tCellRangeAddress.EndRow )
GetLastUsedCell = oCell
end function
Function GetFirstUsedCell( oSheet As com.sun.star.sheet.Spreadsheet ) As com.sun.star.sheet.SheetCell
' The Spreadsheet interface XSpreadsheet has method createCursor(),
' which returns a SheetCellCursor.
oCellCursor = oSheet.createCursor()
' The SheetCellCursor has interface XUsedAreaCursor, which has method gotoStartOfUsedArea().
oCellCursor.gotoStartOfUsedArea( False )
' The SheetCellCursor includes service SheetCellRange which has interface XCellRangeAddressable
' which has method getRangeAddress(), which returns a struct com.sun.star.table.CellRangeAddress.
tCellRangeAddress = oCellCursor.getRangeAddress()
' Get the first used cell on the spreadsheet.
oCell = oSheet.getCellByPosition( tCellRangeAddress.EndColumn, tCellRangeAddress.EndRow )
GetFirstUsedCell = oCell
end function
Und hier noch Beispiele für das arbeiten mit Druckbereichen
sub Drucken_benannte_Bereiche
dim i As Integer
Dim oSheet As Object
Dim oBenannterBereich As Object
Dim oDoc as object
Dim selArea(0) as new com.sun.star.table.CellRangeAddress
Dim DruckEigenschaften(0) As New com.sun.star.beans.PropertyValue
Dim sURL As string
const sDateiText ="Adobe pdf- Dateien (*.pdf)"
const sDateiJoker = "*.pdf"
oDialogDruckForm = CreateUnoDialog(DialogLibraries.Standard.fmDruck)
Dialoglibraries.Loadlibrary("Standard")
oSheet = ThisComponent.getSheets().getByName(regieSheetIndex)
oDoc = Thiscomponent
oDialogDruckForm.Execute()
for i = 0 to thisComponent.NamedRanges.Count-1
if left$(thisComponent.NamedRanges.ElementNames(i),6) = "regieB" then
oBenannterBereich = thisComponent.NamedRanges.GetByIndex(i)
'msgbox "Drucke " & thisComponent.NamedRanges.ElementNames(i)
selArea(0).StartColumn = oBenannterBereich.ReferredCells.RangeAddress.StartColumn
selArea(0).StartRow = oBenannterBereich.ReferredCells.RangeAddress.StartRow
selArea(0).EndColumn = oBenannterBereich.ReferredCells.RangeAddress.EndColumn
selArea(0).EndRow = oBenannterBereich.ReferredCells.RangeAddress.EndRow
oSheet.setPrintareas(selArea())
if boDruck = True then
oDoc.Print(Array())
'xray oBenannterBereich
else
sUrlVorgabe= "Arbeitszeitbericht " & oBenannterBereich.getReferredCells.getCellByPosition(3,3).string & " von " & oBenannterBereich.getReferredCells.getCellByPosition(7,5).string & " bis " & oBenannterBereich.getReferredCells.getCellByPosition(7,7).string & ".pdf"
DruckEigenschaften(0).Name="FilterName"
DruckEigenschaften(0).Value = "writer_pdf_Export"
SaveFileDialog(sURL, sDateiText, sDateiJoker, sUrlVorgabe)
oDoc.storetoUrl(sUrl,DruckEigenschaften())
end if
Druckbereich_aus
end if
next
end Sub
Sub Druckbereich_Ein (sSht$, nStC&, nStR&, nEndC&, nEndR&)
'------------------------------------------------------------------
Dim selArea(0) as new com.sun.star.table.CellRangeAddress
Dim oDoc as object
Dim oSheet as object
Dim oSheets
Dim i%
oDoc = Thiscomponent
oSheets = ThisComponent.Sheets
oSheet = ThisComponent.currentSelection.getSpreadsheet()
oSheet.setPrintareas(array())
selArea(0).StartColumn = 1
selArea(0).StartRow = 0
selArea(0).EndColumn = 12
selArea(0).EndRow = 46
oSheet=ThisComponent.currentSelection.getSpreadsheet()
oSheet.setPrintareas(selArea())
oDoc.Print(Array())
End Sub
REM++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
REM Hier wird der Druckbereich wieder gelöscht.
REM++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub Druckbereich_aus
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:DeletePrintArea", "", 0, Array())
end sub
Die folgenden Makros werden Dir weiterhelfen. Ermittelt werden die erste und letzte benutzte Zelle.
REM ***** BASIC *****
Sub Main
oDoc = ThisComponent
oSheet = oDoc.getSheets().getByIndex( 0 )
oLastCell = GetLastUsedCell( oSheet )
Print "Last cell is ", oLastCell.getRangeAddress().EndColumn, oLastCell.getRangeAddress().EndRow
oFirstCell = GetFirstUsedCell( oSheet )
Print "First cell is ", oFirstCell.getRangeAddress().EndColumn, oFirstCell.getRangeAddress().EndRow
End Sub
Function GetLastUsedCell( oSheet As com.sun.star.sheet.Spreadsheet ) As com.sun.star.sheet.SheetCell
' The Spreadsheet interface XSpreadsheet has method createCursor(),
' which returns a SheetCellCursor.
oCellCursor = oSheet.createCursor()
' The SheetCellCursor has interface XUsedAreaCursor, which has method gotoEndOfUsedArea().
oCellCursor.gotoEndOfUsedArea( False )
' The SheetCellCursor includes service SheetCellRange which has interface XCellRangeAddressable
' which has method getRangeAddress(), which returns a struct com.sun.star.table.CellRangeAddress.
tCellRangeAddress = oCellCursor.getRangeAddress()
' Get the last used cell on the spreadsheet.
oCell = oSheet.getCellByPosition( tCellRangeAddress.EndColumn, tCellRangeAddress.EndRow )
GetLastUsedCell = oCell
end function
Function GetFirstUsedCell( oSheet As com.sun.star.sheet.Spreadsheet ) As com.sun.star.sheet.SheetCell
' The Spreadsheet interface XSpreadsheet has method createCursor(),
' which returns a SheetCellCursor.
oCellCursor = oSheet.createCursor()
' The SheetCellCursor has interface XUsedAreaCursor, which has method gotoStartOfUsedArea().
oCellCursor.gotoStartOfUsedArea( False )
' The SheetCellCursor includes service SheetCellRange which has interface XCellRangeAddressable
' which has method getRangeAddress(), which returns a struct com.sun.star.table.CellRangeAddress.
tCellRangeAddress = oCellCursor.getRangeAddress()
' Get the first used cell on the spreadsheet.
oCell = oSheet.getCellByPosition( tCellRangeAddress.EndColumn, tCellRangeAddress.EndRow )
GetFirstUsedCell = oCell
end function
Und hier noch Beispiele für das arbeiten mit Druckbereichen
sub Drucken_benannte_Bereiche
dim i As Integer
Dim oSheet As Object
Dim oBenannterBereich As Object
Dim oDoc as object
Dim selArea(0) as new com.sun.star.table.CellRangeAddress
Dim DruckEigenschaften(0) As New com.sun.star.beans.PropertyValue
Dim sURL As string
const sDateiText ="Adobe pdf- Dateien (*.pdf)"
const sDateiJoker = "*.pdf"
oDialogDruckForm = CreateUnoDialog(DialogLibraries.Standard.fmDruck)
Dialoglibraries.Loadlibrary("Standard")
oSheet = ThisComponent.getSheets().getByName(regieSheetIndex)
oDoc = Thiscomponent
oDialogDruckForm.Execute()
for i = 0 to thisComponent.NamedRanges.Count-1
if left$(thisComponent.NamedRanges.ElementNames(i),6) = "regieB" then
oBenannterBereich = thisComponent.NamedRanges.GetByIndex(i)
'msgbox "Drucke " & thisComponent.NamedRanges.ElementNames(i)
selArea(0).StartColumn = oBenannterBereich.ReferredCells.RangeAddress.StartColumn
selArea(0).StartRow = oBenannterBereich.ReferredCells.RangeAddress.StartRow
selArea(0).EndColumn = oBenannterBereich.ReferredCells.RangeAddress.EndColumn
selArea(0).EndRow = oBenannterBereich.ReferredCells.RangeAddress.EndRow
oSheet.setPrintareas(selArea())
if boDruck = True then
oDoc.Print(Array())
'xray oBenannterBereich
else
sUrlVorgabe= "Arbeitszeitbericht " & oBenannterBereich.getReferredCells.getCellByPosition(3,3).string & " von " & oBenannterBereich.getReferredCells.getCellByPosition(7,5).string & " bis " & oBenannterBereich.getReferredCells.getCellByPosition(7,7).string & ".pdf"
DruckEigenschaften(0).Name="FilterName"
DruckEigenschaften(0).Value = "writer_pdf_Export"
SaveFileDialog(sURL, sDateiText, sDateiJoker, sUrlVorgabe)
oDoc.storetoUrl(sUrl,DruckEigenschaften())
end if
Druckbereich_aus
end if
next
end Sub
Sub Druckbereich_Ein (sSht$, nStC&, nStR&, nEndC&, nEndR&)
'------------------------------------------------------------------
Dim selArea(0) as new com.sun.star.table.CellRangeAddress
Dim oDoc as object
Dim oSheet as object
Dim oSheets
Dim i%
oDoc = Thiscomponent
oSheets = ThisComponent.Sheets
oSheet = ThisComponent.currentSelection.getSpreadsheet()
oSheet.setPrintareas(array())
selArea(0).StartColumn = 1
selArea(0).StartRow = 0
selArea(0).EndColumn = 12
selArea(0).EndRow = 46
oSheet=ThisComponent.currentSelection.getSpreadsheet()
oSheet.setPrintareas(selArea())
oDoc.Print(Array())
End Sub
REM++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
REM Hier wird der Druckbereich wieder gelöscht.
REM++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sub Druckbereich_aus
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:DeletePrintArea", "", 0, Array())
end sub