OO tábla: több érték visszaadása

Fórumok

Sziasztok, adott két oszlop:

domain1:host0
domain2:host0
domain3:host1
domain4:host2

Az első oszlopban a domain-ek, a másodikban hogy melyik hoston laknak. Szeretnék ebből egy olyan táblát gyártani, ami kb így néz ki:

host0        host1       host2
domain1      domain3     domain4
domain2

Azaz az egyes hostokhoz automatikusan felsorolódik a rajta lakó domain-ek listája. Lehet h rosszul kerestem, de nem találtam megoldást, magamtól meg csak rettenetesen bonyolult - és rugalmatlan - megoldást találtam, hátha tud valaki jobbat.

Update: az is megfelelő, ha kb. ilyen jön ki:

host0:domain1 domain2

Mert ez most csak arra kell, hogy egy külön lapon felsorolva, egy egyszerűbb elrendezésben is lehessen látni, hogy mi hol van.

Hozzászólások

Kitenni pl. csv-be utána sed/awk/perl?

OO-n belül kellene megoldani, realtime update kellene. Vagy maximum egy gombnyomás egy makróra. De még ennyit se ér.

Ha mégis szükség lesz rá, akkor hanyagolni fogom az OO táblát és keresek valami olyasmit mint az ispcp, amivel át tudom tekinteni, hogy mi merre hány méter. Most épp 44 (al)domaint kell átköltöztetnem, ez kevesebb nem lesz.


REM  *****  BASIC  *****

Sub Main

Dim SourceSheet, Sheet 
Dim SourceCell, Cell 
Dim Col as Integer
Dim Row as Integer
Dim MaxRow as Integer
Dim SourceSheetNr as Integer
Dim TargetSheetNr as Integer

rem !!!!!!!
SourceSheetNr = 0
TargetSheetNr = 1

SourceSheet = ThisComponent.Sheets.getByIndex(SourceSheetNr)
Sheet = ThisComponent.Sheets.getByIndex(TargetSheetNr)

rem !!!!!!!
MaxSourceRow = 1000

rem Cleaning target sheet
Dim CellRangeAddress as New com.sun.star.table.CellRangeAddress
CellRangeAddress.Sheet = TargetSheetNr
CellRangeAddress.StartColumn = 0
CellRangeAddress.EndColumn = MaxSourceRow
CellRangeAddress.StartRow = 0
CellRangeAddress.EndRow = MaxSourceRow
Sheet.removeRange(CellRangeAddress, com.sun.star.sheet.CellDeleteMode.COLUMNS)


rem Number of domains
For SourceRow = 0 to MaxSourceRow
	SourceCell = SourceSheet.getCellByPosition(0, SourceRow)
	If SourceCell.Type = com.sun.star.table.CellContentType.EMPTY Then
		MaxSourceRow = SourceRow - 1
	    Exit For
	End If
Next SourceRow

rem Inserting first row
MaxCol = 0
For SourceRow = 0 to MaxSourceRow
	SourceCell = SourceSheet.getCellByPosition(1, SourceRow)
	Was = 0
	For Col = 0 to MaxCol
		Cell = Sheet.getCellByPosition(Col, 0)
		If Cell.String = SourceCell.String Then
			Was = 1
			Exit For
		End If
	Next Col
	If Was = 0 Then
		Cell = Sheet.getCellByPosition(MaxCol, 0)
		Cell.String = SourceCell.String
		MaxCol = MaxCol + 1
	End If
Next SourceRow
MaxCol = MaxCol - 1

rem Inserting domains
Dim FirstCell, DomainCell

For Col = 0 to MaxCol
	FirstCell = Sheet.getCellByPosition(Col, 0)
	Row = 1
	For SourceRow = 0 to MaxSourceRow
		SourceCell = SourceSheet.getCellByPosition(1, SourceRow)
		If FirstCell.String = SourceCell.String Then
			Cell = Sheet.getCellByPosition(Col, Row)
			DomainCell = SourceSheet.getCellByPosition(0, SourceRow)
			Cell.String = DomainCell.String
			Row = Row + 1
		End If
	Next SourceRow
Next Col

End Sub

Rövid magyarázat:
Az 1. táblázat a1:b1000-es tartományát vizsgálja (bedrótozva).
A konvertált értékek a 2. táblázat a1-es mezőjétől kezdődően helyezkednek el.

-----
"Én vagyok a hülye, hogy leállok magával vitatkozni."

Kicsit kipofozva, az induló értékek az elején definiálva:


REM  *****  BASIC  *****

rem ** transform table and groupping items **
rem SourceSheetNr: original datasheet
rem TargetSheetNr: transformed datasheet
rem ColumnOffset: horizontal offset of datas (A -> 0; B -> 1; ...)
rem RowOffset: vertical offset of datas (row 1 -> 0; row 2 -> 1; ...)
rem MaxDomains: Maximal number of rows

Sub Main

Dim SourceSheet, Sheet 
Dim SourceCell, Cell 
Dim Col as Integer
Dim Row as Integer
Dim MaxRow as Integer
Dim MaxSourceRow as Integer
Dim SourceSheetNr as Integer
Dim TargetSheetNr as Integer
Dim ColumnOffset as Integer
Dim RowOffset as Integer
Dim MaxDomains as Integer

rem !!!!!!!
SourceSheetNr = 0
TargetSheetNr = 1
ColumnOffset = 0
RowOffset = 0
MaxDomains = 1000


MaxSourceRow = RowOffset + MaxDomains

SourceSheet = ThisComponent.Sheets.getByIndex(SourceSheetNr)
Sheet = ThisComponent.Sheets.getByIndex(TargetSheetNr)

rem **** Cleaning target sheet ****
Dim CellRangeAddress as New com.sun.star.table.CellRangeAddress
CellRangeAddress.Sheet = TargetSheetNr
CellRangeAddress.StartColumn = ColumnOffset
CellRangeAddress.EndColumn = ColumnOffset + MaxSourceRow
CellRangeAddress.StartRow = RowOffset
CellRangeAddress.EndRow = RowOffset + MaxSourceRow
Sheet.removeRange(CellRangeAddress, com.sun.star.sheet.CellDeleteMode.COLUMNS)


rem **** Number of domains ****
For SourceRow = RowOffset to MaxSourceRow
	SourceCell = SourceSheet.getCellByPosition(ColumnOffset, SourceRow)
	If SourceCell.Type = com.sun.star.table.CellContentType.EMPTY Then
		MaxSourceRow = SourceRow - 1
	    Exit For
	End If
Next SourceRow

rem **** Inserting first row ****
MaxCol = 0
For SourceRow = RowOffset to MaxSourceRow
	SourceCell = SourceSheet.getCellByPosition(ColumnOffset + 1, SourceRow)
	Was = 0
	For Col = 0 to MaxCol
		Cell = Sheet.getCellByPosition(Col, 0)
		If Cell.String = SourceCell.String Then
			Was = 1
			Exit For
		End If
	Next Col
	If Was = 0 Then
		Cell = Sheet.getCellByPosition(MaxCol, 0)
		Cell.String = SourceCell.String
		MaxCol = MaxCol + 1
	End If
Next SourceRow
MaxCol = MaxCol - 1

rem **** Inserting domains ****
Dim FirstCell, DomainCell

For Col = 0 to MaxCol
	FirstCell = Sheet.getCellByPosition(Col, 0)
	Row = 1
	For SourceRow = RowOffset to MaxSourceRow
		SourceCell = SourceSheet.getCellByPosition(ColumnOffset + 1, SourceRow)
		If FirstCell.String = SourceCell.String Then
			Cell = Sheet.getCellByPosition(Col, Row)
			DomainCell = SourceSheet.getCellByPosition(ColumnOffset, SourceRow)
			Cell.String = DomainCell.String
			Row = Row + 1
		End If
	Next SourceRow
Next Col

End Sub

-----
"Én vagyok a hülye, hogy leállok magával vitatkozni."