2009年6月15日 星期一

透過LotesNotes建立Openoffice空白文件上建立表格並且插入列,並且「合併儲存格」

在OpenOfficeg上使用Basic語法「合併儲存」,不像在MS Word上來的便利
試了一天半終於測試出來的..感動..希望可以提供大家參考。各位也可以直接參考
以下這篇文章:
http://codesnippets.services.openoffice.org/WriterWriter.MergeTableCells.snip

'/==================================
'透過LotesNotes建立Openoffice空白文件
'上建立表格並且插入列,並且「合併儲存格」
'/==================================

Sub Click(Source As Button)
Dim objServiceManager As Variant
Dim objDesktop As Variant
Dim objDocument As Variant
Dim objTable As Variant
Dim objCursor As Variant

Dim objRows As Variant
Dim objRow As Variant
Dim objCellCursor As Variant
Dim objCellText As Variant

Dim sURL As String
Dim session As New NotesSession
Dim db As NotesDatabase
Dim args() As Variant
Dim argsEnd() As Variant

' Initialize the OpenOffice Environment
Set objServiceManager = CreateObject("com.sun.star.ServiceManager")
Set objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")

' Initialize the Lotus Notes Environment
Set db = session.CurrentDatabase
' URL to create a new file
sUrl ="private:factory/swriter"
Set objDocument = objDesktop.loadComponentFromURL(sURL, "_blank", 0, args)

Set objText= objDocument.getText()
Set objCursor= objText.createTextCursor()

Set objTable= objDocument.createInstance( "com.sun.star.text.TextTable")

objTable.initialize 2, 4
'Insert the table
objText.insertTextContent objCursor, objTable, False
'Get first row
Set objRows= objTable.getRows()
Set objRow= objRows.getByIndex(0)

Set objCellText= objTable.getCellByName("A1")
Set objCellCursor= objCellText.createTextCursor()
objCellCursor.setPropertyValue "CharColor",255
objCellText.insertString objCellCursor, "第一欄", False

'-----------------------------------------
' xTextTableCursor=xTextTable.createCursorByCellName("A"row) '-- create cursor
' xTextTableCursor=gotoCellByName("B"row, .true) '-- select area up toand including this cell
' xTextTableCursor=mergeRange '-- merge selectedcells

' insertIntoCell "A1","第一欄", objTable
' insertIntoCell "B1","第二欄", objTable
' insertIntoCell "C1","第三欄", objTable
' insertIntoCell "D1","加總", objTable
' insertByIndex( [in] long nIndex, [in] long nCount );
' com.sun.star.text.XTableRows xRows = xTextTable.getRows();
' insertByIndex( 6,4 ),objTable
' xRows.insertByIndex(xRows.getCount()-1, 0);
' 加入動態插入列
objRows.insertByIndex objRows.getCount(), 6
'測試合併儲存格
Dim objTextTableCursor As Variant
Set objTextTableCursor=objTable.createCursorByCellName("A1")
objTextTableCursor.gotoCellByName("A4") ,True
objTextTableCursor.mergeRange

End Sub

沒有留言: