====== Tabellenkalkulation: Der PC-Konfigurator ====== Dieses Projekt "Kauf eines PC's" kann sehr gut mit dem Thema "Arbeiten mit großen Datenmengen" sowie "Umgang mit Editoren" kombiniert werden. Ein aktueller PC-Komponenten-Flyer (PDF) wird dazu im Internet gesucht und in eine Textdatei konvertiert. Mithilfe regulärer Ausdrücke wird diese Datei in ein Format umgewandelt, das in OpenOffice-Calc importiert werden kann. Für dieses Projekt werden Kenntnisse der Makroprogrammierung benötigt! In diesem Projekt wird ein PC-Konfigurator mit OpenOffice Calc entwickelt. |{{ :inf:angewandte:pc_kauf.png?450 |}}| |Das Arbeitsblatt "PC-Konfigurator" in Aktion.| ===== Beispieltabelle und das dazugehörige Makro ===== ==== Die Calc-Tabelle ==== Ein Arbeitsblatt "cpu_board.ods" befindet sich im Downloadbereich, in dem einige Grundelemente bereits installiert sind. === Basic-makro === ' Grunddatei fürs CPU-Projekt sub test MsgBox "Hallo Welt" end sub ' cpu-Prozedur zum Erstellen des Konfigurators ' sub cpu 'Ermittelt die Zeilennummer, in der sich der Cursor befindet. r = getCurrentRow() 'Die aktuelle Spaltennummer wird ausgelesen und der Variablen c zugewiesen.' c = getCurrentCol() value = readCell( c+1,r ) writeCell(5,2,value) strCPU = readString(c,r) writeString(4,2,strCPU) end sub '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' utility functions ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' getCurrentRow ' @returns the current cell position (zero based) Function getCurrentRow() as Integer oDesktop = createUnoService( "com.sun.star.frame.Desktop" ) oController = oDesktop.CurrentFrame.Controller oSelection = oController.Selection aPos = oSelection.getRangeAddress getCurrentRow = aPos.StartRow End Function ' getCurrentCol ' @returns the current cell position (zero based) Function getCurrentCol() as Integer oDesktop = createUnoService( "com.sun.star.frame.Desktop" ) oController = oDesktop.CurrentFrame.Controller oSelection = oController.Selection aPos = oSelection.getRangeAddress getCurrentCol = aPos.StartColumn End Function ' writeCell writes a number to the table cell. ' @param the zero based xPos table position ' @param the zero based yPos table position ' @param value Function writeCell( xPos as Integer, yPos as Integer, value as Double) Dim myDoc Dim mySheet Dim myCell myDoc = thisComponent mySheet = myDoc.sheets( 0 ) myCell = mySheet.getCellByPosition( xPos, yPos ) myCell.setValue( value ) End Function ' overloaded function for string operations ' @see writeCell Function writeString( xPos as Integer, yPos as Integer, value as String) Dim myDoc Dim mySheet Dim myCell myDoc = thisComponent mySheet = myDoc.sheets( 0 ) myCell = mySheet.getCellByPosition( xPos, yPos ) myCell.String = value End Function ' overloaded function for string operations ' @see readCell Function readString( xPos as Integer, yPos as Integer) as String Dim myDoc Dim mySheet Dim myCell myDoc = thisComponent mySheet = myDoc.sheets( 0 ) myCell = mySheet.getCellByPosition( xPos, yPos ) readString = myCell.String End Function ' readCell reads a number from the given cell position. ' @param the zero based xPos table position ' @param the zero based yPos table position ' @return double (integer) value in the given position ' #todo# exception handling Function readCell( xPos as Integer, yPos as Integer) as Double Dim myDoc Dim mySheet myDoc = thisComponent mySheet = myDoc.sheets( 0 ) readCell = mySheet.getCellByPosition( xPos, yPos ).getValue() End Function