Hi,
I have a spreadsheet (ods file) in which I have been storing textual data. I want to automate the copying of each cell out to a document file (odt file). However within each cell of the spreadsheet, I have set a mix of textual attributes, i.e. some text is standard font, some characters are in italics, some in bold.
I have tried creating a macro that employs the the getString method and it successfully copies the text data into my odt file, but all the careful text formatting has been lost. Is there a more obscure method I can use, maybe by using createTextCursor etc. that might do the job for me?
Sorry but I am only on day one of trying out macros and Basic and I am feeling a bit confused! The code I have been trying is below:
Sub MyDoLoop
Dim ColNo as Integer
Dim Cursor as Object
Dim Doc As Object
Dim Dummy()
Dim oCell as Object
Dim oSheet as Variant
Dim oSheets as Variant
Dim oString as String
Dim RowNo as Integer
Dim Url As String
oSheets = ThisComponent.getSheets(0)
oSheet = oSheets.getByIndex(0)
Url = "private:factory/swriter"
Doc = StarDesktop.loadComponentFromURL(Url, "_blank", 0, Dummy())
Cursor = Doc.Text.createTextCursor
For RowNo = 1 To 5
oString = ""
For ColNo = 1 To 4
oCell = oSheet.GetCellByPosition(ColNo, RowNo)
oString = oString + oCell.getString()
If ColNo < 3 then oString = oString + ", "
if ColNo = 3 then oString = oString + " "
Next
Cursor.String = oString
Doc.Text.insertControlCharacter(Cursor, _
com.sun.star.text.ControlCharacter.LINE_BREAK, False)
Cursor.gotoEnd(False)
Next
Url = "file:///C:/Gash/data.odt"
Doc.storeAsURL(Url, Dummy())
End Sub