libreoffice calc宏 - 在同一单元格内设置两种不同类型的字体

发布于 2025-02-10 20:38:10 字数 1133 浏览 1 评论 0原文

大家早上好, 我想构建一个基本宏,使我们能够以首先使用一个字符格式化的内容设置一个格式化一个单元格,然后使用其他字符。 我需要它能够产生标签,然后使用串行打印与作家打印。

这是我的代码:

Public Sub FormattaCarattere()
    Dim Doc As Object
    Dim Sheet As Object
    Dim Cell As Object
     
    Doc = ThisComponent
    sheet = ThisComponent.Sheets.getByName("Test")
    ThisComponent.CurrentController.setActiveSheet(sheet)       

    Cell = Sheet.getCellRangeByName("D7")
    
    Cell.CharFontName = "Gill Sans MT"
    Cell.String = "TEST-01" & vbcrlf  'Insert one Carriege Return
    
    Cell.CharFontName = "Libre Barcode 128 Text"  'I want to change font in the same cell
    Cell.String = Cell.String & "TEST-02"
     
    Cell.HoriJustify = com.sun.star.table.CellHoriJustify.CENTER
    Cell.VertJustify = com.sun.star.table.CellVertJustify.CENTER
End Sub

下面是我想做的事情的图像:

“在此处输入图像说明”

我已经编写了一些宏来生成正确单元格中的标题,并生成相对条形码( Code128)正确。但是,由于在条形码使用另一种时,用字体制作了铭文,因此现在我想在最终单元格中写下所有内容,然后序列化打印。 你可以帮我吗? 我感谢。

Good morning everyone,
I would like to build a Uno Basic macro that allows us to set the formatting one cell in such a way as to have the content first formatted with one character and then subsequently with a different character.
I would need it to be able to produce labels to then print with the Writer using serial printing.

This is my code:

Public Sub FormattaCarattere()
    Dim Doc As Object
    Dim Sheet As Object
    Dim Cell As Object
     
    Doc = ThisComponent
    sheet = ThisComponent.Sheets.getByName("Test")
    ThisComponent.CurrentController.setActiveSheet(sheet)       

    Cell = Sheet.getCellRangeByName("D7")
    
    Cell.CharFontName = "Gill Sans MT"
    Cell.String = "TEST-01" & vbcrlf  'Insert one Carriege Return
    
    Cell.CharFontName = "Libre Barcode 128 Text"  'I want to change font in the same cell
    Cell.String = Cell.String & "TEST-02"
     
    Cell.HoriJustify = com.sun.star.table.CellHoriJustify.CENTER
    Cell.VertJustify = com.sun.star.table.CellVertJustify.CENTER
End Sub

This below the image of what I would like to be able to do:

enter image description here

I have already written some macroes that generate the header in the correct cells and that generate the relative Bar Code (Code128) correctly. But since an inscription is made with a font while the BarCode uses another one, now I would like to write everything in a final cell and then serialize the print.
You can help me ?
I thank.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在风中等你 2025-02-17 20:38:10

创建一个文本光标以修改单元格内的文本。

LF = CHR(10)
oDoc = ThisComponent
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0, 0)
oCurs = oCell.createTextCursor()
oCurs.gotoStart(False)
oCurs.getText().insertString(oCurs, "TEST-01" & LF, True)  'Insert and select
oCurs.CharFontName = "Liberation Sans Narrow"
oCurs.goRight(0, False)  'De-select
oCurs.getText().insertString(oCurs, "TEST-02", True)  'Insert and select
oCurs.CharFontName = "Liberation Sans"

Create a text cursor to modify the text inside the cell.

LF = CHR(10)
oDoc = ThisComponent
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0, 0)
oCurs = oCell.createTextCursor()
oCurs.gotoStart(False)
oCurs.getText().insertString(oCurs, "TEST-01" & LF, True)  'Insert and select
oCurs.CharFontName = "Liberation Sans Narrow"
oCurs.goRight(0, False)  'De-select
oCurs.getText().insertString(oCurs, "TEST-02", True)  'Insert and select
oCurs.CharFontName = "Liberation Sans"
¢好甜 2025-02-17 20:38:10

这是我的测试代码,工作正常。

Private Sub TEST()
    Dim Doc As Object
    Dim Sheet As Object
    Dim Cell As Object
    Dim oCurs as Object
     
    Doc = ThisComponent
    'Sheet = Doc.Sheets(0)
    sheet = ThisComponent.Sheets.getByName("Test")              'Select the sheet by name
    ThisComponent.CurrentController.setActiveSheet(sheet)       'Activate the sheet
    
    Cell = Sheet.getCellRangeByName("F18")                      'Select the cell for Test
    
    oCurs = Cell.createTextCursor()
    oCurs.gotoStart(False)
    oCurs.CharFontName = "Gill Sans MT"                                         'Set Property Style Font 1
    oCurs.CharHeight = 10                                                       'Set Property for Char Size
    oCurs.getText().insertString(oCurs, "Inv. 13916" & vbcrlf, True)            'Insert and select
    oCurs.goRight(0, False)                                                     'De-select text
    oCurs.CharFontName = "Libre Barcode 128"                                    'Set Property Style Font 2
    oCurs.CharHeight = 48                                                       'Set Property for Char Size
    oCurs.getText().insertString(oCurs, BARCODE128_ENCODED("13916"), True)      'Insert and select second text with Code128 Algoritm
    oCurs.goRight(0, False)                                                     'De-select text
    
    Cell.HoriJustify = com.sun.star.table.CellHoriJustify.CENTER
    Cell.VertJustify = com.sun.star.table.CellVertJustify.CENTER
End Sub

This is my code for a test and it's work fine.

Private Sub TEST()
    Dim Doc As Object
    Dim Sheet As Object
    Dim Cell As Object
    Dim oCurs as Object
     
    Doc = ThisComponent
    'Sheet = Doc.Sheets(0)
    sheet = ThisComponent.Sheets.getByName("Test")              'Select the sheet by name
    ThisComponent.CurrentController.setActiveSheet(sheet)       'Activate the sheet
    
    Cell = Sheet.getCellRangeByName("F18")                      'Select the cell for Test
    
    oCurs = Cell.createTextCursor()
    oCurs.gotoStart(False)
    oCurs.CharFontName = "Gill Sans MT"                                         'Set Property Style Font 1
    oCurs.CharHeight = 10                                                       'Set Property for Char Size
    oCurs.getText().insertString(oCurs, "Inv. 13916" & vbcrlf, True)            'Insert and select
    oCurs.goRight(0, False)                                                     'De-select text
    oCurs.CharFontName = "Libre Barcode 128"                                    'Set Property Style Font 2
    oCurs.CharHeight = 48                                                       'Set Property for Char Size
    oCurs.getText().insertString(oCurs, BARCODE128_ENCODED("13916"), True)      'Insert and select second text with Code128 Algoritm
    oCurs.goRight(0, False)                                                     'De-select text
    
    Cell.HoriJustify = com.sun.star.table.CellHoriJustify.CENTER
    Cell.VertJustify = com.sun.star.table.CellVertJustify.CENTER
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文